3
P\t @ s d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlm Z ddlm
Z
G d d
d
ejZG dd deejZ
G d
d de
ZG dd deZG dd deZdddZdd ZdS )a The App Engine Transport Adapter for requests.
.. versionadded:: 0.6.0
This requires a version of requests >= 2.10.0 and Python 2.
There are two ways to use this library:
#. If you're using requests directly, you can use code like:
.. code-block:: python
>>> import requests
>>> import ssl
>>> import requests.packages.urllib3.contrib.appengine as ul_appengine
>>> from requests_toolbelt.adapters import appengine
>>> s = requests.Session()
>>> if ul_appengine.is_appengine_sandbox():
... s.mount('http://', appengine.AppEngineAdapter())
... s.mount('https://', appengine.AppEngineAdapter())
#. If you depend on external libraries which use requests, you can use code
like:
.. code-block:: python
>>> from requests_toolbelt.adapters import appengine
>>> appengine.monkeypatch()
which will ensure all requests.Session objects use AppEngineAdapter properly.
You are also able to :ref:`disable certificate validation `
when monkey-patching.
N)adapters)sessions )
exceptions)
gaecontrib)timeoutc s$ e Zd ZdZdZ fddZ ZS )AppEngineMROHacka 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.
Fc s" | j sd| _ tt| j|| d S )NT)_initializedsuperr __init__)selfargskwargs) __class__ /usr/lib/python3.6/appengine.pyr 9 s zAppEngineMROHack.__init__)__name__
__module____qualname____doc__r r
__classcell__r r )r r r . s r c s: e Zd ZdZejjdg Zd fdd Zd
ddZ Z S )AppEngineAdapteray The transport adapter for Requests to use urllib3's GAE support.
Implements Requests's HTTPAdapter API.
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.
_validate_certificateTc s" t || _tt| j|| d S )N)_check_versionr r
r r )r validate_certificater
r )r r r r L s zAppEngineAdapter.__init__Fc C s t | j| _d S )N)_AppEnginePoolManagerr Zpoolmanager)r Zconnectionsmaxsizeblockr r r init_poolmanagerQ s z!AppEngineAdapter.init_poolmanager)T)F)
r r r r r HTTPAdapterZ __attrs__r r r r r )r r r ? s r c s e Zd ZdZ fddZ ZS )InsecureAppEngineAdaptera An always-insecure GAE adapter for Requests.
This is a variant of the the transport adapter for Requests to use
urllib3's GAE support that does not validate certificates. Use with
caution!
.. note::
The ``validate_certificate`` keyword argument will not be honored here
and is not part of the signature because we always force it to
``False``.
See :class:`AppEngineAdapter` for further details.
c s8 |j ddrtjdtj tt| j|ddi| d S )Nr FzCertificate validation cannot be specified on the InsecureAppEngineAdapter, but was present. This will be ignored and certificate validation will remain off.)popwarningswarnexcZ IgnoringGAECertificateValidationr
r r )r r
r )r r r r d s
z!InsecureAppEngineAdapter.__init__)r r r r r r r r )r r r U s
r c @ s* e Zd ZdZd
ddZdd Zdd Zd S )r aK Implements urllib3's PoolManager API expected by requests.
While a real PoolManager map hostnames to reusable Connections,
AppEngine has no concept of a reusable connection to a host.
So instead, this class constructs a small Connection per request,
that is returned to the Adapter and used to access the URL.
Tc C s t j|d| _d S )N)r )r ZAppEngineManagerappengine_manager)r r r r r r x s z_AppEnginePoolManager.__init__c C s t | j|S )N)_AppEngineConnectionr% )r urlr r r connection_from_url| s z)_AppEnginePoolManager.connection_from_urlc C s d S )Nr )r r r r clear s z_AppEnginePoolManager.clearN)T)r r r r r r( r) r r r r r o s
r c @ s6 e Zd ZdZdd ZdddddejjddfddZdS )r&