# HG changeset patch # User Nicolas Chauvat # Date 1360852705 -3600 # Node ID 358d8bed9626726df169136a10d6c819bfed6d58 # Parent d901c36bcfce89301d07a9c541838ea0dc9de487 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624) The older form is not necessary since we dropped python 2.5 compability. This will help Python 3.3 experimentation. diff -r d901c36bcfce -r 358d8bed9626 _exceptions.py --- a/_exceptions.py Thu Feb 14 15:39:23 2013 +0100 +++ b/_exceptions.py Thu Feb 14 15:38:25 2013 +0100 @@ -100,7 +100,7 @@ if self.args: return ' '.join(self.args) return self.msg - except Exception, ex: + except Exception as ex: return str(ex) class Forbidden(SecurityError): diff -r d901c36bcfce -r 358d8bed9626 cwconfig.py --- a/cwconfig.py Thu Feb 14 15:39:23 2013 +0100 +++ b/cwconfig.py Thu Feb 14 15:38:25 2013 +0100 @@ -473,7 +473,7 @@ try: parent = __import__('cubes.%s.__pkginfo__' % cube) return getattr(parent, cube).__pkginfo__ - except Exception, ex: + except Exception as ex: raise ConfigurationError( 'unable to find packaging information for cube %s (%s: %s)' % (cube, ex.__class__.__name__, ex)) @@ -580,7 +580,7 @@ if dep in cubes) try: return ordered_nodes(graph) - except UnorderableGraph, ex: + except UnorderableGraph as ex: raise ConfigurationError('cycles in cubes dependencies: %s' % ex.cycles) @@ -614,7 +614,7 @@ if exists(join(CW_SOFTWARE_ROOT, ctlfile)): try: load_module_from_file(join(CW_SOFTWARE_ROOT, ctlfile)) - except ImportError, err: + except ImportError as err: cls.error('could not import the command provider %s: %s', ctlfile, err) cls.info('loaded cubicweb-ctl plugin %s', ctlfile) @@ -643,7 +643,7 @@ for cube in cls.available_cubes(): try: __import__('cubes.%s' % cube) - except Exception, ex: + except Exception as ex: cls.warning("can't init cube %s: %s", cube, ex) cubicweb_appobject_path = set(['entities']) @@ -1055,7 +1055,7 @@ self.info('creating %s directory', path) try: os.makedirs(path) - except OSError, ex: + except OSError as ex: self.warning('error while creating %s directory: %s', path, ex) return if self['uid']: @@ -1074,14 +1074,14 @@ self.info('giving ownership of %s directory to %s', path, self['uid']) try: os.chown(path, uid, os.getgid()) - except OSError, ex: + except OSError as ex: self.warning('error while giving ownership of %s directory to %s: %s', path, self['uid'], ex) if not (fstat.st_mode & stat.S_IWUSR): self.info('forcing write permission on directory %s', path) try: os.chmod(path, fstat.st_mode | stat.S_IWUSR) - except OSError, ex: + except OSError as ex: self.warning('error while forcing write permission on directory %s: %s', path, ex) return @@ -1191,7 +1191,7 @@ try: try: smtp = SMTP(server, port) - except Exception, ex: + except Exception as ex: self.exception("can't connect to smtp server %s:%s (%s)", server, port, ex) return False @@ -1199,7 +1199,7 @@ for msg, recipients in msgs: try: smtp.sendmail(heloaddr, recipients, msg.as_string()) - except Exception, ex: + except Exception as ex: self.exception("error sending mail to %s (%s)", recipients, ex) smtp.close() @@ -1314,7 +1314,7 @@ fpath = source.binary_to_str(value) try: return Binary(fpath) - except OSError, ex: + except OSError as ex: source.critical("can't open %s: %s", fpath, ex) return None diff -r d901c36bcfce -r 358d8bed9626 cwctl.py --- a/cwctl.py Thu Feb 14 15:39:23 2013 +0100 +++ b/cwctl.py Thu Feb 14 15:38:25 2013 +0100 @@ -165,11 +165,11 @@ cmdmeth = getattr(self, '%s_instance' % self.name) try: status = cmdmeth(appid) - except (ExecutionError, ConfigurationError), ex: + except (ExecutionError, ConfigurationError) as ex: sys.stderr.write('instance %s not %s: %s\n' % ( appid, self.actionverb, ex)) status = 4 - except Exception, ex: + except Exception as ex: import traceback traceback.print_exc() sys.stderr.write('instance %s not %s: %s\n' % ( @@ -234,7 +234,7 @@ try: cubesdir = pathsep.join(cwcfg.cubes_search_path()) namesize = max(len(x) for x in cwcfg.available_cubes()) - except ConfigurationError, ex: + except ConfigurationError as ex: print 'No cubes available:', ex except ValueError: print 'No cubes available in %s' % cubesdir @@ -245,7 +245,7 @@ tinfo = cwcfg.cube_pkginfo(cube) tversion = tinfo.version cfgpb.add_cube(cube, tversion) - except (ConfigurationError, AttributeError), ex: + except (ConfigurationError, AttributeError) as ex: tinfo = None tversion = '[missing cube information: %s]' % ex print '* %s %s' % (cube.ljust(namesize), tversion) @@ -266,7 +266,7 @@ print try: regdir = cwcfg.instances_dir() - except ConfigurationError, ex: + except ConfigurationError as ex: print 'No instance available:', ex print return @@ -281,7 +281,7 @@ print '* %s (%s)' % (appid, ', '.join(modes)) try: config = cwcfg.config_for(appid, modes[0]) - except Exception, exc: + except Exception as exc: print ' (BROKEN instance, %s)' % exc continue else: @@ -365,7 +365,7 @@ try: templdirs = [cwcfg.cube_dir(cube) for cube in cubes] - except ConfigurationError, ex: + except ConfigurationError as ex: print ex print '\navailable cubes:', print ', '.join(cwcfg.available_cubes()) @@ -466,7 +466,7 @@ # remove instance data directory try: rm(config.appdatahome) - except OSError, ex: + except OSError as ex: import errno if ex.errno != errno.ENOENT: raise @@ -561,7 +561,7 @@ else: try: wait_process_end(pid) - except ExecutionError, ex: + except ExecutionError as ex: sys.stderr.write('%s\ntrying SIGKILL\n' % ex) try: kill(pid, signal.SIGKILL) @@ -905,7 +905,7 @@ try: login, pwd = manager_userpasswd(msg=None) cnx = connect(appuri, login=login, password=pwd, mulcnx=False) - except AuthenticationError, ex: + except AuthenticationError as ex: print ex except (KeyboardInterrupt, EOFError): print @@ -1013,10 +1013,10 @@ cwcfg.load_cwctl_plugins() try: CWCTL.run(args) - except ConfigurationError, err: + except ConfigurationError as err: print 'ERROR: ', err sys.exit(1) - except ExecutionError, err: + except ExecutionError as err: print err sys.exit(2) diff -r d901c36bcfce -r 358d8bed9626 cwvreg.py --- a/cwvreg.py Thu Feb 14 15:39:23 2013 +0100 +++ b/cwvreg.py Thu Feb 14 15:38:25 2013 +0100 @@ -816,10 +816,10 @@ for key, val in propvalues: try: values[key] = self.typed_value(key, val) - except ValueError, ex: + except ValueError as ex: self.warning('%s (you should probably delete that property ' 'from the database)', ex) - except UnknownProperty, ex: + except UnknownProperty as ex: self.warning('%s (you should probably delete that property ' 'from the database)', ex) diff -r d901c36bcfce -r 358d8bed9626 dataimport.py --- a/dataimport.py Thu Feb 14 15:39:23 2013 +0100 +++ b/dataimport.py Thu Feb 14 15:38:25 2013 +0100 @@ -216,7 +216,7 @@ res[dest] = func(res[dest]) if res[dest] is None: break - except ValueError, err: + except ValueError as err: raise ValueError('error with %r field: %s' % (src, err)), None, sys.exc_info()[-1] return res @@ -744,7 +744,7 @@ txuuid = self.store.commit() if txuuid is not None: self.tell('Transaction commited (txuuid: %s)' % txuuid) - except QueryError, ex: + except QueryError as ex: self.tell('Transaction aborted: %s' % ex) self._print_stats() if self.errors: diff -r d901c36bcfce -r 358d8bed9626 dbapi.py --- a/dbapi.py Thu Feb 14 15:39:23 2013 +0100 +++ b/dbapi.py Thu Feb 14 15:38:25 2013 +0100 @@ -107,7 +107,7 @@ return _get_repository(uri, config, vreg) except ConnectionError: raise - except Exception, exc: + except Exception as exc: raise ConnectionError('cause: %r' % exc) def _get_repository(uri=None, config=None, vreg=None): diff -r d901c36bcfce -r 358d8bed9626 devtools/cwwindmill.py --- a/devtools/cwwindmill.py Thu Feb 14 15:39:23 2013 +0100 +++ b/devtools/cwwindmill.py Thu Feb 14 15:38:25 2013 +0100 @@ -35,7 +35,7 @@ import windmill from windmill.dep import functest from windmill.bin.admin_lib import configure_global_settings, setup, teardown -except ImportError, ex: +except ImportError: windmill = None from cubicweb.devtools.httptest import CubicWebServerTC, CubicWebServerConfig diff -r d901c36bcfce -r 358d8bed9626 devtools/devctl.py --- a/devtools/devctl.py Thu Feb 14 15:39:23 2013 +0100 +++ b/devtools/devctl.py Thu Feb 14 15:38:25 2013 +0100 @@ -386,7 +386,7 @@ continue try: toedit = update_cube_catalogs(cubedir) - except CalledProcessError, exc: + except CalledProcessError as exc: print '\n*** error while updating catalogs for cube', cubedir print 'cmd:\n%s' % exc.cmd print 'stdout:\n%s\nstderr:\n%s' % exc.data @@ -606,7 +606,7 @@ print "-> creating cubes directory", cubesdir try: mkdir(cubesdir) - except OSError, err: + except OSError as err: self.fail("failed to create directory %r\n(%s)" % (cubesdir, err)) cubedir = osp.join(cubesdir, cubename) @@ -694,7 +694,7 @@ for filepath in args: try: stream = file(filepath) - except OSError, ex: + except OSError as ex: raise BadCommandUsage("can't open rql log file %s: %s" % (filepath, ex)) for lineno, line in enumerate(stream): @@ -711,7 +711,7 @@ clocktime = float(chunks[0][1:]) cputime = float(chunks[-3]) req.append( (clocktime, cputime) ) - except Exception, exc: + except Exception as exc: sys.stderr.write('Line %s: %s (%s)\n' % (lineno, exc, line)) stat = [] for rql, times in requests.iteritems(): diff -r d901c36bcfce -r 358d8bed9626 devtools/htmlparser.py --- a/devtools/htmlparser.py Thu Feb 14 15:39:23 2013 +0100 +++ b/devtools/htmlparser.py Thu Feb 14 15:38:25 2013 +0100 @@ -37,7 +37,7 @@ try: data = self.preprocess_data(data) return PageInfo(data, etree.fromstring(data, self.parser)) - except etree.XMLSyntaxError, exc: + except etree.XMLSyntaxError as exc: def save_in(fname=''): file(fname, 'w').write(data) new_exc = AssertionError(u'invalid xml %s' % exc) diff -r d901c36bcfce -r 358d8bed9626 devtools/httptest.py --- a/devtools/httptest.py Thu Feb 14 15:39:23 2013 +0100 +++ b/devtools/httptest.py Thu Feb 14 15:38:25 2013 +0100 @@ -50,7 +50,7 @@ try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = s.connect(("localhost", port)) - except socket.error, err: + except socket.error as err: if err.args[0] in (111, 106): return port finally: @@ -179,7 +179,7 @@ def tearDown(self): try: self.stop_server() - except error.ReactorNotRunning, err: + except error.ReactorNotRunning as err: # Server could be launched manually print err super(CubicWebServerTC, self).tearDown() diff -r d901c36bcfce -r 358d8bed9626 devtools/qunit.py --- a/devtools/qunit.py Thu Feb 14 15:39:23 2013 +0100 +++ b/devtools/qunit.py Thu Feb 14 15:38:25 2013 +0100 @@ -82,7 +82,7 @@ check_call(self.firefox_cmd + ['-CreateProfile', '%s %s' % (self._profile_name, self._tmp_dir)], stdout=stdout, stderr=stderr) - except CalledProcessError, cpe: + except CalledProcessError as cpe: stdout.seek(0) stderr.seek(0) raise VerboseCalledProcessError(cpe.returncode, cpe.cmd, stdout.read(), stderr.read()) diff -r d901c36bcfce -r 358d8bed9626 devtools/repotest.py --- a/devtools/repotest.py Thu Feb 14 15:39:23 2013 +0100 +++ b/devtools/repotest.py Thu Feb 14 15:38:25 2013 +0100 @@ -155,7 +155,7 @@ if cls.backend is not None: try: cls.dbhelper = get_db_helper(cls.backend) - except ImportError, ex: + except ImportError as ex: raise SkipTest(str(ex)) def setUp(self): diff -r d901c36bcfce -r 358d8bed9626 devtools/stresstester.py --- a/devtools/stresstester.py Thu Feb 14 15:39:23 2013 +0100 +++ b/devtools/stresstester.py Thu Feb 14 15:38:25 2013 +0100 @@ -132,7 +132,7 @@ opts, args = getopt.getopt(args, 'hn:t:u:p:P:o:', ['help', 'user=', 'password=', 'nb-times=', 'nb-threads=', 'profile', 'report-output=',]) - except Exception, ex: + except Exception as ex: print ex usage(1) repeat = 100 diff -r d901c36bcfce -r 358d8bed9626 devtools/test/unittest_httptest.py --- a/devtools/test/unittest_httptest.py Thu Feb 14 15:39:23 2013 +0100 +++ b/devtools/test/unittest_httptest.py Thu Feb 14 15:38:25 2013 +0100 @@ -28,7 +28,7 @@ def test_response(self): try: response = self.web_get() - except httplib.NotConnected, ex: + except httplib.NotConnected as ex: self.fail("Can't connection to test server: %s" % ex) def test_response_anon(self): diff -r d901c36bcfce -r 358d8bed9626 devtools/testlib.py --- a/devtools/testlib.py Thu Feb 14 15:39:23 2013 +0100 +++ b/devtools/testlib.py Thu Feb 14 15:38:25 2013 +0100 @@ -315,7 +315,7 @@ try: self._init_repo() self.addCleanup(self._close_cnx) - except Exception, ex: + except Exception as ex: self.__class__._repo_init_failed = ex raise resume_tracing() @@ -720,7 +720,7 @@ """ try: callback(req) - except Redirect, ex: + except Redirect as ex: return self._parse_location(req, ex.location) else: self.fail('expected a Redirect exception') @@ -1087,7 +1087,7 @@ for rql, args in q: try: cu.execute(rql, args) - except ValidationError, ex: + except ValidationError as ex: # failed to satisfy some constraint print 'error in automatic db population', ex self.session.commit_state = None # reset uncommitable flag diff -r d901c36bcfce -r 358d8bed9626 etwist/server.py --- a/etwist/server.py Thu Feb 14 15:39:23 2013 +0100 +++ b/etwist/server.py Thu Feb 14 15:38:25 2013 +0100 @@ -169,7 +169,7 @@ try: ### Try to generate the actual request content content = self.appli.handle_request(req, path) - except DirectResponse, ex: + except DirectResponse as ex: return ex.response # at last: create twisted object return HTTPResponse(code = req.status_out, diff -r d901c36bcfce -r 358d8bed9626 etwist/service.py --- a/etwist/service.py Thu Feb 14 15:39:23 2013 +0100 +++ b/etwist/service.py Thu Feb 14 15:38:25 2013 +0100 @@ -91,7 +91,7 @@ logger.info('instance started on %s', root_resource.base_url) self.ReportServiceStatus(win32service.SERVICE_RUNNING) reactor.run() - except Exception, e: + except Exception as e: logger.error('service %s stopped (cause: %s)' % (self.instance, e)) logger.exception('what happened ...') self.ReportServiceStatus(win32service.SERVICE_STOPPED) diff -r d901c36bcfce -r 358d8bed9626 ext/rest.py --- a/ext/rest.py Thu Feb 14 15:39:23 2013 +0100 +++ b/ext/rest.py Thu Feb 14 15:38:25 2013 +0100 @@ -114,7 +114,7 @@ vid = 'noresult' view = _cw.vreg['views'].select(vid, _cw, rset=rset) content = view.render() - except Exception, exc: + except Exception as exc: content = 'an error occured while interpreting this rql directive: %r' % exc set_classes(options) return [nodes.raw('', content, format='html')], [] @@ -155,7 +155,7 @@ source_path=path, encoding=encoding, error_handler=state.document.settings.input_encoding_error_handler, handle_io_errors=None) - except IOError, error: + except IOError as error: severe = state_machine.reporter.severe( 'Problems with "%s" directive path:\n%s: %s.' % (name, error.__class__.__name__, error), @@ -163,7 +163,7 @@ return [severe] try: include_text = include_file.read() - except UnicodeError, error: + except UnicodeError as error: severe = state_machine.reporter.severe( 'Problem with "%s" directive:\n%s: %s' % (name, error.__class__.__name__, error), diff -r d901c36bcfce -r 358d8bed9626 ext/tal.py --- a/ext/tal.py Thu Feb 14 15:39:23 2013 +0100 +++ b/ext/tal.py Thu Feb 14 15:38:25 2013 +0100 @@ -182,7 +182,7 @@ """ Internally used when expanding a template that is part of a context.""" try: interpreter.execute(self) - except UnicodeError, unierror: + except UnicodeError as unierror: LOGGER.exception(str(unierror)) raise simpleTALES.ContextContentException("found non-unicode %r string in Context!" % unierror.args[1]), None, sys.exc_info()[-1] @@ -230,7 +230,7 @@ # XXX precompile expr will avoid late syntax error try: result = eval(expr, globals, locals) - except Exception, ex: + except Exception as ex: ex = ex.__class__('in %r: %s' % (expr, ex)) raise ex, None, sys.exc_info()[-1] if (isinstance (result, simpleTALES.ContextVariable)): diff -r d901c36bcfce -r 358d8bed9626 hooks/__init__.py --- a/hooks/__init__.py Thu Feb 14 15:39:23 2013 +0100 +++ b/hooks/__init__.py Thu Feb 14 15:38:25 2013 +0100 @@ -67,7 +67,7 @@ session = repo.internal_session(safe=True) try: source.pull_data(session) - except Exception, exc: + except Exception as exc: session.exception('while trying to update feed %s', source) finally: session.close() diff -r d901c36bcfce -r 358d8bed9626 hooks/syncschema.py --- a/hooks/syncschema.py Thu Feb 14 15:39:23 2013 +0100 +++ b/hooks/syncschema.py Thu Feb 14 15:38:25 2013 +0100 @@ -368,7 +368,7 @@ for etype in rschema.subjects(): try: add_inline_relation_column(session, str(etype), rtype) - except Exception, ex: + except Exception as ex: # the column probably already exists. this occurs when the # entity's type has just been added or if the column has not # been previously dropped (eg sqlite) @@ -459,7 +459,7 @@ % (table, column, attrtype)), rollback_on_failure=False) self.info('added column %s to table %s', table, column) - except Exception, ex: + except Exception as ex: # the column probably already exists. this occurs when # the entity's type has just been added or if the column # has not been previously dropped @@ -468,7 +468,7 @@ try: syssource.create_index(session, table, column, unique=extra_unique_index) - except Exception, ex: + except Exception as ex: self.error('error while creating index for %s.%s: %s', table, column, ex) # final relations are not infered, propagate @@ -757,7 +757,7 @@ for sql in sqls: try: session.system_sql(sql) - except Exception, exc: # should be ProgrammingError + except Exception as exc: # should be ProgrammingError if sql.startswith('DROP'): self.error('execute of `%s` failed (cause: %s)', sql, exc) continue diff -r d901c36bcfce -r 358d8bed9626 hooks/syncsession.py --- a/hooks/syncsession.py Thu Feb 14 15:39:23 2013 +0100 +++ b/hooks/syncsession.py Thu Feb 14 15:38:25 2013 +0100 @@ -167,7 +167,7 @@ except UnknownProperty: msg = _('unknown property key %s') raise validation_error(self.entity, {('pkey', 'subject'): msg}, (key,)) - except ValueError, ex: + except ValueError as ex: raise validation_error(self.entity, {('value', 'subject'): str(ex)}) if not session.user.matching_groups('managers'): @@ -193,7 +193,7 @@ value = session.vreg.typed_value(key, value) except UnknownProperty: return - except ValueError, ex: + except ValueError as ex: raise validation_error(entity, {('value', 'subject'): str(ex)}) if entity.for_user: for session_ in get_user_sessions(session.repo, entity.for_user[0].eid): diff -r d901c36bcfce -r 358d8bed9626 hooks/workflow.py --- a/hooks/workflow.py Thu Feb 14 15:39:23 2013 +0100 +++ b/hooks/workflow.py Thu Feb 14 15:38:25 2013 +0100 @@ -325,7 +325,7 @@ entity = self._cw.entity_from_eid(self.eidfrom) try: entity.cw_set(modification_date=datetime.now()) - except RepositoryError, ex: + except RepositoryError as ex: # usually occurs if entity is coming from a read-only source # (eg ldap user) self.warning('cant change modification date for %s: %s', entity, ex) diff -r d901c36bcfce -r 358d8bed9626 i18n.py --- a/i18n.py Thu Feb 14 15:39:23 2013 +0100 +++ b/i18n.py Thu Feb 14 15:38:25 2013 +0100 @@ -101,10 +101,10 @@ except OSError: pass # suppose not exists execute2(['msgfmt', mergedpo, '-o', applmo]) - except CalledProcessError, exc: + except CalledProcessError as exc: errors.append(u'while handling language %s:\ncmd:\n%s\nstdout:\n%s\nstderr:\n%s\n' % (lang, exc.cmd, repr(exc.data[0]), repr(exc.data[1]))) - except Exception, exc: + except Exception as exc: errors.append(u'while handling language %s: %s' % (lang, exc)) try: # clean everything diff -r d901c36bcfce -r 358d8bed9626 mail.py --- a/mail.py Thu Feb 14 15:39:23 2013 +0100 +++ b/mail.py Thu Feb 14 15:38:25 2013 +0100 @@ -212,7 +212,7 @@ subject = self.subject() except SkipEmail: continue - except Exception, ex: + except Exception as ex: # shouldn't make the whole transaction fail because of rendering # error (unauthorized or such) XXX check it doesn't actually # occurs due to rollback on such error diff -r d901c36bcfce -r 358d8bed9626 misc/cwdesklets/rqlsensor/__init__.py --- a/misc/cwdesklets/rqlsensor/__init__.py Thu Feb 14 15:39:23 2013 +0100 +++ b/misc/cwdesklets/rqlsensor/__init__.py Thu Feb 14 15:38:25 2013 +0100 @@ -104,7 +104,7 @@ output = self._new_output() try: self.__run_query(output) - except Exception, ex: + except Exception as ex: import traceback traceback.print_exc() output.set('layout', 'vertical, 10') diff -r d901c36bcfce -r 358d8bed9626 rset.py --- a/rset.py Thu Feb 14 15:39:23 2013 +0100 +++ b/rset.py Thu Feb 14 15:38:25 2013 +0100 @@ -642,7 +642,7 @@ try: entity = self.get_entity(row, index) return entity, rel.r_type - except NotAnEntity, exc: + except NotAnEntity as exc: return None, None return None, None diff -r d901c36bcfce -r 358d8bed9626 schema.py --- a/schema.py Thu Feb 14 15:39:23 2013 +0100 +++ b/schema.py Thu Feb 14 15:38:25 2013 +0100 @@ -784,14 +784,14 @@ if self.eid is not None: _cw.local_perm_cache[key] = False return False - except TypeResolverException, ex: + except TypeResolverException as ex: # some expression may not be resolvable with current kwargs # (type conflict) self.warning('%s: %s', rql, str(ex)) if self.eid is not None: _cw.local_perm_cache[key] = False return False - except Unauthorized, ex: + except Unauthorized as ex: self.debug('unauthorized %s: %s', rql, str(ex)) if self.eid is not None: _cw.local_perm_cache[key] = False diff -r d901c36bcfce -r 358d8bed9626 server/__init__.py --- a/server/__init__.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/__init__.py Thu Feb 14 15:38:25 2013 +0100 @@ -183,7 +183,7 @@ dropsql = sqldropschema(schema, driver) try: sqlexec(dropsql, execute, pbtitle=_title) - except Exception, ex: + except Exception as ex: print '-> drop failed, skipped (%s).' % ex sqlcnx.rollback() _title = '-> creating tables ' diff -r d901c36bcfce -r 358d8bed9626 server/checkintegrity.py --- a/server/checkintegrity.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/checkintegrity.py Thu Feb 14 15:38:25 2013 +0100 @@ -285,7 +285,7 @@ continue try: cursor = session.system_sql('SELECT eid_from FROM %s_relation;' % rschema) - except Exception, ex: + except Exception as ex: # usually because table doesn't exist print 'ERROR', ex continue diff -r d901c36bcfce -r 358d8bed9626 server/cwzmq.py --- a/server/cwzmq.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/cwzmq.py Thu Feb 14 15:38:25 2013 +0100 @@ -221,7 +221,7 @@ for cmd in cmds: result = self.process_cmd(cmd) self.send_data(result) - except Exception, exc: + except Exception as exc: traceback.print_exc() self.send_data(exc) @@ -235,7 +235,7 @@ self.loop.add_callback(self.loop.stop) self.stream.on_recv(None) self.stream.close() - except Exception, e: + except Exception as e: print e pass if shutdown_repo and not self.repo.shutting_down: diff -r d901c36bcfce -r 358d8bed9626 server/edition.py --- a/server/edition.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/edition.py Thu Feb 14 15:38:25 2013 +0100 @@ -141,7 +141,7 @@ try: entity.e_schema.check(dict_protocol_catcher(entity), creation=creation, relations=relations) - except ValidationError, ex: + except ValidationError as ex: ex.entity = self.entity raise diff -r d901c36bcfce -r 358d8bed9626 server/ldaputils.py --- a/server/ldaputils.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/ldaputils.py Thu Feb 14 15:38:25 2013 +0100 @@ -212,7 +212,7 @@ # check password by establishing a (unused) connection try: self._connect(user, password) - except ldap.LDAPError, ex: + except ldap.LDAPError as ex: # Something went wrong, most likely bad credentials self.info('while trying to authenticate %s: %s', user, ex) raise AuthenticationError() @@ -305,7 +305,7 @@ self.info('ldap NO SUCH OBJECT %s %s %s', base, scope, searchstr) self._process_no_such_object(session, base) return [] - # except ldap.REFERRAL, e: + # except ldap.REFERRAL as e: # cnx = self.handle_referral(e) # try: # res = cnx.search_s(base, scope, searchstr, attrs) diff -r d901c36bcfce -r 358d8bed9626 server/migractions.py --- a/server/migractions.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/migractions.py Thu Feb 14 15:38:25 2013 +0100 @@ -155,7 +155,7 @@ try: return super(ServerMigrationHelper, self).cmd_process_script( migrscript, funcname, *args, **kwargs) - except ExecutionError, err: + except ExecutionError as err: sys.stderr.write("-> %s\n" % err) except BaseException: self.rollback() @@ -193,7 +193,7 @@ for source in repo.sources: try: source.backup(osp.join(tmpdir, source.uri), self.confirm, format=format) - except Exception, ex: + except Exception as ex: print '-> error trying to backup %s [%s]' % (source.uri, ex) if not self.confirm('Continue anyway?', default='n'): raise SystemExit(1) @@ -252,7 +252,7 @@ continue try: source.restore(osp.join(tmpdir, source.uri), self.confirm, drop, format) - except Exception, exc: + except Exception as exc: print '-> error trying to restore %s [%s]' % (source.uri, exc) if not self.confirm('Continue anyway?', default='n'): raise SystemExit(1) @@ -398,7 +398,7 @@ try: sqlexec(open(fpath).read(), self.session.system_sql, False, delimiter=';;') - except Exception, exc: + except Exception as exc: print '-> ERROR:', exc, ', skipping', fpath # schema synchronization internals ######################################## @@ -1457,7 +1457,7 @@ if not ask_confirm or self.confirm('Execute rql: %s ?' % msg): try: res = execute(rql, kwargs, build_descr=build_descr) - except Exception, ex: + except Exception as ex: if self.confirm('Error: %s\nabort?' % ex, pdb=True): raise return res @@ -1551,7 +1551,7 @@ raise StopIteration try: return self._h._cw.execute(rql, kwargs) - except Exception, ex: + except Exception as ex: if self._h.confirm('Error: %s\nabort?' % ex): raise else: diff -r d901c36bcfce -r 358d8bed9626 server/querier.py --- a/server/querier.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/querier.py Thu Feb 14 15:38:25 2013 +0100 @@ -399,7 +399,7 @@ for solution in rqlst.solutions: try: localcheck = check_read_access(session, rqlst, solution, self.args) - except Unauthorized, ex: + except Unauthorized as ex: msg = 'remove %s from solutions since %s has no %s access to %s' msg %= (solution, session.user.login, ex.args[0], ex.args[1]) msgs.append(msg) diff -r d901c36bcfce -r 358d8bed9626 server/repository.py --- a/server/repository.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/repository.py Thu Feb 14 15:38:25 2013 +0100 @@ -343,7 +343,7 @@ deserialize_schema(appschema, session) except BadSchemaDefinition: raise - except Exception, ex: + except Exception as ex: import traceback traceback.print_exc() raise Exception('Is the database initialised ? (cause: %s)' % @@ -785,7 +785,7 @@ return rset except (Unauthorized, RQLSyntaxError): raise - except ValidationError, ex: + except ValidationError as ex: # need ValidationError normalization here so error may pass # through pyro if hasattr(ex.entity, 'eid'): @@ -1357,7 +1357,7 @@ edited.check(creation=True) try: source.add_entity(session, entity) - except UniqueTogetherError, exc: + except UniqueTogetherError as exc: userhdlr = session.vreg['adapters'].select( 'IUserFriendlyError', session, entity=entity, exc=exc) userhdlr.raise_user_exception() @@ -1423,7 +1423,7 @@ try: source.update_entity(session, entity) edited.saved = True - except UniqueTogetherError, exc: + except UniqueTogetherError as exc: etype, rtypes = exc.args problems = {} for col in rtypes: diff -r d901c36bcfce -r 358d8bed9626 server/schemaserial.py --- a/server/schemaserial.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/schemaserial.py Thu Feb 14 15:38:25 2013 +0100 @@ -442,11 +442,11 @@ def _ervalues(erschema): try: type_ = unicode(erschema.type) - except UnicodeDecodeError, e: + except UnicodeDecodeError as e: raise Exception("can't decode %s [was %s]" % (erschema.type, e)) try: desc = unicode(erschema.description) or u'' - except UnicodeDecodeError, e: + except UnicodeDecodeError as e: raise Exception("can't decode %s [was %s]" % (erschema.description, e)) return { 'name': type_, diff -r d901c36bcfce -r 358d8bed9626 server/serverctl.py --- a/server/serverctl.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/serverctl.py Thu Feb 14 15:38:25 2013 +0100 @@ -208,7 +208,7 @@ def confirm_on_error_or_die(msg, func, *args, **kwargs): try: return func(*args, **kwargs) - except Exception, ex: + except Exception as ex: print 'ERROR', ex if not ASK.confirm('An error occurred while %s. Continue anyway?' % msg): raise ExecutionError(str(ex)) @@ -382,7 +382,7 @@ if automatic or ASK.confirm('Create language %s ?' % extlang): try: helper.create_language(cursor, extlang) - except Exception, exc: + except Exception as exc: print '-> ERROR:', exc print '-> could not create language %s, some stored procedures might be unusable' % extlang cnx.rollback() @@ -449,7 +449,7 @@ host=system.get('db-host'), port=system.get('db-port'), user=system.get('db-user') or '', password=system.get('db-password') or '', **extra) - except Exception, ex: + except Exception as ex: raise ConfigurationError( 'You seem to have provided wrong connection information in '\ 'the %s file. Resolve this first (error: %s).' @@ -552,7 +552,7 @@ try: sqlexec(sqlgrants(schema, source['db-driver'], user, set_owner=set_owner), cursor) - except Exception, ex: + except Exception as ex: cnx.rollback() import traceback traceback.print_exc() @@ -620,7 +620,7 @@ sconfig['password'] = pwd sourcescfg['admin'] = sconfig config.write_sources_file(sourcescfg) - except Exception, ex: + except Exception as ex: cnx.rollback() import traceback traceback.print_exc() @@ -868,7 +868,7 @@ if not self.config.no_drop: try: CWCTL.run(['db-create', '--automatic', appid]) - except SystemExit, exc: + except SystemExit as exc: # continue if the command exited with status 0 (success) if exc.code: raise @@ -879,7 +879,7 @@ if self.config.format == 'portable': try: CWCTL.run(['db-rebuild-fti', appid]) - except SystemExit, exc: + except SystemExit as exc: if exc.code: raise diff -r d901c36bcfce -r 358d8bed9626 server/sources/__init__.py --- a/server/sources/__init__.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/sources/__init__.py Thu Feb 14 15:38:25 2013 +0100 @@ -177,7 +177,7 @@ # type check try: value = configuration.convert(value, optdict, optname) - except Exception, ex: + except Exception as ex: msg = unicode(ex) # XXX internationalization raise ValidationError(eid, {role_name('config', 'subject'): msg}) processed[optname] = value diff -r d901c36bcfce -r 358d8bed9626 server/sources/datafeed.py --- a/server/sources/datafeed.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/sources/datafeed.py Thu Feb 14 15:38:25 2013 +0100 @@ -207,14 +207,14 @@ try: if parser.process(url, raise_on_error): error = True - except IOError, exc: + except IOError as exc: if raise_on_error: raise parser.import_log.record_error( 'could not pull data while processing %s: %s' % (url, exc)) error = True - except Exception, exc: + except Exception as exc: if raise_on_error: raise self.exception('error while processing %s: %s', @@ -318,7 +318,7 @@ eid = session.repo.extid2eid(source, str(uri), etype, session, complete=False, commit=False, sourceparams=sourceparams) - except ValidationError, ex: + except ValidationError as ex: # XXX use critical so they are seen during tests. Should consider # raise_on_error instead? self.source.critical('error while creating %s: %s', etype, ex) @@ -402,7 +402,7 @@ """IDataFeedParser main entry point""" try: parsed = self.parse(url) - except Exception, ex: + except Exception as ex: if raise_on_error: raise self.import_log.record_error(str(ex)) @@ -424,7 +424,7 @@ # other a chance to get our connections set commit() set_cnxset() - except ValidationError, exc: + except ValidationError as exc: if raise_on_error: raise self.source.error('Skipping %s because of validation error %s' @@ -455,7 +455,7 @@ if extid.startswith('http'): try: _OPENER.open(self.normalize_url(extid)) # XXX HTTP HEAD request - except urllib2.HTTPError, ex: + except urllib2.HTTPError as ex: if ex.code == 404: return True elif extid.startswith('file://'): diff -r d901c36bcfce -r 358d8bed9626 server/sources/extlite.py --- a/server/sources/extlite.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/sources/extlite.py Thu Feb 14 15:38:25 2013 +0100 @@ -290,7 +290,7 @@ try: # str(query) to avoid error if it's an unicode string cursor.execute(str(query), args) - except Exception, ex: + except Exception as ex: self.critical("sql: %r\n args: %s\ndbms message: %r", query, args, ex.args[0]) try: diff -r d901c36bcfce -r 358d8bed9626 server/sources/ldapuser.py --- a/server/sources/ldapuser.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/sources/ldapuser.py Thu Feb 14 15:38:25 2013 +0100 @@ -238,13 +238,13 @@ # handle restriction try: eidfilters_, ldapfilter = generator.generate(rqlst, mainvar) - except GotDN, ex: + except GotDN as ex: assert ex.dn, 'no dn!' try: res = [self._cache[ex.dn]] except KeyError: res = self._search(session, ex.dn, BASE) - except UnknownEid, ex: + except UnknownEid as ex: # raised when we are looking for the dn of an eid which is not # coming from this source res = [] diff -r d901c36bcfce -r 358d8bed9626 server/sources/native.py --- a/server/sources/native.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/sources/native.py Thu Feb 14 15:38:25 2013 +0100 @@ -83,7 +83,7 @@ print 'exec', query, args try: self.cu.execute(str(query), args) - except Exception, ex: + except Exception as ex: print "sql: %r\n args: %s\ndbms message: %r" % ( query, args, ex.args[0]) raise @@ -411,7 +411,7 @@ # test if 'asource' column exists query = self.dbhelper.sql_add_limit_offset('SELECT asource FROM entities', 1) source_entity._cw.system_sql(query) - except Exception, ex: + except Exception as ex: self.eid_type_source = self.eid_type_source_pre_131 def shutdown(self): @@ -536,7 +536,7 @@ self.warning("trying to reconnect") session.cnxset.reconnect(self) cursor = self.doexec(session, sql, args) - except (self.DbapiError,), exc: + except self.DbapiError as exc: # We get this one with pyodbc and SQL Server when connection was reset if exc.args[0] == '08S01' and session.mode != 'write': self.warning("trying to reconnect") @@ -736,7 +736,7 @@ try: # str(query) to avoid error if it's an unicode string cursor.execute(str(query), args) - except Exception, ex: + except Exception as ex: if self.repo.config.mode != 'test': # during test we get those message when trying to alter sqlite # db schema @@ -747,7 +747,7 @@ session.cnxset.connection(self.uri).rollback() if self.repo.config.mode != 'test': self.critical('transaction has been rollbacked') - except Exception, ex: + except Exception as ex: pass if ex.__class__.__name__ == 'IntegrityError': # need string comparison because of various backends @@ -777,7 +777,7 @@ try: # str(query) to avoid error if it's an unicode string cursor.executemany(str(query), args) - except Exception, ex: + except Exception as ex: if self.repo.config.mode != 'test': # during test we get those message when trying to alter sqlite # db schema @@ -941,7 +941,7 @@ self.warning("trying to reconnect create eid connection") self._eid_creation_cnx = None return self._create_eid() # pylint: disable=E1102 - except (self.DbapiError,), exc: + except self.DbapiError as exc: # We get this one with pyodbc and SQL Server when connection was reset if exc.args[0] == '08S01': self.warning("trying to reconnect create eid connection") @@ -1309,14 +1309,14 @@ subj, rtype, obj = action.eid_from, action.rtype, action.eid_to try: sentity, oentity, rdef = _undo_rel_info(session, subj, rtype, obj) - except _UndoException, ex: + except _UndoException as ex: errors.append(unicode(ex)) else: for role, entity in (('subject', sentity), ('object', oentity)): try: _undo_check_relation_target(entity, rdef, role) - except _UndoException, ex: + except _UndoException as ex: errors.append(unicode(ex)) continue if not errors: @@ -1392,7 +1392,7 @@ subj, rtype, obj = action.eid_from, action.rtype, action.eid_to try: sentity, oentity, rdef = _undo_rel_info(session, subj, rtype, obj) - except _UndoException, ex: + except _UndoException as ex: errors.append(unicode(ex)) else: rschema = rdef.rtype diff -r d901c36bcfce -r 358d8bed9626 server/sources/pyrorql.py --- a/server/sources/pyrorql.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/sources/pyrorql.py Thu Feb 14 15:38:25 2013 +0100 @@ -34,7 +34,7 @@ def get_connection(self): try: return self._get_connection() - except (ConnectionError, PyroError), ex: + except (ConnectionError, PyroError) as ex: self.critical("can't get connection to source %s: %s", self.uri, ex) return ConnectionWrapper() diff -r d901c36bcfce -r 358d8bed9626 server/sources/remoterql.py --- a/server/sources/remoterql.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/sources/remoterql.py Thu Feb 14 15:38:25 2013 +0100 @@ -118,7 +118,7 @@ def get_connection(self): try: return self._get_connection() - except ConnectionError, ex: + except ConnectionError as ex: self.critical("can't get connection to source %s: %s", self.uri, ex) return ConnectionWrapper() @@ -337,7 +337,7 @@ translator = RQL2RQL(self) try: rql = translator.generate(session, union, args) - except UnknownEid, ex: + except UnknownEid as ex: if server.DEBUG: print ' unknown eid', ex, 'no results' return [] @@ -345,7 +345,7 @@ print ' translated rql', rql try: rset = cu.execute(rql, args) - except Exception, ex: + except Exception as ex: self.exception(str(ex)) msg = session._("error while querying source %s, some data may be missing") session.set_shared_data('sources_error', msg % self.uri, txdata=True) @@ -573,7 +573,7 @@ return # XXX what about optional relation or outer NOT EXISTS() raise - except ReplaceByInOperator, ex: + except ReplaceByInOperator as ex: rhs = 'IN (%s)' % ','.join(eid for eid in ex.eids) self.need_translation = False self.current_operator = None @@ -600,7 +600,7 @@ for child in node.children: try: rql = child.accept(self) - except UnknownEid, ex: + except UnknownEid as ex: continue res.append(rql) if not res: diff -r d901c36bcfce -r 358d8bed9626 server/sources/storages.py --- a/server/sources/storages.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/sources/storages.py Thu Feb 14 15:38:25 2013 +0100 @@ -144,7 +144,7 @@ fpath = source.binary_to_str(value) try: return Binary.from_file(fpath) - except EnvironmentError, ex: + except EnvironmentError as ex: source.critical("can't open %s: %s", value, ex) return None @@ -264,7 +264,7 @@ for filepath in self.get_data(): try: unlink(filepath) - except Exception, ex: + except Exception as ex: self.error('cant remove %s: %s' % (filepath, ex)) class DeleteFileOp(hook.DataOperationMixIn, hook.Operation): @@ -272,5 +272,5 @@ for filepath in self.get_data(): try: unlink(filepath) - except Exception, ex: + except Exception as ex: self.error('cant remove %s: %s' % (filepath, ex)) diff -r d901c36bcfce -r 358d8bed9626 server/test/unittest_rql2sql.py --- a/server/test/unittest_rql2sql.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/test/unittest_rql2sql.py Thu Feb 14 15:38:25 2013 +0100 @@ -35,7 +35,7 @@ supported_backends = ('postgres', 'sqlite', 'mysql') try: register_function(stockproc) -except AssertionError, ex: +except AssertionError as ex: pass # already registered @@ -1294,7 +1294,7 @@ varmap=varmap) args.update(nargs) self.assertMultiLineEqual(strip(r % args), self._norm_sql(sql)) - except Exception, ex: + except Exception as ex: if 'r' in locals(): try: print (r%args).strip() @@ -1319,7 +1319,7 @@ rqlst = self._prepare(rql) r, args, cbs = self.o.generate(rqlst, args) self.assertEqual((r.strip(), args), sql) - except Exception, ex: + except Exception as ex: print rql if 'r' in locals(): print r.strip() diff -r d901c36bcfce -r 358d8bed9626 server/test/unittest_undo.py --- a/server/test/unittest_undo.py Thu Feb 14 15:39:23 2013 +0100 +++ b/server/test/unittest_undo.py Thu Feb 14 15:38:25 2013 +0100 @@ -52,7 +52,7 @@ expected_errors = [] try: self.cnx.undo_transaction(txuuid) - except UndoTransactionException, exn: + except UndoTransactionException as exn: errors = exn.errors else: errors = [] diff -r d901c36bcfce -r 358d8bed9626 setup.py --- a/setup.py Thu Feb 14 15:39:23 2013 +0100 +++ b/setup.py Thu Feb 14 15:38:25 2013 +0100 @@ -129,7 +129,7 @@ shutil.copy2(src, dest) try: os.mkdir(to_dir) - except OSError, ex: + except OSError as ex: # file exists ? import errno if ex.errno != errno.EEXIST: diff -r d901c36bcfce -r 358d8bed9626 skeleton/setup.py --- a/skeleton/setup.py Thu Feb 14 15:39:23 2013 +0100 +++ b/skeleton/setup.py Thu Feb 14 15:38:25 2013 +0100 @@ -115,7 +115,7 @@ shutil.copy2(src, dest) try: os.mkdir(to_dir) - except OSError, ex: + except OSError as ex: # file exists ? import errno if ex.errno != errno.EEXIST: diff -r d901c36bcfce -r 358d8bed9626 toolsutils.py --- a/toolsutils.py Thu Feb 14 15:39:23 2013 +0100 +++ b/toolsutils.py Thu Feb 14 15:38:25 2013 +0100 @@ -59,7 +59,7 @@ try: makedirs(directory) print '-> created directory %s' % directory - except OSError, ex: + except OSError as ex: import errno if ex.errno != errno.EEXIST: raise @@ -185,7 +185,7 @@ option = option.strip().replace(' ', '_') value = value.strip() current[option] = value or None - except IOError, ex: + except IOError as ex: if raise_if_unreadable: raise ExecutionError('%s. Are you logged with the correct user ' 'to use this instance?' % ex) diff -r d901c36bcfce -r 358d8bed9626 web/application.py --- a/web/application.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/application.py Thu Feb 14 15:38:25 2013 +0100 @@ -362,7 +362,7 @@ ### Try to generate the actual request content content = self.core_handle(req, path) # Handle user log-out - except LogOut, ex: + except LogOut as ex: # When authentification is handled by cookie the code that # raised LogOut must has invalidated the cookie. We can just # reload the original url without authentification @@ -380,7 +380,7 @@ content = self.loggedout_content(req) # let the explicitly reset http credential raise AuthenticationError() - except Redirect, ex: + except Redirect as ex: # authentication needs redirection (eg openid) content = self.redirect_handler(req, ex) # Wrong, absent or Reseted credential @@ -441,12 +441,12 @@ raise Unauthorized(req._('not authorized')) req.update_search_state() result = controller.publish(rset=rset) - except StatusResponse, ex: + except StatusResponse as ex: warn('StatusResponse is deprecated use req.status_out', DeprecationWarning) result = ex.content req.status_out = ex.status - except Redirect, ex: + except Redirect as ex: # Redirect may be raised by edit controller when everything went # fine, so attempt to commit result = self.redirect_handler(req, ex) @@ -456,24 +456,24 @@ if txuuid is not None: req.data['last_undoable_transaction'] = txuuid ### error case - except NotFound, ex: + except NotFound as ex: result = self.notfound_content(req) req.status_out = ex.status - except ValidationError, ex: + except ValidationError as ex: result = self.validation_error_handler(req, ex) - except RemoteCallFailed, ex: + except RemoteCallFailed as ex: result = self.ajax_error_handler(req, ex) - except Unauthorized, ex: + except Unauthorized as ex: req.data['errmsg'] = req._('You\'re not authorized to access this page. ' 'If you think you should, please contact the site administrator.') req.status_out = httplib.UNAUTHORIZED result = self.error_handler(req, ex, tb=False) - except Forbidden, ex: + except Forbidden as ex: req.data['errmsg'] = req._('This action is forbidden. ' 'If you think it should be allowed, please contact the site administrator.') req.status_out = httplib.FORBIDDEN result = self.error_handler(req, ex, tb=False) - except (BadRQLQuery, RequestError), ex: + except (BadRQLQuery, RequestError) as ex: result = self.error_handler(req, ex, tb=False) ### pass through exception except DirectResponse: @@ -484,7 +484,7 @@ # the rollback is handled in the finally raise ### Last defense line - except BaseException, ex: + except BaseException as ex: result = self.error_handler(req, ex, tb=True) finally: if req.cnx and not commited: diff -r d901c36bcfce -r 358d8bed9626 web/component.py --- a/web/component.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/component.py Thu Feb 14 15:38:25 2013 +0100 @@ -256,7 +256,7 @@ view = self.cw_extra_kwargs['view'] try: view.init_rendering() - except Unauthorized, ex: + except Unauthorized as ex: self.warning("can't render %s: %s", view, ex) return False except EmptyComponent: diff -r d901c36bcfce -r 358d8bed9626 web/formfields.py --- a/web/formfields.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/formfields.py Thu Feb 14 15:38:25 2013 +0100 @@ -988,7 +988,7 @@ return None try: value = form._cw.parse_datetime(value, self.etype) - except ValueError, ex: + except ValueError as ex: raise ProcessFormError(unicode(ex)) return value diff -r d901c36bcfce -r 358d8bed9626 web/formwidgets.py --- a/web/formwidgets.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/formwidgets.py Thu Feb 14 15:38:25 2013 +0100 @@ -769,13 +769,13 @@ return None try: date = todatetime(req.parse_datetime(datestr, 'Date')) - except ValueError, exc: + except ValueError as exc: raise ProcessFormError(unicode(exc)) if timestr is None: return date try: time = req.parse_datetime(timestr, 'Time') - except ValueError, exc: + except ValueError as exc: raise ProcessFormError(unicode(exc)) return date.replace(hour=time.hour, minute=time.minute, second=time.second) diff -r d901c36bcfce -r 358d8bed9626 web/http_headers.py --- a/web/http_headers.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/http_headers.py Thu Feb 14 15:38:25 2013 +0100 @@ -77,7 +77,7 @@ header = p(header) # if isinstance(h, types.GeneratorType): # h=list(h) - except ValueError,v: + except ValueError as v: # print v header=None @@ -528,7 +528,7 @@ def parseContentMD5(header): try: return base64.decodestring(header) - except Exception,e: + except Exception as e: raise ValueError(e) def parseContentRange(header): diff -r d901c36bcfce -r 358d8bed9626 web/propertysheet.py --- a/web/propertysheet.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/propertysheet.py Thu Feb 14 15:38:25 2013 +0100 @@ -101,7 +101,7 @@ # this in the source css file ? try: content = self.compile(content) - except ValueError, ex: + except ValueError as ex: self.error("can't process %s/%s: %s", rdirectory, rid, ex) adirectory = rdirectory else: diff -r d901c36bcfce -r 358d8bed9626 web/request.py --- a/web/request.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/request.py Thu Feb 14 15:38:25 2013 +0100 @@ -880,7 +880,7 @@ user, passwd = base64.decodestring(rest).split(":", 1) # XXX HTTP header encoding: use email.Header? return user.decode('UTF8'), passwd - except Exception, ex: + except Exception as ex: self.debug('bad authorization %s (%s: %s)', auth, ex.__class__.__name__, ex) return None, None diff -r d901c36bcfce -r 358d8bed9626 web/test/unittest_application.py --- a/web/test/unittest_application.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/test/unittest_application.py Thu Feb 14 15:38:25 2013 +0100 @@ -332,7 +332,7 @@ self.assertAuthFailure(req) try: form = self.app_handle_request(req, 'login') - except Redirect, redir: + except Redirect as redir: self.fail('anonymous user should get login form') self.assertTrue('__login' in form) self.assertTrue('__password' in form) diff -r d901c36bcfce -r 358d8bed9626 web/test/unittest_http.py --- a/web/test/unittest_http.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/test/unittest_http.py Thu Feb 14 15:38:25 2013 +0100 @@ -21,7 +21,7 @@ status = None try: req.validate_cache() - except StatusResponse, ex: + except StatusResponse as ex: status = ex.status return status, req diff -r d901c36bcfce -r 358d8bed9626 web/test/unittest_views_apacherewrite.py --- a/web/test/unittest_views_apacherewrite.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/test/unittest_views_apacherewrite.py Thu Feb 14 15:38:25 2013 +0100 @@ -40,7 +40,7 @@ try: urlrewriter.rewrite('logilab.fr', '/whatever', req) self.fail('redirect exception expected') - except Redirect, ex: + except Redirect as ex: self.assertEqual(ex.location, 'http://www.logilab.fr/whatever') self.assertEqual(urlrewriter.rewrite('www.logilab.fr', '/whatever', req), '/whatever') diff -r d901c36bcfce -r 358d8bed9626 web/test/unittest_views_errorform.py --- a/web/test/unittest_views_errorform.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/test/unittest_views_errorform.py Thu Feb 14 15:38:25 2013 +0100 @@ -50,7 +50,7 @@ with self.temporary_appobjects(MyWrongView): try: self.view('my-view') - except Exception, e: + except Exception as e: import sys self.req.data['excinfo'] = sys.exc_info() self.req.data['ex'] = e diff -r d901c36bcfce -r 358d8bed9626 web/views/ajaxcontroller.py --- a/web/views/ajaxcontroller.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/views/ajaxcontroller.py Thu Feb 14 15:38:25 2013 +0100 @@ -135,7 +135,7 @@ args = (args,) try: args = [json.loads(arg) for arg in args] - except ValueError, exc: + except ValueError as exc: self.exception('error while decoding json arguments for ' 'js_%s: %s (err: %s)', fname, args, exc) raise RemoteCallFailed(exc_message(exc, self._cw.encoding)) @@ -143,7 +143,7 @@ result = func(*args) except (RemoteCallFailed, DirectResponse): raise - except Exception, exc: + except Exception as exc: self.exception('an exception occurred while calling js_%s(%s): %s', fname, args, exc) raise RemoteCallFailed(exc_message(exc, self._cw.encoding)) @@ -214,7 +214,7 @@ self._cw.ensure_ro_rql(rql) try: return self._cw.execute(rql, args) - except Exception, ex: + except Exception as ex: self.exception("error in _exec(rql=%s): %s", rql, ex) return None return None diff -r d901c36bcfce -r 358d8bed9626 web/views/basecontrollers.py --- a/web/views/basecontrollers.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/views/basecontrollers.py Thu Feb 14 15:38:25 2013 +0100 @@ -212,14 +212,14 @@ return (False, {None: req._('not authorized')}, None) try: ctrl.publish(None) - except ValidationError, ex: + except ValidationError as ex: return (False, _validation_error(req, ex), ctrl._edited_entity) - except Redirect, ex: + except Redirect as ex: try: txuuid = req.cnx.commit() # ValidationError may be raised on commit - except ValidationError, ex: + except ValidationError as ex: return (False, _validation_error(req, ex), ctrl._edited_entity) - except Exception, ex: + except Exception as ex: req.cnx.rollback() req.exception('unexpected error while validating form') return (False, str(ex).decode('utf-8'), ctrl._edited_entity) @@ -231,7 +231,7 @@ if ctrl._edited_entity: ctrl._edited_entity.complete() return (True, ex.location, ctrl._edited_entity) - except Exception, ex: + except Exception as ex: req.cnx.rollback() req.exception('unexpected error while validating form') return (False, str(ex).decode('utf-8'), ctrl._edited_entity) @@ -298,7 +298,7 @@ txuuid = self._cw.form['txuuid'] try: self._cw.cnx.undo_transaction(txuuid) - except UndoTransactionException, exc: + except UndoTransactionException as exc: errors = exc.errors #This will cause a rollback in main_publish raise ValidationError(None, {None: '\n'.join(errors)}) diff -r d901c36bcfce -r 358d8bed9626 web/views/baseviews.py --- a/web/views/baseviews.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/views/baseviews.py Thu Feb 14 15:38:25 2013 +0100 @@ -498,7 +498,7 @@ for attr in entity.e_schema.indexable_attributes(): try: value = xml_escape(entity.printable_value(attr, format='text/plain').lower()) - except TransformError, ex: + except TransformError as ex: continue except Exception: continue diff -r d901c36bcfce -r 358d8bed9626 web/views/cwproperties.py --- a/web/views/cwproperties.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/views/cwproperties.py Thu Feb 14 15:38:25 2013 +0100 @@ -349,7 +349,7 @@ return try: pdef = form._cw.vreg.property_info(entity.pkey) - except UnknownProperty, ex: + except UnknownProperty as ex: form.warning('%s (you should probably delete that property ' 'from the database)', ex) msg = form._cw._('you should probably delete that property') diff -r d901c36bcfce -r 358d8bed9626 web/views/editcontroller.py --- a/web/views/editcontroller.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/views/editcontroller.py Thu Feb 14 15:38:25 2013 +0100 @@ -132,7 +132,7 @@ # __type and eid formparams = req.extract_entity_params(eid, minparams=2) eid = self.edit_entity(formparams) - except (RequestError, NothingToEdit), ex: + except (RequestError, NothingToEdit) as ex: if '__linkto' in req.form and 'eid' in req.form: self.execute_linkto() elif not ('__delete' in req.form or '__insert' in req.form): @@ -159,7 +159,7 @@ try: entity = self._cw.execute(rql, rqlquery.kwargs).get_entity(0, 0) neweid = entity.eid - except ValidationError, ex: + except ValidationError as ex: self._to_create[eid] = ex.entity if self._cw.ajax_request: # XXX (syt) why? ex.entity = eid @@ -249,7 +249,7 @@ else: self._pending_fields.add( (form, field) ) - except ProcessFormError, exc: + except ProcessFormError as exc: self.errors.append((field, exc)) def handle_inlined_relation(self, form, field, values, origvalues, rqlquery): diff -r d901c36bcfce -r 358d8bed9626 web/views/embedding.py --- a/web/views/embedding.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/views/embedding.py Thu Feb 14 15:38:25 2013 +0100 @@ -94,7 +94,7 @@ body = embed_external_page(embedded_url, prefix, headers, req.form.get('custom_css')) body = soup2xhtml(body, self._cw.encoding) - except HTTPError, err: + except HTTPError as err: body = '

