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.
master
Dustin 2016-07-10 20:12:53 -05:00
parent 71d00e4207
commit ff27f3a917
1 changed files with 8 additions and 6 deletions

View File

@ -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): class BaseApplication(object):
'''Base class for Milla applications '''Base class for Milla applications
@ -88,12 +96,6 @@ class BaseApplication(object):
# The callable might have returned just a string, which is OK, # The callable might have returned just a string, which is OK,
# but we need to wrap it in a Response object # 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: if isinstance(response, _string) or not response:
response = request.ResponseClass(response) response = request.ResponseClass(response)