From 6caaa8a527134dc9aff6d5c442969e96f9c00f21 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 18 May 2013 16:24:40 +0200 Subject: [PATCH] automated change using python-modernize: use 'as' in except --- flask/app.py | 10 +++++----- flask/config.py | 2 +- flask/ctx.py | 2 +- flask/debughelpers.py | 2 +- flask/helpers.py | 2 +- flask/testsuite/__init__.py | 2 +- flask/testsuite/basic.py | 20 ++++++++++---------- flask/testsuite/blueprints.py | 4 ++-- flask/testsuite/config.py | 8 ++++---- flask/testsuite/reqctx.py | 6 +++--- flask/testsuite/testing.py | 4 ++-- flask/wrappers.py | 2 +- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/flask/app.py b/flask/app.py index cc9a2f90..3204e13f 100644 --- a/flask/app.py +++ b/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) diff --git a/flask/config.py b/flask/config.py index 759fd488..80e9983e 100644 --- a/flask/config.py +++ b/flask/config.py @@ -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 diff --git a/flask/ctx.py b/flask/ctx.py index 6b271687..a02c9a86 100644 --- a/flask/ctx.py +++ b/flask/ctx.py @@ -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): diff --git a/flask/debughelpers.py b/flask/debughelpers.py index 3ebd2f3e..504fab93 100644 --- a/flask/debughelpers.py +++ b/flask/debughelpers.py @@ -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) diff --git a/flask/helpers.py b/flask/helpers.py index d24dde6b..d68cb04b 100644 --- a/flask/helpers.py +++ b/flask/helpers.py @@ -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 diff --git a/flask/testsuite/__init__.py b/flask/testsuite/__init__.py index 5d86fa3d..084b3726 100644 --- a/flask/testsuite/__init__.py +++ b/flask/testsuite/__init__.py @@ -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 diff --git a/flask/testsuite/basic.py b/flask/testsuite/basic.py index 5f6dbe4b..2836a1b6 100644 --- a/flask/testsuite/basic.py +++ b/flask/testsuite/basic.py @@ -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)) diff --git a/flask/testsuite/blueprints.py b/flask/testsuite/blueprints.py index ea047918..0399d48e 100644 --- a/flask/testsuite/blueprints.py +++ b/flask/testsuite/blueprints.py @@ -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') diff --git a/flask/testsuite/config.py b/flask/testsuite/config.py index bf72925b..0b2c65bd 100644 --- a/flask/testsuite/config.py +++ b/flask/testsuite/config.py @@ -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') diff --git a/flask/testsuite/reqctx.py b/flask/testsuite/reqctx.py index a93523e7..89a47728 100644 --- a/flask/testsuite/reqctx.py +++ b/flask/testsuite/reqctx.py @@ -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 ) diff --git a/flask/testsuite/testing.py b/flask/testsuite/testing.py index 92e3f267..605078a7 100644 --- a/flask/testsuite/testing.py +++ b/flask/testsuite/testing.py @@ -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') diff --git a/flask/wrappers.py b/flask/wrappers.py index a56fe5d7..717d8ce5 100644 --- a/flask/wrappers.py +++ b/flask/wrappers.py @@ -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):