-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
At the moment this will not work because the AppEngineManager does not have the same signature as urllib3's PoolManager. Related to: https://github.com/kennethreitz/requests/issues/1905#issuecomment-159380704
- Loading branch information
1 parent
14756e3
commit 1b6421c
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# -*- coding: utf-8 -*- | ||
"""The App Engine Transport Adapter for requests. | ||
This requires a version of requests >= 2.8.0. | ||
""" | ||
import requests | ||
from requests import adapters | ||
|
||
from .. import exceptions as exc | ||
from .._compat import gaecontrib | ||
|
||
|
||
class AppEngineAdapter(adapters.HTTPAdapter): | ||
"""A transport adapter for Requests to use urllib3's GAE support. | ||
When deploying to Google's App Engine service, some of Requests' | ||
functionality is broken. There is underlying support for GAE in urllib3. | ||
This functionality, however, is opt-in and needs to be enabled explicitly | ||
for Requests to be able to use it. | ||
Example usage: | ||
.. code-block:: python | ||
>>> import requests | ||
>>> import ssl | ||
>>> from requests_toolbelt.adapters import appengine | ||
>>> s = requests.Session() | ||
>>> if using_appengine(): | ||
... s.mount('https://', appengine.AppEngineAdapter()) | ||
... | ||
>>> | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
if gaecontrib is None: | ||
raise exc.VersionMismatchError( | ||
"The toolbelt requires at least Requests 2.8.0 to be " | ||
"installed. Version {0} was found instead.".format( | ||
requests.__version__ | ||
) | ||
) | ||
super(AppEngineAdapter, self).__init__(self, *args, **kwargs) | ||
|
||
def init_poolmanager(self, connections, maxsize, block=False): | ||
self.poolmanager = gaecontrib.AppEngineManager( | ||
num_pools=connections, | ||
maxsize=maxsize, | ||
block=block, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters