Update exception block syntax.

This commit is contained in:
Ryan Petrello
2013-04-30 11:24:51 -04:00
parent 79c379daef
commit 0d641362eb
13 changed files with 33 additions and 33 deletions

View File

@@ -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})

View File

@@ -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
)

View File

@@ -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),

View File

@@ -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):

View File

@@ -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

View File

@@ -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))

View File

@@ -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
)

View File

@@ -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)

View File

@@ -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(

View File

@@ -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:

View File

@@ -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:

View File

@@ -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

View File

@@ -187,7 +187,7 @@ class TestSecure(PecanTestCase):
try:
secure(Foo())
except Exception, e:
except Exception as e:
assert isinstance(e, TypeError)