Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 19 additions & 26 deletions webapp2.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from webob import exc


_webapp = _webapp_util = _local = None
_local = None


try: # pragma: no cover
Expand All @@ -65,15 +65,6 @@
html = cgi


# google.appengine.ext.webapp imports webapp2 in the
# App Engine Python 2.7 runtime.
if os.environ.get('APPENGINE_RUNTIME') != 'python27': # pragma: no cover
try:
from google.appengine.ext import webapp as _webapp
except ImportError: # pragma: no cover
# Running webapp2 outside of GAE.
pass

try: # pragma: no cover
# Thread-local variables container.
from webapp2_extras import local
Expand Down Expand Up @@ -1341,12 +1332,18 @@ class and function views or, for compatibility purposes, a
A wrapped handler callable.
"""
if inspect.isclass(handler):
if _webapp and issubclass(handler, _webapp.RequestHandler):
# Compatible with webapp.RequestHandler.
adapter = WebappHandlerAdapter
else:
# Default, compatible with webapp2.RequestHandler.
adapter = Webapp2HandlerAdapter
# Default, compatible with webapp2.RequestHandler.
adapter = Webapp2HandlerAdapter
try:
# There is an import cycle between webapp and webapp2.
# We import webapp lazily so the cycle doesn't cause problems
# during module initialization.
from google.appengine.ext import webapp as _webapp
if issubclass(handler, _webapp.RequestHandler):
# Compatible with webapp.RequestHandler.
adapter = WebappHandlerAdapter
except ImportError: # pragma: no cover
pass
else:
# A "view" function.
adapter = BaseHandlerAdapter
Expand Down Expand Up @@ -1659,12 +1656,16 @@ def run(self, bare=False):
If True, doesn't add registered WSGI middleware: use
``run_bare_wsgi_app`` instead of ``run_wsgi_app``.
"""
if _webapp_util:
try:
# There is an import cycle between webapp and webapp2.
# We import webapp lazily so the cycle doesn't cause problems
# during module initialization.
from google.appengine.ext.webapp import util as _webapp_util
if bare:
_webapp_util.run_bare_wsgi_app(self)
else:
_webapp_util.run_wsgi_app(self)
else: # pragma: no cover
except ImportError: # pragma: no cover
handlers.CGIHandler().run(self)

def get_response(self, *args, **kwargs):
Expand Down Expand Up @@ -2053,11 +2054,3 @@ def _set_thread_safe_app():
_abort = abort
# Thread-safety support.
_set_thread_safe_app()

# Defer importing google.appengine.ext.webapp.util until every public symbol
# has been defined since google.appengine.ext.webapp in App Engine Python 2.7
# runtime imports this module to provide its public interface.
try:
from google.appengine.ext.webapp import util as _webapp_util
except ImportError: # pragma: no cover
pass