automated change using python-modernize: use 'as' in except
This commit is contained in:
parent
521398d5e7
commit
6caaa8a527
12 changed files with 32 additions and 32 deletions
10
flask/app.py
10
flask/app.py
|
|
@ -1478,7 +1478,7 @@ class Flask(_PackageBoundObject):
|
|||
rv = self.preprocess_request()
|
||||
if rv is None:
|
||||
rv = self.dispatch_request()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
rv = self.handle_user_exception(e)
|
||||
response = self.make_response(rv)
|
||||
response = self.process_response(response)
|
||||
|
|
@ -1516,9 +1516,9 @@ class Flask(_PackageBoundObject):
|
|||
methods = []
|
||||
try:
|
||||
adapter.match(method='--')
|
||||
except MethodNotAllowed, e:
|
||||
except MethodNotAllowed as e:
|
||||
methods = e.valid_methods
|
||||
except HTTPException, e:
|
||||
except HTTPException as e:
|
||||
pass
|
||||
rv = self.response_class()
|
||||
rv.allow.update(methods)
|
||||
|
|
@ -1626,7 +1626,7 @@ class Flask(_PackageBoundObject):
|
|||
rv = handler(error, endpoint, values)
|
||||
if rv is not None:
|
||||
return rv
|
||||
except BuildError, error:
|
||||
except BuildError as error:
|
||||
pass
|
||||
|
||||
# At this point we want to reraise the exception. If the error is
|
||||
|
|
@ -1807,7 +1807,7 @@ class Flask(_PackageBoundObject):
|
|||
with self.request_context(environ):
|
||||
try:
|
||||
response = self.full_dispatch_request()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
response = self.make_response(self.handle_exception(e))
|
||||
return response(environ, start_response)
|
||||
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ class Config(dict):
|
|||
d.__file__ = filename
|
||||
try:
|
||||
execfile(filename, d.__dict__)
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
if silent and e.errno in (errno.ENOENT, errno.EISDIR):
|
||||
return False
|
||||
e.strerror = 'Unable to load configuration file (%s)' % e.strerror
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ class RequestContext(object):
|
|||
url_rule, self.request.view_args = \
|
||||
self.url_adapter.match(return_rule=True)
|
||||
self.request.url_rule = url_rule
|
||||
except HTTPException, e:
|
||||
except HTTPException as e:
|
||||
self.request.routing_exception = e
|
||||
|
||||
def push(self):
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ def attach_enctype_error_multidict(request):
|
|||
def __getitem__(self, key):
|
||||
try:
|
||||
return oldcls.__getitem__(self, key)
|
||||
except KeyError, e:
|
||||
except KeyError as e:
|
||||
if key not in request.form:
|
||||
raise
|
||||
raise DebugFilesKeyError(request, key)
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ def url_for(endpoint, **values):
|
|||
try:
|
||||
rv = url_adapter.build(endpoint, values, method=method,
|
||||
force_external=external)
|
||||
except BuildError, error:
|
||||
except BuildError as error:
|
||||
# We need to inject the values again so that the app callback can
|
||||
# deal with that sort of stuff.
|
||||
values['_external'] = external
|
||||
|
|
|
|||
|
|
@ -220,5 +220,5 @@ def main():
|
|||
"""Runs the testsuite as command line application."""
|
||||
try:
|
||||
unittest.main(testLoader=BetterLoader(), defaultTest='suite')
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
print 'Error: %s' % e
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
def expect_exception(f, *args, **kwargs):
|
||||
try:
|
||||
f(*args, **kwargs)
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
self.assert_(e.args and 'session is unavailable' in e.args[0])
|
||||
else:
|
||||
self.assert_(False, 'expected exception')
|
||||
|
|
@ -629,7 +629,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
c = app.test_client()
|
||||
try:
|
||||
c.get('/fail')
|
||||
except KeyError, e:
|
||||
except KeyError as e:
|
||||
self.assert_(isinstance(e, BadRequest))
|
||||
else:
|
||||
self.fail('Expected exception')
|
||||
|
|
@ -645,7 +645,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
c = app.test_client()
|
||||
try:
|
||||
c.get('/fail')
|
||||
except NotFound, e:
|
||||
except NotFound as e:
|
||||
pass
|
||||
else:
|
||||
self.fail('Expected exception')
|
||||
|
|
@ -664,7 +664,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
with app.test_client() as c:
|
||||
try:
|
||||
c.post('/fail', data={'foo': 'index.txt'})
|
||||
except DebugFilesKeyError, e:
|
||||
except DebugFilesKeyError as e:
|
||||
self.assert_('no file contents were transmitted' in str(e))
|
||||
self.assert_('This was submitted: "index.txt"' in str(e))
|
||||
else:
|
||||
|
|
@ -755,7 +755,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
try:
|
||||
with app.test_request_context():
|
||||
flask.url_for('spam')
|
||||
except BuildError, error:
|
||||
except BuildError as error:
|
||||
pass
|
||||
try:
|
||||
raise RuntimeError('Test case where BuildError is not current.')
|
||||
|
|
@ -802,7 +802,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
return None
|
||||
try:
|
||||
app.test_client().get('/')
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
self.assert_equal(str(e), 'View function did not return a response')
|
||||
pass
|
||||
else:
|
||||
|
|
@ -843,7 +843,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
rv = app.test_client().get('/', 'https://localhost.localdomain')
|
||||
# Werkzeug 0.8
|
||||
self.assert_equal(rv.status_code, 404)
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
# Werkzeug 0.7
|
||||
self.assert_equal(str(e), "the server name provided " +
|
||||
"('localhost.localdomain:443') does not match the " + \
|
||||
|
|
@ -854,7 +854,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
rv = app.test_client().get('/', 'http://foo.localhost')
|
||||
# Werkzeug 0.8
|
||||
self.assert_equal(rv.status_code, 404)
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
# Werkzeug 0.7
|
||||
self.assert_equal(str(e), "the server name provided " + \
|
||||
"('localhost.localdomain') does not match the " + \
|
||||
|
|
@ -975,7 +975,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
@app.route('/foo')
|
||||
def broken():
|
||||
return 'Meh'
|
||||
except AssertionError, e:
|
||||
except AssertionError as e:
|
||||
self.assert_('A setup function was called' in str(e))
|
||||
else:
|
||||
self.fail('Expected exception')
|
||||
|
|
@ -1009,7 +1009,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
with app.test_client() as c:
|
||||
try:
|
||||
c.post('/foo', data={})
|
||||
except AssertionError, e:
|
||||
except AssertionError as e:
|
||||
self.assert_('http://localhost/foo/' in str(e))
|
||||
self.assert_('Make sure to directly send your POST-request '
|
||||
'to this URL' in str(e))
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ class ModuleTestCase(FlaskTestCase):
|
|||
with app.test_request_context():
|
||||
try:
|
||||
flask.render_template('missing.html')
|
||||
except TemplateNotFound, e:
|
||||
except TemplateNotFound as e:
|
||||
self.assert_equal(e.name, 'missing.html')
|
||||
else:
|
||||
self.assert_(0, 'expected exception')
|
||||
|
|
@ -378,7 +378,7 @@ class BlueprintTestCase(FlaskTestCase):
|
|||
with app.test_request_context():
|
||||
try:
|
||||
flask.render_template('missing.html')
|
||||
except TemplateNotFound, e:
|
||||
except TemplateNotFound as e:
|
||||
self.assert_equal(e.name, 'missing.html')
|
||||
else:
|
||||
self.assert_(0, 'expected exception')
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class ConfigTestCase(FlaskTestCase):
|
|||
app = flask.Flask(__name__)
|
||||
try:
|
||||
app.config.from_envvar('FOO_SETTINGS')
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
self.assert_("'FOO_SETTINGS' is not set" in str(e))
|
||||
else:
|
||||
self.assert_(0, 'expected exception')
|
||||
|
|
@ -76,7 +76,7 @@ class ConfigTestCase(FlaskTestCase):
|
|||
try:
|
||||
app = flask.Flask(__name__)
|
||||
app.config.from_envvar('FOO_SETTINGS')
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
msg = str(e)
|
||||
self.assert_(msg.startswith('[Errno 2] Unable to load configuration '
|
||||
'file (No such file or directory):'))
|
||||
|
|
@ -91,7 +91,7 @@ class ConfigTestCase(FlaskTestCase):
|
|||
app = flask.Flask(__name__)
|
||||
try:
|
||||
app.config.from_pyfile('missing.cfg')
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
msg = str(e)
|
||||
self.assert_(msg.startswith('[Errno 2] Unable to load configuration '
|
||||
'file (No such file or directory):'))
|
||||
|
|
@ -141,7 +141,7 @@ class InstanceTestCase(FlaskTestCase):
|
|||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
try:
|
||||
flask.Flask(__name__, instance_path='instance')
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
self.assert_('must be absolute' in str(e))
|
||||
else:
|
||||
self.fail('Expected value error')
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class RequestContextTestCase(FlaskTestCase):
|
|||
try:
|
||||
with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}):
|
||||
pass
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.assert_(isinstance(e, ValueError))
|
||||
self.assert_equal(str(e), "the server name provided " +
|
||||
"('localhost.localdomain:5000') does not match the " + \
|
||||
|
|
@ -68,7 +68,7 @@ class RequestContextTestCase(FlaskTestCase):
|
|||
app.config.update(SERVER_NAME='localhost')
|
||||
with app.test_request_context('/', environ_overrides={'SERVER_NAME': 'localhost'}):
|
||||
pass
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
raise ValueError(
|
||||
"No ValueError exception should have been raised \"%s\"" % e
|
||||
)
|
||||
|
|
@ -77,7 +77,7 @@ class RequestContextTestCase(FlaskTestCase):
|
|||
app.config.update(SERVER_NAME='localhost:80')
|
||||
with app.test_request_context('/', environ_overrides={'SERVER_NAME': 'localhost:80'}):
|
||||
pass
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
raise ValueError(
|
||||
"No ValueError exception should have been raised \"%s\"" % e
|
||||
)
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ class TestToolsTestCase(FlaskTestCase):
|
|||
try:
|
||||
with c.session_transaction() as sess:
|
||||
pass
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
self.assert_('Session backend did not open a session' in str(e))
|
||||
else:
|
||||
self.fail('Expected runtime error')
|
||||
|
|
@ -130,7 +130,7 @@ class TestToolsTestCase(FlaskTestCase):
|
|||
try:
|
||||
with c.session_transaction() as s:
|
||||
pass
|
||||
except RuntimeError, e:
|
||||
except RuntimeError as e:
|
||||
self.assert_('cookies' in str(e))
|
||||
else:
|
||||
self.fail('Expected runtime error')
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ class Request(RequestBase):
|
|||
if request_charset is not None:
|
||||
return json.loads(self.data, encoding=request_charset)
|
||||
return json.loads(self.data)
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
return self.on_json_loading_failed(e)
|
||||
|
||||
def on_json_loading_failed(self, e):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue