Re+zdZddlmZddlZddlZddlZddlmZmZm Z m Z m Z m Z ddl mZddlmZddlmZdd lmZdd lmZd d lmZ dd lmZn #e$rdZYnwxYwejeZGddeZGddeZ GddeZ!ej"Z"ej#Z#ej$Z$ej%Z%ej&Z&dS)a[ This module provides a pool manager that uses Google App Engine's `URLFetch Service `_. Example usage:: from pip._vendor.urllib3 import PoolManager from pip._vendor.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 `_ 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 `_ 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 `_, you can use the standard :class:`PoolManager` without any configuration or special environment variables. )absolute_importN) HTTPError HTTPWarning MaxRetryError ProtocolErrorSSLError TimeoutError)urljoin)RequestMethods) HTTPResponse)Retry)Timeout)_appengine_environ)urlfetchceZdZdS)AppEnginePlatformWarningN__name__ __module__ __qualname__/builddir/build/BUILDROOT/alt-python311-pip-21.3.1-3.el8.x86_64/opt/alt/python311/lib/python3.11/site-packages/pip/_vendor/urllib3/contrib/appengine.pyrrGDrrceZdZdS)AppEnginePlatformErrorNrrrrrrKrrrc\eZdZdZ d dZdZdZddddejfdZ dZ d Z d Z dS) AppEngineManagera  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 `_. 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 megabytes. * If you use an unsupported request method such as OPTIONS. Beyond those cases, it will raise normal urllib3 errors. NTctstdtjdtt j||||_||_|p tj |_ dS)Nz.URLFetch is not available in this environment.zurllib3 is using URLFetch on Google App Engine sandbox instead of sockets. To use sockets directly instead of URLFetch see https://urllib3.readthedocs.io/en/1.26.x/reference/urllib3.contrib.html.) rrwarningswarnrr __init__validate_certificateurlfetch_retriesrDEFAULTretries)selfheadersr(r%r&s rr$zAppEngineManager.__init__csy (@    W %     g...$8! 0/%- rc|S)Nr)r)s r __enter__zAppEngineManager.__enter__|s rcdS)NFr)r)exc_typeexc_valexc_tbs r__exit__zAppEngineManager.__exit__surc |||} |o|jdko|j} tj||||pid|jo| |||j} n#tj$r} t|| d} ~ wtj $r5} dt| vrtd| t| d} ~ wtj$r7} dt| vrt||| t| d} ~ wtj$r} td| d} ~ wtj$r} t%| d} ~ wtj$r} td |z| d} ~ wwxYw|j| fd |i|} |o| } | r|jr|jrt||d | jd krd } |||| |}n*#t$r|jrt||d | cYSwxYw|| t4d|| t9|| }|j||||f|||d|St=| d}| || j|r^|||| |}t4d||!| |j||f|||||d|S| S)NrF)payloadmethodr*allow_truncatedfollow_redirectsdeadliner%z too largezOURLFetch request too large, URLFetch only supports requests up to 10mb in size.zToo many redirects)reasonzPURLFetch response too large, URLFetch only supportsresponses up to 32mb in size.z$URLFetch does not support method: %sr(ztoo many redirectsi/GET)response_poolzRedirecting %s -> %s)r(redirecttimeoutz Retry-Afterz Retry: %s)bodyr*r(r<r=)" _get_retriesr<totalrfetchr&_get_absolute_timeoutr%DeadlineExceededErrorr InvalidURLErrorstrrr DownloadErrorrResponseTooLargeErrorSSLCertificateErrorr InvalidMethodError#_urlfetch_response_to_http_responseget_redirect_locationraise_on_redirectstatus incrementsleep_for_retrylogdebugr urlopenbool getheaderis_retrysleep)r)r4urlr>r*r(r<r= response_kwr6r:e http_responseredirect_location redirect_urlhas_retry_afters rrRzAppEngineManager.urlopens,##GX66* 'SG,<,ASgm ~ 2 %!%!6!K;K33G<<%)%>   HH- ( ( (tQ'' '' # # #c!ff$$,<  "" "% # # ##s1vv--#D#a8888"" "-   (0  +   1++ *   (6?   A@   % )4  %N)L)L)N)N  $ )B #D#/CDDD '3.."F)%//m40GG%)))0M+D#7KLLL(((() '' 666 0#7HIII&s,=>> #t|   $%#  "   }66}EEFF   FM$8/ J J ''mSW'XXG IIk3 ' ' ' MM- ( ( (4< !     sfAA++E=:B  E=0C  E=2DE="D22E=EE=%E88E=G//$HHc tr(|jd}|dkr|jd=|jd}|dkrG|d}|dd||jd<t dtj|j |j |j|j d|}t dtj|j |j|j |d|S) Nzcontent-encodingdeflateztransfer-encodingchunked,)r>msgr*rM)r>r*rMoriginal_responser) is_prod_appenginer*getsplitremovejoinr ioBytesIOcontent header_msg status_code)r) urlfetch_resprXcontent_encodingtransfer_encoding encodingsrcs rrJz4AppEngineManager._urlfetch_response_to_http_responses6    > -4889KLL 9,,!)*<=)1556IJJ  ) ))//44I   Y ' ' '9<)9L9LM !"5 6( M122(!) ,      M122!) ,/       rc|tjurdSt|tr/|j|jt jdt|jS|S)NzdURLFetch does not support granular timeout settings, reverting to total or default URLFetch timeout.) rDEFAULT_TIMEOUT isinstance_read_connectr"r#rr@)r)r=s rrBz&AppEngineManager._get_absolute_timeoutsc g- - -4 gw ' ' !}(G,<,H F, = rct|tstj|||j}|js|js|jrtjdt|S)N)r<defaultzhURLFetch only supports total retries and does not recognize connect, read, or redirect retry parameters.) rtrfrom_intr(connectreadr<r"r#r)r)r(r<s rr?zAppEngineManager._get_retries&sn'5)) WnWxVVVG ? gl g.>  MI(    r)NNTT) rrr__doc__r$r,r1rrsrRrJrBr?rrrr r Os*! 00002'ppppd" " " H        rr )'r| __future__rriloggingr" exceptionsrrrrr r packages.six.moves.urllib.parser requestr r:r util.retryr util.timeoutrrgoogle.appengine.apir ImportError getLoggerrrPrrr is_appengineis_appengine_sandboxis_local_appenginerdis_prod_appengine_mvmsrrrrs &&P'&&&&& 655555$$$$$$######"""""" -------HHHg!!     {        Y   bbbbb~bbbN". )>':&8+Bs AAA