Skip to content
Myr

Merge branch 'pr/839'

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

authored by Armin Ronacher · committed by Armin Ronacher · parents 2639a23, 3d67736 · Browse files · 3 files+49 added−3 removed
This commit

State

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

Diff stats

3 files+49 added−3 removed

  • other:+49 added−3 removed

3 files+49 added−3 removed

modified:flask/testsuite/basic.py+40 added-1 removed
17 unmodified lines
18from datetime import datetime19from threading import Thread20from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning21from flask._compat import text_type22from werkzeug.exceptions import BadRequest, NotFound22from werkzeug.exceptions import BadRequest, NotFound, Forbidden23from werkzeug.http import parse_date24from werkzeug.routing import BuildError2526
599 unmodified lines
626 return 'not found', 404627 @app.errorhandler(500)628 def internal_server_error(e):629 return 'internal server error', 500630 @app.errorhandler(Forbidden)631 def forbidden(e):632 return 'forbidden', 403633 @app.route('/')634 def index():635 flask.abort(404)636 @app.route('/error')637 def error():638 1 // 0639 @app.route('/forbidden')640 def error2():641 flask.abort(403)642 c = app.test_client()643 rv = c.get('/')644 self.assert_equal(rv.status_code, 404)645 self.assert_equal(rv.data, b'not found')646 rv = c.get('/error')647 self.assert_equal(rv.status_code, 500)648 self.assert_equal(b'internal server error', rv.data)649 rv = c.get('/forbidden')650 self.assert_equal(rv.status_code, 403)651 self.assert_equal(b'forbidden', rv.data)652653 def test_before_request_and_routing_errors(self):654 app = flask.Flask(__name__)655 @app.before_request
21 unmodified lines
677678 c = app.test_client()679 self.assert_equal(c.get('/').data, b'42')680681 def test_http_error_subclass_handling(self):682 class ForbiddenSubclass(Forbidden):683 pass684685 app = flask.Flask(__name__)686 @app.errorhandler(ForbiddenSubclass)687 def handle_forbidden_subclass(e):688 self.assert_true(isinstance(e, ForbiddenSubclass))689 return 'banana'690 @app.errorhandler(403)691 def handle_forbidden_subclass(e):692 self.assert_false(isinstance(e, ForbiddenSubclass))693 self.assert_true(isinstance(e, Forbidden))694 return 'apple'695696 @app.route('/1')697 def index1():698 raise ForbiddenSubclass()699 @app.route('/2')700 def index2():701 flask.abort(403)702 @app.route('/3')703 def index3():704 raise Forbidden()705706 c = app.test_client()707 self.assert_equal(c.get('/1').data, b'banana')708 self.assert_equal(c.get('/2').data, b'apple')709 self.assert_equal(c.get('/3').data, b'apple')710711 def test_trapping_of_bad_request_key_errors(self):712 app = flask.Flask(__name__)713 app.testing = True714 @app.route('/fail')
680 unmodified lines
modified:flask/app.py+3 added-2 removed
1439 unmodified lines
1440 # ensure not to trash sys.exc_info() at that point in case someone1441 # wants the traceback preserved in handle_http_exception. Of course1442 # we cannot prevent users from trashing it themselves in a custom1443 # trap_http_exception method so that's their fault then.1444 if isinstance(e, HTTPException) and not self.trap_http_exception(e):1445 return self.handle_http_exception(e)14441445 blueprint_handlers = ()1446 handlers = self.error_handler_spec.get(request.blueprint)1447 if handlers is not None:
2 unmodified lines
1450 for typecheck, handler in chain(blueprint_handlers, app_handlers):1451 if isinstance(e, typecheck):1452 return handler(e)14531454 if isinstance(e, HTTPException) and not self.trap_http_exception(e):1455 return self.handle_http_exception(e)14561457 reraise(exc_type, exc_value, tb)14581459 def handle_exception(self, e):1460 """Default exception handling that kicks in when an exception
463 unmodified lines
modified:CHANGES+6 added
28 unmodified lines
29- Added ``flask`` and the ``flask.cli`` module to start the local30 debug server through the click CLI system. This is recommended over the old31 ``flask.run()`` method as it works faster and more reliable due to a32 different design and also replaces ``Flask-Script``.33- Error handlers that match specific classes are now checked first,34 thereby allowing catching exceptions that are subclasses of HTTP35 exceptions (in ``werkzeug.execptions``). This makes it possible36 for an extension author to create exceptions that will by default37 result in the HTTP error of their choosing, but may be caught with38 a custom error handler if desired.3940Version 0.10.241--------------42
478 unmodified lines