From 0d641362eb03028e3892904286178bd18844711a Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Tue, 30 Apr 2013 11:24:51 -0400 Subject: [PATCH] Update exception block syntax. --- pecan/commands/base.py | 2 +- pecan/commands/create.py | 2 +- pecan/commands/shell.py | 2 +- pecan/compat/dictconfig.py | 28 ++++++++++++------------ pecan/core.py | 4 ++-- pecan/hooks.py | 2 +- pecan/middleware/errordocument.py | 2 +- pecan/middleware/recursive.py | 2 +- pecan/routing.py | 2 +- pecan/tests/middleware/test_recursive.py | 4 ++-- pecan/tests/test_base.py | 12 +++++----- pecan/tests/test_hooks.py | 2 +- pecan/tests/test_secure.py | 2 +- 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/pecan/commands/base.py b/pecan/commands/base.py index 68b5c0e..67fc0d4 100644 --- a/pecan/commands/base.py +++ b/pecan/commands/base.py @@ -46,7 +46,7 @@ class CommandManager(object): try: cmd = ep.load() assert hasattr(cmd, 'run') - except Exception, e: # pragma: nocover + except Exception as e: # pragma: nocover warn("Unable to load plugin %s: %s" % (ep, e), RuntimeWarning) continue self.add({ep.name: cmd}) diff --git a/pecan/commands/create.py b/pecan/commands/create.py index f332065..b6eec2a 100644 --- a/pecan/commands/create.py +++ b/pecan/commands/create.py @@ -23,7 +23,7 @@ class ScaffoldManager(object): try: cmd = ep.load() assert hasattr(cmd, 'copy_to') - except Exception, e: # pragma: nocover + except Exception as e: # pragma: nocover warn( "Unable to load scaffold %s: %s" % (ep, e), RuntimeWarning ) diff --git a/pecan/commands/shell.py b/pecan/commands/shell.py index 8f7a38a..44d5c33 100644 --- a/pecan/commands/shell.py +++ b/pecan/commands/shell.py @@ -153,7 +153,7 @@ class ShellCommand(BaseCommand): shell = self.SHELLS[self.args.shell] try: shell().invoke(locs, banner) - except ImportError, e: + except ImportError as e: warn(( "%s is not installed, `%s`, " "falling back to native shell") % (self.args.shell, e), diff --git a/pecan/compat/dictconfig.py b/pecan/compat/dictconfig.py index d077d00..782d2b9 100644 --- a/pecan/compat/dictconfig.py +++ b/pecan/compat/dictconfig.py @@ -300,21 +300,21 @@ class DictConfigurator(BaseConfigurator): level = handler_config.get('level', None) if level: handler.setLevel(_checkLevel(level)) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure handler ' '%r: %s' % (name, e)) loggers = config.get('loggers', EMPTY_DICT) for name in loggers: try: self.configure_logger(name, loggers[name], True) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure logger ' '%r: %s' % (name, e)) root = config.get('root', None) if root: try: self.configure_root(root, True) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure root ' 'logger: %s' % e) else: @@ -329,7 +329,7 @@ class DictConfigurator(BaseConfigurator): try: formatters[name] = self.configure_formatter( formatters[name]) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure ' 'formatter %r: %s' % (name, e)) # Next, do filters - they don't refer to anything else, either @@ -337,7 +337,7 @@ class DictConfigurator(BaseConfigurator): for name in filters: try: filters[name] = self.configure_filter(filters[name]) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure ' 'filter %r: %s' % (name, e)) @@ -350,7 +350,7 @@ class DictConfigurator(BaseConfigurator): handler = self.configure_handler(handlers[name]) handler.name = name handlers[name] = handler - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure handler ' '%r: %s' % (name, e)) # Next, do loggers - they refer to handlers and filters @@ -389,7 +389,7 @@ class DictConfigurator(BaseConfigurator): existing.remove(name) try: self.configure_logger(name, loggers[name]) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure logger ' '%r: %s' % (name, e)) @@ -412,7 +412,7 @@ class DictConfigurator(BaseConfigurator): if root: try: self.configure_root(root) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure root ' 'logger: %s' % e) finally: @@ -424,7 +424,7 @@ class DictConfigurator(BaseConfigurator): factory = config['()'] # for use in exception handler try: result = self.configure_custom(config) - except TypeError, te: + except TypeError as te: if "'format'" not in str(te): raise #Name of parameter changed from fmt to format. @@ -454,7 +454,7 @@ class DictConfigurator(BaseConfigurator): for f in filters: try: filterer.addFilter(self.config['filters'][f]) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to add filter %r: %s' % (f, e)) def configure_handler(self, config): @@ -463,7 +463,7 @@ class DictConfigurator(BaseConfigurator): if formatter: try: formatter = self.config['formatters'][formatter] - except StandardError, e: + except StandardError as e: raise ValueError('Unable to set formatter ' '%r: %s' % (formatter, e)) level = config.pop('level', None) @@ -483,7 +483,7 @@ class DictConfigurator(BaseConfigurator): config['target'] = self.config['handlers'][ config['target'] ] - except StandardError, e: + except StandardError as e: raise ValueError('Unable to set target handler ' '%r: %s' % (config['target'], e)) elif issubclass(klass, logging.handlers.SMTPHandler) and\ @@ -496,7 +496,7 @@ class DictConfigurator(BaseConfigurator): kwargs = dict([(k, config[k]) for k in config if valid_ident(k)]) try: result = factory(**kwargs) - except TypeError, te: + except TypeError as te: if "'stream'" not in str(te): raise #The argument name changed from strm to stream @@ -518,7 +518,7 @@ class DictConfigurator(BaseConfigurator): for h in handlers: try: logger.addHandler(self.config['handlers'][h]) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to add handler %r: %s' % (h, e)) def common_logger_config(self, logger, config, incremental=False): diff --git a/pecan/core.py b/pecan/core.py index 4f5ad8a..e51b3d2 100644 --- a/pecan/core.py +++ b/pecan/core.py @@ -248,7 +248,7 @@ class Pecan(object): try: node, remainder = lookup_controller(node, path) return node, remainder - except NonCanonicalPath, e: + except NonCanonicalPath as e: if self.force_canonical and \ not _cfg(e.controller).get('accept_noncanonical', False): if req.method == 'POST': @@ -555,7 +555,7 @@ class Pecan(object): state.request.pecan = dict(content_type=None) self.handle_request(state.request, state.response) - except Exception, e: + except Exception as e: # if this is an HTTP Exception, set it as the response if isinstance(e, exc.HTTPException): state.response = e diff --git a/pecan/hooks.py b/pecan/hooks.py index 94fdd1b..8a6f9d6 100644 --- a/pecan/hooks.py +++ b/pecan/hooks.py @@ -304,7 +304,7 @@ class RequestViewerHook(PecanHook): value = getattr(state.request, request_info) else: value = value(self, state) - except Exception, e: + except Exception as e: value = e terminal.append('%-12s - %s\n' % (request_info, value)) diff --git a/pecan/middleware/errordocument.py b/pecan/middleware/errordocument.py index 4f8ac92..2559c9c 100644 --- a/pecan/middleware/errordocument.py +++ b/pecan/middleware/errordocument.py @@ -22,7 +22,7 @@ class StatusPersist(object): try: return self.app(environ, keep_status_start_response) - except RecursionLoop, e: + except RecursionLoop as e: environ['wsgi.errors'].write( 'Recursion error getting error page: %s\n' % e ) diff --git a/pecan/middleware/recursive.py b/pecan/middleware/recursive.py index f7471ec..b1296b8 100644 --- a/pecan/middleware/recursive.py +++ b/pecan/middleware/recursive.py @@ -54,7 +54,7 @@ class RecursiveMiddleware(object): environ['pecan.recursive.script_name'] = my_script_name try: return self.application(environ, start_response) - except ForwardRequestException, e: + except ForwardRequestException as e: middleware = CheckForRecursionMiddleware( e.factory(self), environ) return middleware(environ, start_response) diff --git a/pecan/routing.py b/pecan/routing.py index 5063fbe..8ebd7a9 100644 --- a/pecan/routing.py +++ b/pecan/routing.py @@ -50,7 +50,7 @@ def lookup_controller(obj, url_path): # crossing controller boundary cross_boundary(prev_obj, obj) break - except TypeError, te: + except TypeError as te: import warnings msg = 'Got exception calling lookup(): %s (%s)' warnings.warn( diff --git a/pecan/tests/middleware/test_recursive.py b/pecan/tests/middleware/test_recursive.py index 8cd213c..451155b 100644 --- a/pecan/tests/middleware/test_recursive.py +++ b/pecan/tests/middleware/test_recursive.py @@ -49,7 +49,7 @@ def forward(app): assert 'Page not found' in res try: res = app.get('/recurse') - except AssertionError, e: + except AssertionError as e: if str(e).startswith('Forwarding loop detected'): pass else: @@ -126,7 +126,7 @@ class TestRecursiveMiddleware(PecanTestCase): assert 'Page not found' in res try: res = app.get('/recurse') - except AssertionError, e: + except AssertionError as e: if str(e).startswith('Forwarding loop detected'): pass else: diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index d4b4371..8eb69f3 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -245,7 +245,7 @@ class TestControllerArguments(PecanTestCase): try: r = self.app_.get('/') assert r.status_int != 200 # pragma: nocover - except Exception, ex: + except Exception as ex: assert type(ex) == TypeError assert ex.args[0] == 'index() takes exactly 2 arguments (1 given)' @@ -644,7 +644,7 @@ class TestControllerArguments(PecanTestCase): try: r = self.app_.get('/eater') assert r.status_int != 200 # pragma: nocover - except Exception, ex: + except Exception as ex: assert type(ex) == TypeError assert ex.args[0] == 'eater() takes at least 2 arguments (1 given)' @@ -1090,7 +1090,7 @@ class TestCanonicalRouting(PecanTestCase): try: self.app_.post('/sub', dict(foo=1)) raise Exception("Post should fail") # pragma: nocover - except Exception, e: + except Exception as e: assert isinstance(e, RuntimeError) def test_with_args(self): @@ -1280,7 +1280,7 @@ class TestEngines(PecanTestCase): error_msg = None try: r = app.get('/badtemplate.html') - except Exception, e: + except Exception as e: for error_f in error_formatters: error_msg = error_f(e) if error_msg: @@ -1328,7 +1328,7 @@ class TestEngines(PecanTestCase): error_msg = None try: r = app.get('/badtemplate.html') - except Exception, e: + except Exception as e: for error_f in error_formatters: error_msg = error_f(e) if error_msg: @@ -1361,7 +1361,7 @@ class TestEngines(PecanTestCase): error_msg = None try: r = app.get('/badtemplate.html') - except Exception, e: + except Exception as e: for error_f in error_formatters: error_msg = error_f(e) if error_msg: diff --git a/pecan/tests/test_hooks.py b/pecan/tests/test_hooks.py index 8e103b2..df72e27 100644 --- a/pecan/tests/test_hooks.py +++ b/pecan/tests/test_hooks.py @@ -127,7 +127,7 @@ class TestHooks(PecanTestCase): run_hook = [] try: response = app.get('/causeerror') - except Exception, e: + except Exception as e: assert isinstance(e, IndexError) assert len(run_hook) == 2 diff --git a/pecan/tests/test_secure.py b/pecan/tests/test_secure.py index 1fb1fd9..1f48037 100644 --- a/pecan/tests/test_secure.py +++ b/pecan/tests/test_secure.py @@ -187,7 +187,7 @@ class TestSecure(PecanTestCase): try: secure(Foo()) - except Exception, e: + except Exception as e: assert isinstance(e, TypeError)