a *Nat@sdZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z Gd d d ej Z Gd d d e ej Z Gd dde ZGdddeZGdddeZdddZddZdS)aThe 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)timeoutcs$eZdZdZdZfddZZS)AppEngineMROHackaResolves 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. Fcs&|js"d|_tt|j|i|dS)NT) _initializedsuperr__init__selfargskwargs __class__/private/var/folders/js/6pj4vh5d4zd0k6bxv74qrbhr0000gr/T/pip-target-22xwyzbs/lib/python/requests_toolbelt/adapters/appengine.pyr 9szAppEngineMROHack.__init__)__name__ __module__ __qualname____doc__r r __classcell__rrrrr.srcs:eZdZdZejjdgZd fdd Zd ddZZ S) AppEngineAdapterayThe 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_certificateTcs&t||_tt|j|i|dSN)_check_versionrr rr )r validate_certificaterrrrrr LszAppEngineAdapter.__init__FcCst|j|_dSr)_AppEnginePoolManagerr poolmanager)r connectionsmaxsizeblockrrrinit_poolmanagerQsz!AppEngineAdapter.init_poolmanager)T)F) rrrrr HTTPAdapter __attrs__r r#rrrrrr?s rcs eZdZdZfddZZS)InsecureAppEngineAdapteraAn 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. cs8|ddrtdtjtt|j|ddi|dS)NrFzCertificate 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 rrrr ds  z!InsecureAppEngineAdapter.__init__)rrrrr rrrrrr&Usr&c@s*eZdZdZd ddZddZddZd S) raKImplements 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. TcCstj|d|_dS)N)r)rZAppEngineManagerappengine_manager)r rrrrr xsz_AppEnginePoolManager.__init__cCs t|j|Sr)_AppEngineConnectionr+)r urlrrrconnection_from_url|sz)_AppEnginePoolManager.connection_from_urlcCsdSrr)r rrrclearsz_AppEnginePoolManager.clearN)T)rrrrr r.r/rrrrros rc@s6eZdZdZddZdddddejjddfddZdS)r,aImplements urllib3's HTTPConnectionPool API's urlopen(). This Connection's urlopen() is called with a host-relative path, so in order to properly support opening the URL, we need to store the full URL when this Connection is constructed from the PoolManager. This code wraps AppEngineManager.urlopen(), which exposes a different API than in the original urllib3 urlopen(), and thus needs this adapter. cCs||_||_dSr)r+r-)r r+r-rrrr sz_AppEngineConnection.__init__NTc Ks8|js|jp|j|_|jj||jf|||||d| S)N)bodyheadersretriesredirectr)total_read_connectr+urlopenr-) r methodr-r0r1r2r3assert_same_hostr pool_timeout release_conn response_kwrrrr7sz_AppEngineConnection.urlopen) rrrrr rTimeoutDEFAULT_TIMEOUTr7rrrrr,s r,TcCs"tt}|st}|t_|t_dS)aSets up all Sessions to use AppEngineAdapter by default. If you don't want to deal with configuring your own Sessions, or if you use libraries that use requests directly (ie requests.post), then you may prefer to monkeypatch and auto-configure all Sessions. .. warning: : If ``validate_certificate`` is ``False``, certification validation will effectively be disabled for all requests. N)rrr&rr$r)radapterrrr monkeypatchs r@cCstdurtdtjdS)Nz^The toolbelt requires at least Requests 2.10.0 to be installed. Version {0} was found instead.)rr*ZVersionMismatchErrorformatrequests __version__rrrrrs r)T)rrBr(rrrr*_compatrrr$rrr&objectrr,r@rrrrrs"     ,