zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
U
I=®d=nã@s`ddlmZddlmZddlZddlZddlZddlmZ    ddlm
Z z ddl Z Wne k
rldZ YnXddlmZddlmZmZmZmZmZmZmZmZdd    lmZmZdd
lmZdd l m!Z!m"Z"dd l#m$Z$m%Z%e &e'¡Z(Gd d„de)ƒZ*Gdd„de)ƒZ+Gdd„de)ƒZ,e dk    r2Gdd„de)ƒZ-Gdd„de)ƒZ.dd„Z/Gdd„dej0ƒZ1dS)é)Úabsolute_import)ÚcontextmanagerN)Útimeout)Úerroré)ÚHTTPHeaderDict)ÚBodyNotHttplibCompatibleÚ ProtocolErrorÚ DecodeErrorÚReadTimeoutErrorÚResponseNotChunkedÚIncompleteReadÚ InvalidHeaderÚ    HTTPError)Ú string_typesÚPY3)Ú http_client)Ú HTTPExceptionÚ BaseSSLError)Ú is_fp_closedÚis_response_to_headc@s$eZdZdd„Zdd„Zdd„ZdS)ÚDeflateDecodercCsd|_d|_t ¡|_dS)NTó)Ú
_first_tryÚ_dataÚzlibÚ decompressobjÚ_obj©Úself©r úSD:\z\workplace\VsCode\pyvenv\venv\Lib\site-packages\pip/_vendor/urllib3/response.pyÚ__init__"szDeflateDecoder.__init__cCs t|j|ƒS©N©Úgetattrr©rÚnamer r r!Ú __getattr__'szDeflateDecoder.__getattr__c Csš|s|S|js|j |¡S|j|7_z"|j |¡}|rFd|_d|_|WStjk
r”d|_t tj ¡|_z| |j¡W¢YSd|_XYnXdS)NF)rrÚ
decompressrrrrÚ    MAX_WBITS)rÚdataÚ decompressedr r r!r)*s"  zDeflateDecoder.decompressN©Ú__name__Ú
__module__Ú __qualname__r"r(r)r r r r!r!src@seZdZdZdZdZdS)ÚGzipDecoderStaterréN)r.r/r0Ú FIRST_MEMBERÚ OTHER_MEMBERSÚ SWALLOW_DATAr r r r!r1Asr1c@s$eZdZdd„Zdd„Zdd„ZdS)Ú GzipDecodercCst dtj¡|_tj|_dS©Né)rrr*rr1r3Ú_staterr r r!r"IszGzipDecoder.__init__cCs t|j|ƒSr#r$r&r r r!r(MszGzipDecoder.__getattr__cCs¤tƒ}|jtjks|st|ƒSz||j |¡7}Wn<tjk
rn|j}tj|_|tj    krht|ƒYS‚YnX|jj
}|s„t|ƒStj    |_t  dtj ¡|_qdSr7) Ú    bytearrayr9r1r5Úbytesrr)rrr4Ú unused_datarr*)rr+ÚretÚprevious_stater r r!r)Ps 
 zGzipDecoder.decompressNr-r r r r!r6Hsr6c@s$eZdZdd„Zdd„Zdd„ZdS)Ú BrotliDecodercCst ¡|_dSr#)ÚbrotliZ Decompressorrrr r r!r"lszBrotliDecoder.__init__cCs$t|jdƒr|j |¡S|j |¡S)Nr))Úhasattrrr)Úprocess)rr+r r r!r)os  zBrotliDecoder.decompresscCst|jdƒr|j ¡SdS)NÚflushr)rArrCrr r r!rCts 
zBrotliDecoder.flushN)r.r/r0r"r)rCr r r r!r?hsr?c@s(eZdZdZdd„Zdd„Zdd„ZdS)    Ú MultiDecodera
    From RFC7231:
        If one or more encodings have been applied to a representation, the
        sender that applied the encodings MUST generate a Content-Encoding
        header field that lists the content codings in the order in which
        they were applied.
    cCsdd„| d¡Dƒ|_dS)NcSsg|]}t| ¡ƒ‘qSr )Ú _get_decoderÚstrip)Ú.0Úmr r r!Ú
<listcomp>„sz)MultiDecoder.__init__.<locals>.<listcomp>ú,)ÚsplitÚ    _decoders)rÚmodesr r r!r"ƒszMultiDecoder.__init__cCs|jd ¡S©Nr)rLrCrr r r!rC†szMultiDecoder.flushcCst|jƒD]}| |¡}q
|Sr#)ÚreversedrLr))rr+Údr r r!r)‰s zMultiDecoder.decompressN)r.r/r0Ú__doc__r"rCr)r r r r!rDzsrDcCs:d|krt|ƒS|dkrtƒStdk    r4|dkr4tƒStƒS)NrJÚgzipÚbr)rDr6r@r?r)Úmoder r r!rEsrEc@sleZdZdZddgZedk    r&edg7Zdddd    d
gZdNdd„Zdd„Zdd„Z    dd„Z
e dd„ƒZ e dd„ƒZ dd„Zdd„Zdd „Zd!d"„ZeejfZedk    r¬eejf7Zd#d$„Zd%d&„Zed'd(„ƒZdOd)d*„ZdPd,d-„Zed.d/„ƒZd0d1„ZdQd2d3„Zd4d5„Z d6d7„Z!e d8d9„ƒZ"d:d;„Z#d<d=„Z$d>d?„Z%d@dA„Z&dBdC„Z'dDdE„Z(dFdG„Z)dRdHdI„Z*dJdK„Z+dLdM„Z,dS)SÚ HTTPResponseaº
    HTTP Response container.
 
    Backwards-compatible to httplib's HTTPResponse but the response ``body`` is
    loaded and decoded on-demand when the ``data`` property is accessed.  This
    class is also compatible with the Python standard library's :mod:`io`
    module, and can hence be treated as a readable object in the context of that
    framework.
 
    Extra parameters for behaviour not present in httplib.HTTPResponse:
 
    :param preload_content:
        If True, the response's body will be preloaded during construction.
 
    :param decode_content:
        If True, will attempt to decode the body based on the
        'content-encoding' header.
 
    :param original_response:
        When this HTTPResponse wrapper is generated from an httplib.HTTPResponse
        object, it's convenient to include the original for debug purposes. It's
        otherwise unused.
 
    :param retries:
        The retries contains the last :class:`~urllib3.util.retry.Retry` that
        was used during the request.
 
    :param enforce_content_length:
        Enforce content length checking. Body returned by server must match
        value of Content-Length header, if present. Otherwise, raise error.
    rRÚdeflateNrSi-i.i/i3i4ÚrTFcCst|tƒr||_n
t|ƒ|_||_||_||_||_||_| |_||_    ||_
d|_ d|_ d|_ |    |_d|_| |_||_|rŽt|ttfƒrŽ||_ |
|_| |_t|dƒrª||_ d|_d|_|j dd¡ ¡}dd„| d¡Dƒ}d    |krêd
|_| |¡|_|r|j s|j|d |_ dS) NrÚreadFztransfer-encodingrWcss|]}| ¡VqdSr#)rF)rGÚencr r r!Ú    <genexpr>úsz(HTTPResponse.__init__.<locals>.<genexpr>rJÚchunkedT©Údecode_content)Ú
isinstancerÚheadersÚstatusÚversionÚreasonÚstrictr]ÚretriesÚenforce_content_lengthÚ
auto_closeÚ_decoderÚ_bodyÚ_fpÚ_original_responseÚ_fp_bytes_readÚmsgÚ _request_urlÚ
basestringr;Ú_poolÚ _connectionrAr[Ú
chunk_leftÚgetÚlowerrKÚ _init_lengthÚlength_remainingrX)rÚbodyr_r`rarbrcÚpreload_contentr]Úoriginal_responseÚpoolÚ
connectionrlrdreÚrequest_methodÚ request_urlrfÚtr_encÚ    encodingsr r r!r"ÂsB
 
 
 zHTTPResponse.__init__cCs|j|jkr|j d¡SdS)a
        Should we redirect and where to?
 
        :returns: Truthy redirect location string if we got a redirect status
            code and valid location. ``None`` if redirect status and no
            location. ``False`` if not a redirect status code.
        ÚlocationF)r`ÚREDIRECT_STATUSESr_rrrr r r!Úget_redirect_locations  z"HTTPResponse.get_redirect_locationcCs(|jr |jsdS|j |j¡d|_dSr#)rorpÚ    _put_connrr r r!Ú release_conns zHTTPResponse.release_connc Cs.z | ¡Wnttttfk
r(YnXdS)zÏ
        Read and discard any remaining HTTP response data in the response connection.
 
        Unread data in the HTTPResponse connection blocks the connection from being released back to the pool.
        N)rXrÚ SocketErrorrrrr r r!Ú
drain_conns zHTTPResponse.drain_conncCs"|jr |jS|jr|jddSdS)NT)Ú cache_content)rhrirXrr r r!r+$szHTTPResponse.datacCs|jSr#)rprr r r!rz-szHTTPResponse.connectioncCs
t|jƒSr#)rrirr r r!Úisclosed1szHTTPResponse.isclosedcCs|jS)zÛ
        Obtain the number of bytes pulled over the wire so far. May differ from
        the amount of content returned by :meth:``HTTPResponse.read`` if bytes
        are encoded on the wire (e.g, compressed).
        )rkrr r r!Útell4szHTTPResponse.tellcCsà|j d¡}|dk    rŠ|jr(t d¡dSz<tdd„| d¡Dƒƒ}t|ƒdkrZtd|ƒ‚|     ¡}Wnt
k
r|d}YnX|d    krŠd}zt |j ƒ}Wnt
k
r°d    }YnX|d
ksØd |krÎd ksØn|d krÜd    }|S)zM
        Set initial length value for Response content if available.
        zcontent-lengthNzÒReceived response with both Content-Length and Transfer-Encoding set. This is expressly forbidden by RFC 7230 sec 3.3.2. Ignoring Content-Length and attempting to process response as Transfer-Encoding: chunked.cSsg|] }t|ƒ‘qSr )Úint)rGÚvalr r r!rIVsz-HTTPResponse._init_length.<locals>.<listcomp>rJrz8Content-Length contained multiple unmatching values (%s)r)éÌi0édéÈÚHEAD) r_rrr[ÚlogÚwarningÚsetrKÚlenrÚpopÚ
ValueErrorr‰r`)rr{ÚlengthÚlengthsr`r r r!rt<s6 ÿ ÿÿ 
 
&zHTTPResponse._init_lengthcshˆj dd¡ ¡}ˆjdkrd|ˆjkr2t|ƒˆ_n2d|krd‡fdd„| d¡Dƒ}t|ƒrdt|ƒˆ_dS)z=
        Set-up the _decoder attribute if necessary.
        úcontent-encodingrWNrJcs"g|]}| ¡ˆjkr| ¡‘qSr )rFÚCONTENT_DECODERS)rGÚerr r!rI{sþz.HTTPResponse._init_decoder.<locals>.<listcomp>)r_rrrsrgr˜rErKr’)rÚcontent_encodingr~r rr!Ú _init_decoderps
 
 
þzHTTPResponse._init_decoderc
Csx|s|Sz|jr|j |¡}WnD|jk
rb}z$|j dd¡ ¡}td||ƒ‚W5d}~XYnX|rt|| ¡7}|S)zN
        Decode the data passed in and potentially flush the decoder.
        r—rWzEReceived response with content-encoding: %s, but failed to decode it.N)rgr)ÚDECODER_ERROR_CLASSESr_rrrsr
Ú_flush_decoder)rr+r]Ú flush_decoderr™ršr r r!Ú_decode‡s ÿý zHTTPResponse._decodecCs$|jr |j d¡}||j ¡SdS)zk
        Flushes the decoder. Should only be called if the decoder is actually
        being used.
        r)rgr)rC)rÚbufr r r!rs zHTTPResponse._flush_decoderc
csìd}z¤z
dVWntk
r2t|jddƒ‚Ynptk
rn}z dt    |ƒkrP‚t|jddƒ‚W5d}~XYn4t
t fk
r }zt d||ƒ‚W5d}~XYnXd}W5|sÎ|jr¾|j ¡|jrÎ|j ¡|jræ|j ¡ræ| ¡XdS)zç
        Catch low-level python exceptions, instead re-raising urllib3
        variants, so that low-level exceptions are not leaked in the
        high-level api.
 
        On exit, release the connection back to the pool.
        FNzRead timed out.zread operation timed outzConnection broken: %rT) rjÚcloserpr‡rƒÚ SocketTimeoutr rorÚstrrr„r    )rÚ
clean_exitr™r r r!Ú_error_catcher¨s(    
  
 
zHTTPResponse._error_catcherc    Cs | ¡|dkr|j}|jdkr$dSd}t|jddƒ}| ¡v|dkr`|sV|j ¡nd}d}nPd}|st|j |¡nd}|dkr°|s°|j ¡d}|jr°|jdkr°t    |j
|jƒ‚W5QRX|r|j
t |ƒ7_
|jdk    rî|jt |ƒ8_|  |||¡}|r||_ |S)aP
        Similar to :meth:`httplib.HTTPResponse.read`, but with two additional
        parameters: ``decode_content`` and ``cache_content``.
 
        :param amt:
            How much of the content to read. If specified, caching is skipped
            because it doesn't make sense to cache partial content as the full
            response.
 
        :param decode_content:
            If True, will attempt to decode the body based on the
            'content-encoding' header.
 
        :param cache_content:
            If True, will save the returned data such that the same result is
            returned despite of the state of the underlying file object. This
            is useful if you want the ``.data`` property to continue working
            after having ``.read()`` the file object. (Overridden if ``amt`` is
            set.)
        NFÚclosedrTr)rN)r›r]rir%r¥rXr¡rerur rkr’rŸrh)rÚamtr]r†ržÚ    fp_closedr+r r r!rXás:
 
