Skip to content
Myr

automated change using python-modernize: use 'as' in except

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Thomas Waldmann · committed by Thomas Waldmann · parent 521398d · Browse files · 12 files+32 added−32 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

12 files+32 added−32 removed

  • other:+32 added−32 removed

12 files+32 added−32 removed

modified:flask/testsuite/__init__.py+1 added-1 removed
218 unmodified lines
219def main():220 """Runs the testsuite as command line application."""221 try:222 unittest.main(testLoader=BetterLoader(), defaultTest='suite')223 except Exception, e:223 except Exception as e:224 print 'Error: %s' % e
modified:flask/testsuite/basic.py+10 added-10 removed
254 unmodified lines
255 app = flask.Flask(__name__)256 def expect_exception(f, *args, **kwargs):257 try:258 f(*args, **kwargs)259 except RuntimeError, e:259 except RuntimeError as e:260 self.assert_(e.args and 'session is unavailable' in e.args[0])261 else:262 self.assert_(False, 'expected exception')263 with app.test_request_context():
364 unmodified lines
628 app.config['TRAP_BAD_REQUEST_ERRORS'] = True629 c = app.test_client()630 try:631 c.get('/fail')632 except KeyError, e:632 except KeyError as e:633 self.assert_(isinstance(e, BadRequest))634 else:635 self.fail('Expected exception')636
7 unmodified lines
644645 c = app.test_client()646 try:647 c.get('/fail')648 except NotFound, e:648 except NotFound as e:649 pass650 else:651 self.fail('Expected exception')652
10 unmodified lines
663 # to not negatively affect other tests.664 with app.test_client() as c:665 try:666 c.post('/fail', data={'foo': 'index.txt'})667 except DebugFilesKeyError, e:667 except DebugFilesKeyError as e:668 self.assert_('no file contents were transmitted' in str(e))669 self.assert_('This was submitted: "index.txt"' in str(e))670 else:671 self.fail('Expected exception')
82 unmodified lines
754 # Verify the error is re-raised if not the current exception.755 try:756 with app.test_request_context():757 flask.url_for('spam')758 except BuildError, error:758 except BuildError as error:759 pass760 try:761 raise RuntimeError('Test case where BuildError is not current.')762 except RuntimeError:
38 unmodified lines
801 def test():802 return None803 try:804 app.test_client().get('/')805 except ValueError, e:805 except ValueError as e:806 self.assert_equal(str(e), 'View function did not return a response')807 pass808 else:809 self.assert_("Expected ValueError")
32 unmodified lines
842 app.config.update(SERVER_NAME='localhost.localdomain:443')843 rv = app.test_client().get('/', 'https://localhost.localdomain')844 # Werkzeug 0.8845 self.assert_equal(rv.status_code, 404)846 except ValueError, e:846 except ValueError as e:847 # Werkzeug 0.7848 self.assert_equal(str(e), "the server name provided " +849 "('localhost.localdomain:443') does not match the " + \850 "server name from the WSGI environment ('localhost.localdomain')")
2 unmodified lines
853 app.config.update(SERVER_NAME='localhost.localdomain')854 rv = app.test_client().get('/', 'http://foo.localhost')855 # Werkzeug 0.8856 self.assert_equal(rv.status_code, 404)857 except ValueError, e:857 except ValueError as e:858 # Werkzeug 0.7859 self.assert_equal(str(e), "the server name provided " + \860 "('localhost.localdomain') does not match the " + \861 "server name from the WSGI environment ('foo.localhost')")
112 unmodified lines
974 try:975 @app.route('/foo')976 def broken():977 return 'Meh'978 except AssertionError, e:978 except AssertionError as e:979 self.assert_('A setup function was called' in str(e))980 else:981 self.fail('Expected exception')982
25 unmodified lines
1008 return 'success'1009 with app.test_client() as c:1010 try:1011 c.post('/foo', data={})1012 except AssertionError, e:1012 except AssertionError as e:1013 self.assert_('http://localhost/foo/' in str(e))1014 self.assert_('Make sure to directly send your POST-request '1015 'to this URL' in str(e))1016 else:
136 unmodified lines
modified:flask/testsuite/blueprints.py+2 added-2 removed
181 unmodified lines
182183 with app.test_request_context():184 try:185 flask.render_template('missing.html')186 except TemplateNotFound, e:186 except TemplateNotFound as e:187 self.assert_equal(e.name, 'missing.html')188 else:189 self.assert_(0, 'expected exception')190
186 unmodified lines
377378 with app.test_request_context():379 try:380 flask.render_template('missing.html')381 except TemplateNotFound, e:381 except TemplateNotFound as e:382 self.assert_equal(e.name, 'missing.html')383 else:384 self.assert_(0, 'expected exception')385
381 unmodified lines
modified:flask/testsuite/config.py+4 added-4 removed
55 unmodified lines
56 os.environ = {}57 app = flask.Flask(__name__)58 try:59 app.config.from_envvar('FOO_SETTINGS')60 except RuntimeError, e:60 except RuntimeError as e:61 self.assert_("'FOO_SETTINGS' is not set" in str(e))62 else:63 self.assert_(0, 'expected exception')64 self.assert_(not app.config.from_envvar('FOO_SETTINGS', silent=True))
10 unmodified lines
75 os.environ = {'FOO_SETTINGS': 'missing.cfg'}76 try:77 app = flask.Flask(__name__)78 app.config.from_envvar('FOO_SETTINGS')79 except IOError, e:79 except IOError as e:80 msg = str(e)81 self.assert_(msg.startswith('[Errno 2] Unable to load configuration '82 'file (No such file or directory):'))83 self.assert_(msg.endswith("missing.cfg'"))
6 unmodified lines
90 def test_config_missing(self):91 app = flask.Flask(__name__)92 try:93 app.config.from_pyfile('missing.cfg')94 except IOError, e:94 except IOError as e:95 msg = str(e)96 self.assert_(msg.startswith('[Errno 2] Unable to load configuration '97 'file (No such file or directory):'))98 self.assert_(msg.endswith("missing.cfg'"))
41 unmodified lines
140 def test_explicit_instance_paths(self):141 here = os.path.abspath(os.path.dirname(__file__))142 try:143 flask.Flask(__name__, instance_path='instance')144 except ValueError, e:144 except ValueError as e:145 self.assert_('must be absolute' in str(e))146 else:147 self.fail('Expected value error')148
152 unmodified lines
modified:flask/testsuite/reqctx.py+3 added-3 removed
56 unmodified lines
5758 try:59 with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}):60 pass61 except Exception, e:61 except Exception as e:62 self.assert_(isinstance(e, ValueError))63 self.assert_equal(str(e), "the server name provided " +64 "('localhost.localdomain:5000') does not match the " + \65 "server name from the WSGI environment ('localhost')")
1 unmodified line
67 try:68 app.config.update(SERVER_NAME='localhost')69 with app.test_request_context('/', environ_overrides={'SERVER_NAME': 'localhost'}):70 pass71 except ValueError, e:71 except ValueError as e:72 raise ValueError(73 "No ValueError exception should have been raised \"%s\"" % e74 )7576 try:77 app.config.update(SERVER_NAME='localhost:80')78 with app.test_request_context('/', environ_overrides={'SERVER_NAME': 'localhost:80'}):79 pass80 except ValueError, e:80 except ValueError as e:81 raise ValueError(82 "No ValueError exception should have been raised \"%s\"" % e83 )84
103 unmodified lines
modified:flask/testsuite/testing.py+2 added-2 removed
104 unmodified lines
105 with app.test_client() as c:106 try:107 with c.session_transaction() as sess:108 pass109 except RuntimeError, e:109 except RuntimeError as e:110 self.assert_('Session backend did not open a session' in str(e))111 else:112 self.fail('Expected runtime error')113
15 unmodified lines
129 c = app.test_client(use_cookies=False)130 try:131 with c.session_transaction() as s:132 pass133 except RuntimeError, e:133 except RuntimeError as e:134 self.assert_('cookies' in str(e))135 else:136 self.fail('Expected runtime error')137
106 unmodified lines
modified:flask/app.py+5 added-5 removed
1476 unmodified lines
1477 request_started.send(self)1478 rv = self.preprocess_request()1479 if rv is None:1480 rv = self.dispatch_request()1481 except Exception, e:1481 except Exception as e:1482 rv = self.handle_user_exception(e)1483 response = self.make_response(rv)1484 response = self.process_response(response)1485 request_finished.send(self, response=response)
29 unmodified lines
1515 # fallback for Werkzeug < 0.71516 methods = []1517 try:1518 adapter.match(method='--')1519 except MethodNotAllowed, e:1519 except MethodNotAllowed as e:1520 methods = e.valid_methods1521 except HTTPException, e:1521 except HTTPException as e:1522 pass1523 rv = self.response_class()1524 rv.allow.update(methods)1525 return rv
99 unmodified lines
1625 try:1626 rv = handler(error, endpoint, values)1627 if rv is not None:1628 return rv1629 except BuildError, error:1629 except BuildError as error:1630 pass16311632 # At this point we want to reraise the exception. If the error is1633 # still the same one we can reraise it with the original traceback,
172 unmodified lines
1806 """1807 with self.request_context(environ):1808 try:1809 response = self.full_dispatch_request()1810 except Exception, e:1810 except Exception as e:1811 response = self.make_response(self.handle_exception(e))1812 return response(environ, start_response)18131814 @property
15 unmodified lines
modified:flask/config.py+1 added-1 removed
125 unmodified lines
126 d = imp.new_module('config')127 d.__file__ = filename128 try:129 execfile(filename, d.__dict__)130 except IOError, e:130 except IOError as e:131 if silent and e.errno in (errno.ENOENT, errno.EISDIR):132 return False133 e.strerror = 'Unable to load configuration file (%s)' % e.strerror134 raise
34 unmodified lines
modified:flask/ctx.py+1 added-1 removed
277 unmodified lines
278 try:279 url_rule, self.request.view_args = \280 self.url_adapter.match(return_rule=True)281 self.request.url_rule = url_rule282 except HTTPException, e:282 except HTTPException as e:283 self.request.routing_exception = e284285 def push(self):286 """Binds the request context to the current context."""
86 unmodified lines
modified:flask/debughelpers.py+1 added-1 removed
74 unmodified lines
75 class newcls(oldcls):76 def __getitem__(self, key):77 try:78 return oldcls.__getitem__(self, key)79 except KeyError, e:79 except KeyError as e:80 if key not in request.form:81 raise82 raise DebugFilesKeyError(request, key)83 newcls.__name__ = oldcls.__name__
2 unmodified lines
modified:flask/helpers.py+1 added-1 removed
299 unmodified lines
300301 try:302 rv = url_adapter.build(endpoint, values, method=method,303 force_external=external)304 except BuildError, error:304 except BuildError as error:305 # We need to inject the values again so that the app callback can306 # deal with that sort of stuff.307 values['_external'] = external308 values['_anchor'] = anchor
537 unmodified lines
modified:flask/wrappers.py+1 added-1 removed
99 unmodified lines
100 try:101 if request_charset is not None:102 return json.loads(self.data, encoding=request_charset)103 return json.loads(self.data)104 except ValueError, e:104 except ValueError as e:105 return self.on_json_loading_failed(e)106107 def on_json_loading_failed(self, e):108 """Called if decoding of the JSON data failed. The return value of
38 unmodified lines