8fwddlmZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z dZddlmZddlmZdd lmZmZdd lmZmZmZmZmZmZmZmZmZm Z dd l!m"Z"dd l#m$Z$m%Z%ej&e'Z(Gd de)Z*Gdde)Z+Gdde)Z,eGdde)Z-Gdde)Z.dZ/Gddej0Z1dS))absolute_importN)contextmanager)error)timeout)util)HTTPHeaderDict) BaseSSLError HTTPException) BodyNotHttplibCompatible DecodeError HTTPErrorIncompleteReadInvalidChunkLength InvalidHeader ProtocolErrorReadTimeoutErrorResponseNotChunkedSSLError)six) is_fp_closedis_response_to_headc eZdZdZdZdZdS)DeflateDecodercRd|_d|_tj|_dS)NT) _first_try_datazlib decompressobj_objselfs |/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/pip/_vendor/urllib3/response.py__init__zDeflateDecoder.__init__$s$ &(( rc,t|j|SNgetattrr!r#names r$ __getattr__zDeflateDecoder.__getattr__)ty$'''rc|s|S|js|j|S|xj|z c_ |j|}|rd|_d|_|S#tj$r\d|_t jtj |_ ||jd|_cYS#d|_wxYwwxYw)NF)rr! decompressrrrr MAX_WBITS)r#data decompresseds r$r/zDeflateDecoder.decompress,s K .9''-- - d  "9//55L ""'!  z " " "#DO*DN?;;DI "tz22! T !!!!  "s#+A##:CC7C C  CN__name__ __module__ __qualname__r%r,r/rr$rr#sA))) ((("""""rrceZdZdZdZdZdS)GzipDecoderStaterrN)r4r5r6 FIRST_MEMBER OTHER_MEMBERS SWALLOW_DATAr7rr$r9r9CsLMLLLrr9c eZdZdZdZdZdS) GzipDecodercttjdtjz|_tj|_dS)N)rr r0r!r9r;_stater"s r$r%zGzipDecoder.__init__Ks)&rDN':;; &3 rc,t|j|Sr'r(r*s r$r,zGzipDecoder.__getattr__Or-rct}|jtjks|st |S ||j|z }nM#tj$r;|j}tj|_|tj krt |cYSwxYw|jj }|st |Stj |_tj dtj z|_)NTrA) bytearrayrBr9r=bytesr!r/rrr< unused_datar r0)r#r1retprevious_states r$r/zGzipDecoder.decompressRskk ;*7 7 7t 7::  @ ty++D111:   !%.; !%5%CCC ::%%% 9(D "Szz!*8DK*2+>??DI @sAABBNr3r7rr$r?r?JsF444(((@@@@@rr?ceZdZdZdZdS) BrotliDecoderct|_t|jdr|jj|_dS|jj|_dS)Nr/)brotli Decompressorr!hasattrr/processr"s r$r%zBrotliDecoder.__init__nsI++--DIty,// 4"&)"6"&)"3rcbt|jdr|jSdS)Nflushr)rOr!rRr"s r$rRzBrotliDecoder.flushus-ty'** )y(((3rN)r4r5r6r%rRr7rr$rKrKjs2 4 4 4     rrKc$eZdZdZdZdZdZdS) 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. cNd|dD|_dS)NcPg|]#}t|$Sr7) _get_decoderstrip).0ms r$ z)MultiDecoder.__init__..s(LLLa,qwwyy11LLLr,)split _decoders)r#modess r$r%zMultiDecoder.__init__s'LL5;;s;K;KLLLrc@|jdSNr)r^rRr"s r$rRzMultiDecoder.flushs~a &&(((rc^t|jD]}||}|Sr')reversedr^r/)r#r1ds r$r/zMultiDecoder.decompresss3$.)) & &A<<%%DD rN)r4r5r6__doc__r%rRr/r7rr$rTrT{sNMMM)))rrTcd|vrt|S|dkrtSt|dkrtSt S)Nr\gzipbr)rTr?rMrKr)modes r$rWrWsP d{{D!!! v~~}} ddll   rceZdZdZddgZeedgz ZgdZ d,d Zd Zd Z dZ e dZ e dZ dZdZdZdZeejfZe eejfz ZdZdZedZdZd-dZd.dZedZdZd/dZ dZ!d Z"e d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d'Z)d(Z*d0d)Z+d*Z,d+Z-dS)1 HTTPResponsea HTTP Response container. Backwards-compatible with :class:`http.client.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 :class:`http.client.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 :class:`http.client.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. rgdeflateNrh)i-i.i/i3i4rTFc&t|tr||_nt||_||_||_||_||_||_| |_||_ ||_ d|_ d|_ d|_ | |_d|_| |_||_|r(t|t$jt(fr||_ | |_| |_t/|dr||_ d|_d|_|jdd}d|dD}d|vrd |_|||_|r$|j s|| |_ dSdSdS) NrreadFztransfer-encodingrmc3>K|]}|VdSr')rX)rYencs r$ z(HTTPResponse.__init__..s*>>SSYY[[>>>>>>rr\chunkedTdecode_content) isinstancer headersstatusversionreasonstrictruretriesenforce_content_length auto_close_decoder_body_fp_original_response_fp_bytes_readmsg _request_urlr string_typesrF_pool _connectionrOrs chunk_leftgetlowerr] _init_lengthlength_remainingro)r#bodyrwrxryrzr{preload_contentruoriginal_responsepool connectionrr|r}request_method request_urlr~tr_enc encodingss r$r%zHTTPResponse.__init__s* g~ . . 3"DLL)'22DL    , &<#$  "3'  Jtc&6%>?? DJ % 4  DH !!"5r::@@BB>>FLL,=,=>>>  ! !DL!% 1 1. A A  B4: B.AADJJJ B B B BrcV|j|jvr|jdSdS)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)rxREDIRECT_STATUSESrwrr"s r$get_redirect_locationz"HTTPResponse.get_redirect_locations/ ;$0 0 0<##J// /urcr|jr|jsdS|j|jd|_dSr')rr _put_connr"s r$ release_connzHTTPResponse.release_connsBz !1  F T-...rcx |dS#ttttf$rYdSwxYw)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)ror SocketErrorr r r"s r$ drain_connzHTTPResponse.drain_connsC   IIKKKKK; mD    DD s 99c\|jr|jS|jr|dSdS)NT) cache_content)rrror"s r$r1zHTTPResponse.data%s> : :  8 1994900 0 1 1rc|jSr')rr"s r$rzHTTPResponse.connection.s rc*t|jSr')rrr"s r$isclosedzHTTPResponse.isclosed2sDH%%%rc|jS)z Obtain the number of bytes pulled over the wire so far. May differ from the amount of content returned by :meth:``urllib3.response.HTTPResponse.read`` if bytes are encoded on the wire (e.g, compressed). )rr"s r$tellzHTTPResponse.tell5s ""rc |jd}||jrtddS t d|dD}t|dkrtd|z| }|dkrd}n#t$rd}YnwxYw t|j }n#t$rd}YnwxYw|d vsd |cxkrd ksn|d krd}|S) zM Set initial length value for Response content if available. zcontent-lengthNzReceived 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.c,g|]}t|Sr7)int)rYvals r$r[z-HTTPResponse._init_length..WsEEECs3xxEEErr\rz8Content-Length contained multiple unmatching values (%s)r)i0dHEAD) rwrrslogwarningsetr]lenrpop ValueErrorrrx)r#rlengthlengthsrxs r$rzHTTPResponse._init_length=sl!!"233  |  t " EE6<<3D3DEEEFFw<=B>C C&%C&cJjdd}ji|jvrt |_dSd|vrHfd|dD}t|rt |_dSdSdSdS)z= Set-up the _decoder attribute if necessary. content-encodingrmNr\cng|]1}|jv|2Sr7)rXCONTENT_DECODERS)rYer#s r$r[z.HTTPResponse._init_decoder..|sAwwyyD$999GGII999r)rwrrrrrWr]r)r#content_encodingrs` r$ _init_decoderzHTTPResponse._init_decoderqs  <++,>CCIIKK = 4#888 ,-= > > (((-33C88 y>>C$01A$B$BDMMM ! )( CCrc*|s|S |jr|j|}nR#|j$rE}|jdd}t d|z|d}~wwxYw|r||z }|S)zN Decode the data passed in and potentially flush the decoder. rrmzEReceived response with content-encoding: %s, but failed to decode it.N)rr/DECODER_ERROR_CLASSESrwrrr _flush_decoder)r#r1ru flush_decoderrrs r$_decodezHTTPResponse._decodes K } 6}//55)   #|//0BBGGMMOO ')9:    * D'')) )D s!( A7AA22A7c|jr6|jd}||jzSdS)zk Flushes the decoder. Should only be called if the decoder is actually being used. r)rr/rR)r#bufs r$rzHTTPResponse._flush_decodersA = /-**3//C,,... .src#*Kd} dVn#t$rt|jddt$r;}dt |vrt |t|jddd}~wt tf$r}td|z|d}~wwxYwd}|s@|j r|j |j r|j |j r/|j r| dSdSdS#|s@|j r|j |j r|j |j r.|j r| wwwxYw)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) SocketTimeoutrrr strrr rrrcloserrr)r# clean_exitrs r$_error_catcherzHTTPResponse._error_catchers + $ D  L L L'tz49JKKK L L L-SVV;;"1++%&tz49JKKK!;/ D D D#$;a$?CCC D J -*4+11333 #-$**,,,& $4+B+K+K+M+M $!!##### $ $ $ $ -*4+11333 #-$**,,,& $4+B+K+K+M+M $!!#### $ $s2 D)B6A++B?BBDA:Fc|jsJd}|r||ks|jr|j|krtjstjst jdkrtj}d}||dkrU|t||}||z}n|}|j |}|sn| |~|O|dkU| S||j |n|j S)a_ Read a response with the thought that reading the number of bytes larger than can fit in a 32-bit int at a time via SSL in some known cases leads to an overflow error that has to be prevented if `amt` or `self.length_remaining` indicate that a problem may happen. The known cases: * 3.8 <= CPython < 3.9.7 because of a bug https://github.com/urllib3/urllib3/issues/2513#issuecomment-1152559900. * urllib3 injected with pyOpenSSL-backed SSL-support. * CPython < 3.10 only when `amt` does not fit 32-bit int. i) iNr) rrrIS_SECURETRANSPORT IS_PYOPENSSLsys version_infoioBytesIOminrowritegetvalue)r#amt c_int_maxbuffer max_chunk_amt chunk_amtr1s r$_fp_readzHTTPResponse._fp_reads,xx  Ny)).2.Ci.O.O+/P"/P'*&6&@&@Z\\F$M+? #C 7 7I9$CC -Ix}}Y// T"""+??$$ $*-48==%%%dhmmoo Mrcz|||j}|jdSd}t|jdd}|5|s||nd}|d}nOd}|dkrG|sE|jd}|jr#|jdvrt|j |jdddn #1swxYwY|ra|xj t|z c_ |j|xjt|zc_| |||}|r||_ |S)aT Similar to :meth:`http.client.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.) NFclosedrTr)rN)rrurr)rrrr}rrrrrr)r#rrurr fp_closedr1s r$rozHTTPResponse.reads*   !!0N 8  F DHh66  " " Y Y-6?4==%%%CD{ $ % 1HHTHHNN$$$$(M2 Yt7LU88-T-@$BWXXX7 Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y:  "   3t99 ,  $0%%T2%%<<nmDDD "!  sA.C  CCc#K|jr4|r |||D]}|VdSt|js3|||}|r|Vt|j1dSdS)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. rt)rruN)rssupports_chunked_reads read_chunkedrrro)r#rruliner1s r$streamzHTTPResponse.streamYs < D7799 ))#n)MM     #48,, yySyHHJJJ #48,,     rc "|j}t|tsBtjrtj|}n!t|}t|dd}|d|||j|j |j ||d|}|S)a Given an :class:`http.client.HTTPResponse` instance ``r``, return a corresponding :class:`urllib3.response.HTTPResponse` object. Remaining parameters are passed to the HTTPResponse constructor, along with ``original_response=r``. r{r)rrwrxryrzr{rr7) rrvr rPY2 from_httplibitemsr)rxryrz) ResponseClsr response_kwrwr{resps r$rzHTTPResponse.from_httplibss%'>22 :w :(5g>>(99Ha(({  8I8       rcHtjdtd|jS)Nz|HTTPResponse.getheaders() is deprecated and will be removed in urllib3 v2.1.0. Instead access HTTPResponse.headers directly.r:category stacklevel)warningswarnDeprecationWarningrwr"s r$ getheaderszHTTPResponse.getheaderss1  O'     |rcptjdtd|j||S)NzHTTPResponse.getheader() is deprecated and will be removed in urllib3 v2.1.0. Instead use HTTPResponse.headers.get(name, default).r:r)rrrrwr)r#r+defaults r$ getheaderzHTTPResponse.getheadersA  V'     |g...rc|jSr')rwr"s r$infozHTTPResponse.infos |rc|js|j|jr|j|js!t j|dSdSr')rrrrr~rIOBaser"s r$rzHTTPResponse.closesl{  HNN      %   " " $ $ $ " IOOD ! ! ! ! ! " "rc |js$tjj|S|jdSt |jdr|jSt |jdr |jjSdS)NTrr)r~rrr__get__rrOrr"s r$rzHTTPResponse.closeds} 9#++D11 1 X 4 TXz * * 8$$&& & TXx ( ( 8? "4rc|jtdt|jdr|jStd)Nz-HTTPResponse has no file to get a fileno fromfilenozOThe file-like object this HTTPResponse is wrapped around has no file descriptor)rIOErrorrOrr"s r$rzHTTPResponse.filenosV 8 IJJ J TXx ( ( 8??$$ $0 rc|jDt|jdr1t|jdds|jSdSdSdS)NrRrF)rrOr)rRr"s r$rRzHTTPResponse.flushs\ H '** !DHh66 !8>>## # ! rcdS)NTr7r"s r$readablezHTTPResponse.readablestrc|t|}t|dkrdS||dt|<t|Sra)ror)r#btemps r$readintozHTTPResponse.readintosLyyQ   t99>>1!AkD kNt99 rc,t|jdS)a Checks if the underlying file-like object looks like a :class:`http.client.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)rOrr"s r$rz#HTTPResponse.supports_chunked_readsstx&&&rc|jdS|jj}|ddd} t |d|_dS#t $r%|t||wxYw)N;rrrA) rrr readliner]rrrr)r#rs r$_update_chunk_lengthz!HTTPResponse._update_chunk_lengths ? & Fx{##%%zz$""1% 1!$mmDOOO 1 1 1 JJLLL$T400 0 1s A/B cd}|C|j|j}|}|jdd|_n||jkr,|j|}|j|z |_|}n||jkr>|j|}|jdd|_|}n@|j|j}|jdd|_|S)Nr:)r _safe_readr)r#rreturned_chunkchunkvalues r$ _handle_chunkzHTTPResponse._handle_chunks ;H''88E"N H   " " ""DOO 4? " "H'',,E"o3DO"NN DO # #H'',,E H   " " ""DO"NN!X00AAN H   " " ""DOrc#,K||jstd|st d|5|jr;t|jr'|j ddddS|j j  ddddS | |j dkrn4| |}|||d}|r|VT|r|}|r|V |j j }|sn|dkrn)|jr|jddddS#1swxYwYdS) 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.zkBody should be http.client.HTTPResponse like. It should have have an fp attribute which returns raw chunks.NTrF)rurs )rrsrrr rrrrrr rrrrrr)r#rrurdecodedrs r$rzHTTPResponse.read_chunkedso | $B **,, *P   " ") 0) 0& +>t?V+W+W '--/// ) 0) 0) 0) 0) 0) 0) 0) 0x{") 0) 0) 0) 0) 0) 0) 0) 0 "))+++?a''**3//,,.'"!MMM " "--//"!MMM x{++--7??  & 0'--///S) 0) 0) 0) 0) 0) 0) 0) 0) 0) 0) 0) 0) 0) 0) 0) 0) 0) 0s$6F ' F B;F  F F c~|j0t|jjr|jjdjS|jS)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)r|rhistoryredirect_locationrr"s r$geturlzHTTPResponse.geturlUs: < #DL,@(A(A #<'+= =$ $rc#jKg}|dD]|}d|vra|d}d||dzdzV|ddD] }|dzV |dr |dg}dg}g||}|rd|VdSdS)NTrt rrrr)rr]joinappend)r#rrxs r$__iter__zHTTPResponse.__iter__`s[[[55 % %E~~ E**hhv&&q1E9999qt$$Ae)OOOO9 #Bi[FFFF e$$$$  #((6"" " " " " " # #r)rmNrrNrTTNNNNNFNNT)NNF)rNr')NN).r4r5r6rerrMrr%rrrpropertyr1rrrrrrrrrrrrrrror classmethodrrrrrrrrRrr rrrrrr"r7rr$rkrks@ * TF"111  $%ABABABABF         11X1  X &&&###222hCCC&%dj1 &,0,   5$5$^5$n.N.N.N`FFFFP4[@////"""  X    $$$''' 1 1 1,D0D0D0D0L % % %#####rrk)2 __future__rrloggingrrr contextlibrsocketrrrrrMrmr _collectionsr rr r exceptionsr r rrrrrrrrpackagesr util.responserr getLoggerr4robjectrr9r?rKrTrWrrkr7rr$r/s&&&&&&   %%%%%%''''''++++++ ((((((33333333                        <<<<<<<<g!!"""""V"""@v@@@@@&@@@< "6*   R #R #R #R #R #29R #R #R #R #R #r