ÿÿ
 
    
zHTTPResponse.readéccsR|jr*| ¡r*|j||dD]
}|Vqn$t|jƒsN|j||d}|r*|Vq*dS)a_
        A generator wrapper for the read() method. A call will block until
        ``amt`` bytes have been read from the connection or until the
        connection is closed.
 
        :param amt:
            How much of the content to read. The generator will return up to
            much data per iteration, but may return less. This is particularly
            likely when using compressed data. However, the empty string will
            never be returned.
 
        :param decode_content:
            If True, will attempt to decode the body based on the
            'content-encoding' header.
        r\)r§r]N)r[Úsupports_chunked_readsÚ read_chunkedrrirX)rr§r]Úliner+r r r!Ústream+s
 
zHTTPResponse.streamc
Ks`|j}t|tƒs,tr"t| ¡ƒ}n
t |¡}t|ddƒ}|f|||j|j|j    ||dœ|—Ž}|S)a 
        Given an :class:`httplib.HTTPResponse` instance ``r``, return a
        corresponding :class:`urllib3.response.HTTPResponse` object.
 
        Remaining parameters are passed to the HTTPResponse constructor, along
        with ``original_response=r``.
        rcr)rvr_r`rarbrcrx)
rlr^rrÚitemsÚ from_httplibr%r`rarb)Ú ResponseClsÚrÚ response_kwr_rcÚrespr r r!r¯Es$    
 
 ùø
zHTTPResponse.from_httplibcCs|jSr#©r_rr r r!Ú
getheadersfszHTTPResponse.getheaderscCs|j ||¡Sr#)r_rr)rr'Údefaultr r r!Ú    getheaderiszHTTPResponse.getheadercCs|jSr#r´rr r r!ÚinfomszHTTPResponse.infocCs6|js|j ¡|jr |j ¡|js2tj |¡dSr#)r¦rir¡rprfÚioÚIOBaserr r r!r¡qs 
 
zHTTPResponse.closecCsT|jstjj |¡S|jdkr"dSt|jdƒr8|j ¡St|jdƒrL|jjSdSdS)NTr‡r¦)rfr¹rºr¦Ú__get__rirAr‡rr r r!r¦{s
 
 zHTTPResponse.closedcCs6|jdkrtdƒ‚nt|jdƒr*|j ¡Stdƒ‚dS)Nz-HTTPResponse has no file to get a fileno fromÚfilenozOThe file-like object this HTTPResponse is wrapped around has no file descriptor)riÚIOErrorrAr¼rr r r!r¼ˆs
 
 
ÿzHTTPResponse.filenocCs2|jdk    r.t|jdƒr.t|jddƒs.|j ¡SdS)NrCr¦F)rirAr%rCrr r r!rC“sÿ
þ ýzHTTPResponse.flushcCsdS)NTr rr r r!Úreadable›szHTTPResponse.readablecCs:| t|ƒ¡}t|ƒdkrdS||dt|ƒ…<t|ƒSdSrN)rXr’)rÚbÚtempr r r!ÚreadintoŸs
 zHTTPResponse.readintocCs t|jdƒS)zú
        Checks if the underlying file-like object looks like a
        httplib.HTTPResponse object. We do this by testing for the fp
        attribute. If it is present we assume it returns raw chunks as
        processed by read_chunked().
        Úfp)rArirr r r!rª¨sz#HTTPResponse.supports_chunked_readscCsf|jdk    rdS|jj ¡}| dd¡d}zt|dƒ|_Wn&tk
r`| ¡t     |¡‚YnXdS)Nó;rrr8)
rqrirÂÚreadlinerKr‰r”r¡Úhttplibr )rr¬r r r!Ú_update_chunk_length±s
 z!HTTPResponse._update_chunk_lengthcCs¬d}|dkr2|j |j¡}|}|j d¡d|_nv||jkrZ|j |¡}|j||_|}nN||jkrˆ|j |¡}|j d¡d|_|}n |j |j¡}|j d¡d|_|S)Nr2)riÚ
