zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
U
I=®d+ã@sdZddlmZddlZddlZddlZddlmZddlm    Z    m
Z
m Z m Z m Z mZddlmZddlmZdd    lmZdd
lmZd d lmZzdd lmZWnek
r¸dZYnXe e¡ZGdd„de
ƒZGdd„de    ƒZ Gdd„deƒZ!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 <https://cloud.google.com/appengine/docs/python/urlfetch>`_.
 
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 <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.
é)Úabsolute_importNé)Úurljoin)Ú    HTTPErrorÚ HTTPWarningÚ MaxRetryErrorÚ ProtocolErrorÚ TimeoutErrorÚSSLError)ÚRequestMethods)Ú HTTPResponse)ÚTimeout)ÚRetryé)Ú_appengine_environ)Úurlfetchc@s eZdZdS)ÚAppEnginePlatformWarningN©Ú__name__Ú
__module__Ú __qualname__©rrú\D:\z\workplace\VsCode\pyvenv\venv\Lib\site-packages\pip/_vendor/urllib3/contrib/appengine.pyrGsrc@s eZdZdS)ÚAppEnginePlatformErrorNrrrrrrKsrc@sXeZdZdZddd„Zdd„Zdd    „Zddddejfd
d „Z    d d „Z
dd„Z dd„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
    <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.
    NTcCs@ts tdƒ‚t dt¡t ||¡||_||_|p8t    j
|_ dS)Nz.URLFetch is not available in this environment.zÃ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.) rrÚwarningsÚwarnrr Ú__init__Úvalidate_certificateÚurlfetch_retriesrÚDEFAULTÚretries)ÚselfÚheadersr!rrrrrrcsÿü zAppEngineManager.__init__cCs|S)Nr)r"rrrÚ    __enter__|szAppEngineManager.__enter__cCsdS)NFr)r"Úexc_typeÚexc_valÚexc_tbrrrÚ__exit__szAppEngineManager.__exit__c
Ksâ| ||¡}zF|o |jdko |j}    tj||||p2id|jo<|    | |¡|jd}
WnBtjk
r‚} zt    || ƒ‚W5d} ~ XYntj
k
rÂ} z"dt | ƒkrªt d| ƒ‚t | ƒ‚W5d} ~ XYnÔtjk
r} z&dt | ƒkrðt||| d‚t | ƒ‚W5d} ~ XYnŽtjk
r6} zt d| ƒ‚W5d} ~ XYn`tjk
rb} z t| ƒ‚W5d} ~ XYn4tjk
r”} zt d    || ƒ‚W5d} ~ XYnX|j|
fd
|i|—Ž} |o¸|  ¡} | rv|jrÞ|jrÞt||d ƒ‚n˜| jd krîd }z|j||| |d}Wn.tk
r2|jr*t||d ƒ‚| YSX| | ¡t d|| ¡t|| ƒ}|j||||f|||dœ|—ŽSt|  d¡ƒ}|  || j|¡rÞ|j||| |d}t d|¡| !| ¡|j||f|||||dœ|—ŽS| S)NrF)ÚpayloadÚmethodr#Zallow_truncatedÚfollow_redirectsÚdeadlinerz    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!ÚredirectÚtimeoutz Retry-Afterz    Retry: %s)Úbodyr#r!r1r2)"Ú _get_retriesr1ÚtotalrÚfetchrÚ_get_absolute_timeoutrZDeadlineExceededErrorr    ZInvalidURLErrorÚstrrrZ DownloadErrorrZResponseTooLargeErrorZSSLCertificateErrorr
ZInvalidMethodErrorÚ#_urlfetch_response_to_http_responseÚget_redirect_locationÚraise_on_redirectÚstatusÚ    incrementÚsleep_for_retryÚlogÚdebugrÚurlopenÚboolÚ    getheaderÚis_retryÚsleep)r"r*Úurlr3r#r!r1r2Ú response_kwr+r/ÚeÚ http_responseÚredirect_locationZ redirect_urlÚhas_retry_afterrrrrAƒs¾ ø
 ý ýÿÿÿÿ ÿ
 
 
 
üùø  
þùø zAppEngineManager.urlopencKs¤tƒr"|j d¡}|dkr"|jd=|j d¡}|dkrZ| d¡}| d¡d |¡|jd<tft |j    ¡|j
|j|j dœ|—Ž}tft |j    ¡|j|j |dœ|—ŽS)Nzcontent-encodingÚdeflateztransfer-encodingÚchunkedú,)r3Úmsgr#r<)r3r#r<Úoriginal_response) Úis_prod_appenginer#ÚgetÚsplitÚremoveÚjoinr ÚioÚBytesIOÚcontentZ
header_msgÚ status_code)r"Z urlfetch_resprGÚcontent_encodingZtransfer_encodingÚ    encodingsrPrrrr9õs2  
 
 
úù
 
üûz4AppEngineManager._urlfetch_response_to_http_responsecCsB|tjkrdSt|tƒr>|jdk    s,|jdk    r8t dt¡|jS|S)NzdURLFetch does not support granular timeout settings, reverting to total or default URLFetch timeout.)    r ÚDEFAULT_TIMEOUTÚ
isinstanceÚ_readÚ_connectrrrr5)r"r2rrrr7s
 
ýz&AppEngineManager._get_absolute_timeoutcCs>t|tƒstj|||jd}|js.|js.|jr:t dt    ¡|S)N)r1ÚdefaultzhURLFetch only supports total retries and does not recognize connect, read, or redirect retry parameters.)
r]rÚfrom_intr!ÚconnectÚreadr1rrr)r"r!r1rrrr4&s
ýzAppEngineManager._get_retries)NNTT) rrrÚ__doc__rr$r(r r\rAr9r7r4rrrrrOs"û
ø
r$ r)'rdÚ
__future__rrVÚloggingrZpackages.six.moves.urllib.parserÚ
exceptionsrrrrr    r
Úrequestr r/r Z util.timeoutr Z
util.retryrÚrZgoogle.appengine.apirÚ ImportErrorÚ    getLoggerrr?rrrÚ is_appengineÚis_appengine_sandboxÚis_local_appenginerQÚis_prod_appengine_mvmsrrrrÚ<module>s2(            
 
h