ok

Mini Shell

Direktori : /proc/thread-self/root/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/
Upload File :
Current File : //proc/thread-self/root/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyc

�
��abc@@sxdZddlmZddlZddlZddlZddlmZddlm	Z	m
Z
mZmZm
Z
mZddlmZddlmZdd	lmZdd
lmZddlmZyddlmZWnek
r�dZnXeje�Zd
e
fd��YZ de	fd��YZ!defd��YZ"d�Z#d�Z$d�Z%d�Z&d�Z'dS(sC
This module provides a pool manager that uses Google App Engine's
`URLFetch Service <https://cloud.google.com/appengine/docs/python/urlfetch>`_.

Example usage::

    from urllib3 import PoolManager
    from urllib3.contrib.appengine import AppEngineManager, is_appengine_sandbox

    if is_appengine_sandbox():
        # AppEngineManager uses AppEngine's URLFetch API behind the scenes
        http = AppEngineManager()
    else:
        # PoolManager uses a socket-level API behind the scenes
        http = PoolManager()

    r = http.request('GET', 'https://google.com/')

There are `limitations <https://cloud.google.com/appengine/docs/python/urlfetch/#Python_Quotas_and_limits>`_ to the URLFetch service and it may not be
the best choice for your application. There are three options for using
urllib3 on Google App Engine:

1. You can use :class:`AppEngineManager` with URLFetch. URLFetch is
   cost-effective in many circumstances as long as your usage is within the
   limitations.
2. You can use a normal :class:`~urllib3.PoolManager` by enabling sockets.
   Sockets also have `limitations and restrictions
   <https://cloud.google.com/appengine/docs/python/sockets/   #limitations-and-restrictions>`_ and have a lower free quota than URLFetch.
   To use sockets, be sure to specify the following in your ``app.yaml``::

        env_variables:
            GAE_USE_SOCKETS_HTTPLIB : 'true'