_safe_readrq)rr§Úreturned_chunkÚchunkÚvaluer r r!Ú _handle_chunk¿s& 
 
   zHTTPResponse._handle_chunkc    csþ| ¡|jstdƒ‚| ¡s&tdƒ‚| ¡Æ|jrXt|jƒrX|j ¡W5QR£dS|j    j
dkrrW5QR£dS|  ¡|j dkr†q¬|  |¡}|j||dd}|rr|Vqr|rÂ| ¡}|rÂ|V|j    j
 ¡}|sÔqà|dkrÂqàqÂ|jrð|j ¡W5QRXdS)aÆ
        Similar to :meth:`HTTPResponse.read`, but with an additional
        parameter: ``decode_content``.
 
        :param amt:
            How much of the content to read. If specified, caching is skipped
            because it doesn't make sense to cache partial content as the full
            response.
 
        :param decode_content:
            If True, will attempt to decode the body based on the
            'content-encoding' header.
        zHResponse is not chunked. Header 'transfer-encoding: chunked' is missing.zgBody should be httplib.HTTPResponse like. It should have have an fp attribute which returns raw chunks.NrF)r]ržs
)r›r[r rªrr¥rjrr¡rirÂrÆrqrËrŸrrÄ)rr§r]rÉÚdecodedr¬r r r!r«ÕsJÿÿ
 
 
 
