From ff27f3a917970526e42ef66c5f4b188d3cad8b80 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sun, 10 Jul 2016 20:12:53 -0500 Subject: [PATCH] app: Don't check Python version for every request Checking for the `basestring` name takes a nonzero amount of time, the result of the check never changes. As such, is not appropriate to do this for every request. --- src/milla/app.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/milla/app.py b/src/milla/app.py index 3469413..67e2392 100644 --- a/src/milla/app.py +++ b/src/milla/app.py @@ -40,6 +40,14 @@ __all__ = [ ] +try: + # In Python 2, it could be a str or a unicode object + _string = basestring +except NameError: + # In Python 3, we are only interested in str objects + _string = str + + class BaseApplication(object): '''Base class for Milla applications @@ -88,12 +96,6 @@ class BaseApplication(object): # The callable might have returned just a string, which is OK, # but we need to wrap it in a Response object - try: - # In Python 2, it could be a str or a unicode object - _string = basestring - except NameError: - # In Python 3, we are only interested in str objects - _string = str if isinstance(response, _string) or not response: response = request.ResponseClass(response)