3. If you are using `App Engine Flexible
<https://cloud.google.com/appengine/docs/flexible/>`_, you can use the standard
:class:`PoolManager` without any configuration or special environment variables.
i(tabsolute_importNi(turljoin(t	HTTPErrortHTTPWarningt
MaxRetryErrort
ProtocolErrortTimeoutErrortSSLError(tBytesIO(tRequestMethods(tHTTPResponse(tTimeout(tRetry(turlfetchtAppEnginePlatformWarningcB@seZRS((t__name__t
__module__(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyRGstAppEnginePlatformErrorcB@seZRS((RR(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyRKstAppEngineManagercB@skeZdZddeed�Zd�Zd�Zdddeej	d�Z
d�Zd�Zd�Z
RS(	s
    Connection manager for Google App Engine sandbox applications.

    This manager uses the URLFetch service directly instead of using the
    emulated httplib, and is subject to URLFetch limitations as described in
    the App Engine documentation `here
    <https://cloud.google.com/appengine/docs/python/urlfetch>`_.

    Notably it will raise an :class:`AppEnginePlatformError` if:
        * URLFetch is not available.
        * If you attempt to use this on App Engine Flexible, as full socket
          support is available.
        * If a request size is more than 10 megabytes.
        * If a response size is more than 32 megabtyes.
        * If you use an unsupported request method such as OPTIONS.

    Beyond those cases, it will raise normal urllib3 errors.
    cC@sutstd��nt�r-td��ntjdt�tj||�||_||_	|pkt
j|_dS(Ns.URLFetch is not available in this environment.s�Use normal urllib3.PoolManager instead of AppEngineManageron Managed VMs, as using URLFetch is not necessary in this environment.s�urllib3 is using URLFetch on Google App Engine sandbox instead of sockets. To use sockets directly instead of URLFetch see https://urllib3.readthedocs.io/en/latest/reference/urllib3.contrib.html.(
R
Rtis_prod_appengine_mvmstwarningstwarnRR	t__init__tvalidate_certificateturlfetch_retriesRtDEFAULTtretries(tselftheadersRRR((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyRcs			cC@s|S(N((R((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyt	__enter__{scC@stS(N(tFalse(Rtexc_typetexc_valtexc_tb((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyt__exit__~scK@sk|j||�}yv|o0|jdko0|j}	tj|d|d|d|pTidtd|joi|	d|j|�d|j�}
Wn"tj	k
r�}t
||��n�tjk
r�}d	t|�kr�t
d
|��nt|��n�tjk
r?}dt|�kr0t||d|��nt|��nntjk
rc}t
d
|��nJtjk
r�}t|��n)tjk
r�}t
d||��nX|j|
d||�}|o�|j�}
|
r�|jr|jrt||d��q�|jdkrd}ny"|j||d|d|�}Wn0tk
rp|jrlt||d��n|SX|j|�tjd||
�t||
�}|j||||d|d|d||�Snt|j d��}|j!||j|�rg|j||d|d|�}tjd|�|j"|�|j||d|d|d|d|d||�S|S(NitpayloadtmethodRtallow_truncatedtfollow_redirectstdeadlineRs	too largesOURLFetch request too large, URLFetch only supports requests up to 10mb in size.sToo many redirectstreasonsPURLFetch response too large, URLFetch only supportsresponses up to 32mb in size.s$URLFetch does not support method: %sRstoo many redirectsi/tGETtresponset_poolsRedirecting %s -> %stredirectttimeoutsRetry-Afters	Retry: %stbody(#t_get_retriesR,ttotalR
tfetchRRt_get_absolute_timeoutRtDeadlineExceededErrorRtInvalidURLErrortstrRRt
DownloadErrorRtResponseTooLargeErrortSSLCertificateErrorRtInvalidMethodErrort#_urlfetch_response_to_http_responsetget_redirect_locationtraise_on_redirecttstatust	incrementtsleep_for_retrytlogtdebugRturlopentboolt	getheadertis_retrytsleep(RR$turlR.RRR,R-tresponse_kwR&R*tet
http_responsetredirect_locationtredirect_urlthas_retry_after((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyRB�s�		"
	


	
cK@s�t�r7|jjd�}|dkr7|jd=q7n|jjd�}|dkr�|jd�}|jd�dj|�|jd<ntdt|j�d|jd|j	|�S(	Nscontent-encodingtdeflatestransfer-encodingtchunkedt,R.RR=(
tis_prod_appengineRtgettsplittremovetjoinR
Rtcontenttstatus_code(Rt
urlfetch_respRHtcontent_encodingttransfer_encodingt	encodings((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyR:�s	
	cC@s^|tjkrdSt|t�rZ|jdk	s@|jdk	rStjdt�n|j	S|S(NsdURLFetch does not support granular timeout settings, reverting to total or default URLFetch timeout.(
RtDEFAULT_TIMEOUTtNonet
isinstancet_readt_connectRRRR0(RR-((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyR2�s
cC@sbt|t�s0tj|d|d|j�}n|jsK|jsK|jr^tjdt	�n|S(NR,tdefaultshURLFetch only supports total retries and does not recognize connect, read, or redirect retry parameters.(
R^Rtfrom_intRtconnecttreadR,RRR(RRR,((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyR/s
N(RRt__doc__R]tTrueRRR"RR\RBR:R2R/(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyROs			Z		cC@st�pt�pt�S(N(tis_local_appengineRQR(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pytis_appengines		cC@st�ot�S(N(RhR(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pytis_appengine_sandboxscC@s dtjkodtjdkS(NtAPPENGINE_RUNTIMEsDevelopment/tSERVER_SOFTWARE(tostenviron(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyRgscC@s*dtjko)dtjdko)t�S(NRjsGoogle App Engine/Rk(RlRmR(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyRQ!scC@stjjdt�dkS(NtGAE_VMttrue(RlRmRRR(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyR's((Ret
__future__RtloggingRlRtpackages.six.moves.urllib.parseRt
exceptionsRRRRRRtpackages.sixRtrequestR	R*R
tutil.timeoutRt
util.retryRtgoogle.appengine.apiR
tImportErrorR]t	getLoggerRR@RRRRhRiRgRQR(((sI/usr/lib/python2.7/site-packages/pip/_vendor/urllib3/contrib/appengine.pyt<module>'s0.	

�				

Zerion Mini Shell 1.0