Skip to content

Commit

Permalink
Merge pull request #170 from bendemaree/appengine-mro-fix
Browse files Browse the repository at this point in the history
AppEngine monkeypatching MRO fix
  • Loading branch information
sigmavirus24 committed Jan 12, 2017
2 parents 41f36f9 + 258a97b commit 594b77a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion requests_toolbelt/adapters/appengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,24 @@
from .._compat import timeout


class AppEngineAdapter(adapters.HTTPAdapter):
class AppEngineMROHack(adapters.HTTPAdapter):
"""Resolves infinite recursion when monkeypatching.
This works by injecting itself as the base class of both the
:class:`AppEngineAdapter` and Requests' default HTTPAdapter, which needs to
be done because default HTTPAdapter's MRO is recompiled when we
monkeypatch, at which point this class becomes HTTPAdapter's base class.
In addition, we use an instantiation flag to avoid infinite recursion.
"""
_initialized = False

def __init__(self):
if not self._initialized:
self._initialized = True
super(AppEngineMROHack, self).__init__()


class AppEngineAdapter(AppEngineMROHack, adapters.HTTPAdapter):
"""The transport adapter for Requests to use urllib3's GAE support.
Implements Requests's HTTPAdapter API.
Expand Down

0 comments on commit 594b77a

Please sign in to comment.