From 8c054f04b87dc7d713495d91fdb4d52bdef0e643 Mon Sep 17 00:00:00 2001 From: Phil Schaf Date: Sat, 3 Jan 2015 01:31:38 +0100 Subject: [PATCH] added caching --- flask/app.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/flask/app.py b/flask/app.py index 6fc95c2c..9c6d5064 100644 --- a/flask/app.py +++ b/flask/app.py @@ -1079,14 +1079,12 @@ class Flask(_PackageBoundObject): return decorator @staticmethod - def _ensure_exc_class(exc_class_or_code): + def _get_exc_class_and_code(exc_class_or_code): """ensure that we register only exceptions as handler keys""" if isinstance(exc_class_or_code, integer_types): exc_class = default_exceptions[exc_class_or_code] - elif isinstance(exc_class_or_code, type): - exc_class = exc_class_or_code else: - exc_class = type(exc_class_or_code) + exc_class = exc_class_or_code assert issubclass(exc_class, Exception) @@ -1164,7 +1162,7 @@ class Flask(_PackageBoundObject): 'Handlers can only be registered for exception classes or HTTP error codes.' .format(code_or_exception)) - exc_class, code = self._ensure_exc_class(code_or_exception) + exc_class, code = self._get_exc_class_and_code(code_or_exception) handlers = self.error_handler_spec.setdefault(key, {}).setdefault(code, {}) handlers[exc_class] = f @@ -1412,7 +1410,7 @@ class Flask(_PackageBoundObject): """Finds a registered error handler for the request’s blueprint. If neither blueprint nor App has a suitable handler registered, returns None """ - exc_class, code = self._ensure_exc_class(e) + exc_class, code = self._get_exc_class_and_code(type(e)) def find_superclass(d): if not d: @@ -1422,6 +1420,7 @@ class Flask(_PackageBoundObject): return None handler = d.get(superclass) if handler is not None: + d[exc_class] = handler # cache for next time exc_class is raised return handler return None