%s

%s

' % ( _('error while embedding page'), err) rset = self.process_rql() diff -r d901c36bcfce -r 358d8bed9626 web/views/forms.py --- a/web/views/forms.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/views/forms.py Thu Feb 14 15:38:25 2013 +0100 @@ -293,7 +293,7 @@ try: for field, value in field.process_posted(self): processed[field.role_name()] = value - except ProcessFormError, exc: + except ProcessFormError as exc: errors.append((field, exc)) if errors: errors = dict((f.role_name(), unicode(ex)) for f, ex in errors) diff -r d901c36bcfce -r 358d8bed9626 web/views/idownloadable.py --- a/web/views/idownloadable.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/views/idownloadable.py Thu Feb 14 15:38:25 2013 +0100 @@ -153,7 +153,7 @@ try: self.w(entity._cw_mtc_transform(adapter.download_data(), sourcemt, targetmt, adapter.download_encoding())) - except Exception, ex: + except Exception as ex: self.exception('while rendering data for %s', entity) msg = self._cw._("can't display data, unexpected error: %s") \ % xml_escape(unicode(ex)) diff -r d901c36bcfce -r 358d8bed9626 web/views/magicsearch.py --- a/web/views/magicsearch.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/views/magicsearch.py Thu Feb 14 15:38:25 2013 +0100 @@ -349,7 +349,7 @@ try: word1 = left_words[0] return self._two_words_query(word1, quoted_part) - except BadRQLQuery, error: + except BadRQLQuery as error: raise BadRQLQuery("unable to handle request %r" % ori_rql) # Case (2) : Company name "My own company"; elif len(left_words) == 2: @@ -400,10 +400,10 @@ # FIXME : we don't want to catch any exception type here ! except (RQLSyntaxError, BadRQLQuery): pass - except Unauthorized, ex: + except Unauthorized as ex: unauthorized = ex continue - except Exception, ex: + except Exception as ex: LOGGER.debug('%s: %s', ex.__class__.__name__, ex) continue if unauthorized: @@ -461,7 +461,7 @@ else: return ['%s WHERE %s' % (user_rql, suggestion) for suggestion in self.rql_build_suggestions(select, incomplete_part)] - except Exception, exc: # we never want to crash + except Exception as exc: # we never want to crash self.debug('failed to build suggestions: %s', exc) return [] diff -r d901c36bcfce -r 358d8bed9626 web/views/sparql.py --- a/web/views/sparql.py Thu Feb 14 15:39:23 2013 +0100 +++ b/web/views/sparql.py Thu Feb 14 15:38:25 2013 +0100 @@ -58,11 +58,11 @@ if sparql: try: qinfo = Sparql2rqlTranslator(self._cw.vreg.schema).translate(sparql) - except TypeResolverException, exc: + except TypeResolverException as exc: self.w(self._cw._('can not resolve entity types:') + u' ' + unicode(exc)) except UnsupportedQuery: self.w(self._cw._('we are not yet ready to handle this query')) - except xy.UnsupportedVocabulary, exc: + except xy.UnsupportedVocabulary as exc: self.w(self._cw._('unknown vocabulary:') + u' ' + unicode(exc)) else: rql, args = qinfo.finalize() diff -r d901c36bcfce -r 358d8bed9626 wsgi/handler.py --- a/wsgi/handler.py Thu Feb 14 15:39:23 2013 +0100 +++ b/wsgi/handler.py Thu Feb 14 15:38:25 2013 +0100 @@ -118,7 +118,7 @@ try: path = req.path result = self.appli.handle_request(req, path) - except DirectResponse, ex: + except DirectResponse as ex: return ex.response return WSGIResponse(req.status_out, req, result)