ÿ zHTTPResponse.read_chunkedcCs.|jdk    r$t|jjƒr$|jjdjS|jSdS)zÄ
        Returns the URL that was the source of this response.
        If the request that generated this response redirected, this method
        will return the final redirect location.
        Néÿÿÿÿ)rdr’ÚhistoryÚredirect_locationrmrr r r!ÚgeturlszHTTPResponse.geturlccs”g}|jddD]n}d|krt| d¡}d |¡|ddV|dd…D]}|dVqJ|drn|dg}q~g}q| |¡q|rd |¡VdS)NTr\ó
rrrrÍ)r­rKÚjoinÚappend)rÚbufferrÉÚxr r r!Ú__iter__&s
   zHTTPResponse.__iter__)rWNrrNrTTNNNNNFNNT)NNF)r©N)N)NN)-r.r/r0rQr˜r@r€r"rrƒr…Úpropertyr+rzr‡rˆrtr›r½rrrœrŸrrr¥rXr­Ú classmethodr¯rµr·r¸r¡r¦r¼rCr¾rÁrªrÆrËr«rÐrÖr r r r!rUœsz 
î
C  
 
4
 
8
J
 
 
 
 
         
F rU)2Ú
__future__rÚ
contextlibrrr¹ÚloggingÚsocketrr¢rr„r@Ú ImportErrorÚ _collectionsrÚ
exceptionsrr    r
r r r rrZ packages.sixrrnrZpackages.six.movesrrÅrzrrZ util.responserrÚ    getLoggerr.rÚobjectrr1r6r?rDrErºrUr r r r!Ú<module>s2     
 (