3 ”Re=nã @s`ddlmZddlmZddlZddlZddlZddlmZ ddlm Z y ddl Z Wne k rldZ YnXddlmZddlmZmZmZmZmZmZmZmZdd lmZmZdd lmZdd l m!Z!m"Z"dd l#m$Z$m%Z%ej&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|_tjƒ|_dS)NTó)Ú _first_tryÚ_dataÚzlibÚ decompressobjÚ_obj)Úself©rú‹/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/urllib3/response.pyÚ__init__"szDeflateDecoder.__init__cCs t|j|ƒS)N)Úgetattrr)rÚnamerrr Ú __getattr__'szDeflateDecoder.__getattr__cCs�|s|S|js|jj|ƒS|j|7_y |jj|ƒ}|rFd|_d|_|Stjk rŠd|_tjtj ƒ|_z |j|jƒSd|_XYnXdS)NF)rrÚ decompressrrrrÚ MAX_WBITS)rÚdataÚ decompressedrrr r%*s"   zDeflateDecoder.decompressN)Ú__name__Ú __module__Ú __qualname__r!r$r%rrrr r!src@seZdZdZdZdZdS)ÚGzipDecoderStaterréN)r)r*r+Ú FIRST_MEMBERÚ OTHER_MEMBERSÚ SWALLOW_DATArrrr r,Asr,c@s$eZdZdd„Zdd„Zdd„ZdS)Ú GzipDecodercCstjdtjƒ|_tj|_dS)Né)rrr&rr,r.Ú_state)rrrr r!IszGzipDecoder.__init__cCs t|j|ƒS)N)r"r)rr#rrr r$MszGzipDecoder.__getattr__c Cs¦tƒ}|jtjks| r t|ƒSx€y||jj|ƒ7}Wn8tjk rn|j}tj|_|tj krht|ƒS‚YnX|jj }|s„t|ƒStj |_tj dtj ƒ|_q"WdS)Nr2) Ú bytearrayr3r,r0Úbytesrr%rrr/Ú unused_datarr&)rr'ÚretÚprevious_staterrr r%Ps" zGzipDecoder.decompressN)r)r*r+r!r$r%rrrr r1Hsr1c@s$eZdZdd„Zdd„Zdd„ZdS)Ú BrotliDecodercCstjƒ|_dS)N)ÚbrotliZ Decompressorr)rrrr r!lszBrotliDecoder.__init__cCs$t|jdƒr|jj|ƒS|jj|ƒS)Nr%)Úhasattrrr%Úprocess)rr'rrr r%os  zBrotliDecoder.decompresscCst|jdƒr|jjƒSdS)NÚflushr)r;rr=)rrrr r=ts  zBrotliDecoder.flushN)r)r*r+r!r%r=rrrr r9hsr9c@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„|jdƒDƒ|_dS)NcSsg|]}t|jƒƒ‘qSr)Ú _get_decoderÚstrip)Ú.0Úmrrr ú „sz)MultiDecoder.__init__..ú,)ÚsplitÚ _decoders)rÚmodesrrr r!ƒszMultiDecoder.__init__cCs|jdjƒS)Nr)rFr=)rrrr r=†szMultiDecoder.flushcCs"xt|jƒD]}|j|ƒ}q W|S)N)ÚreversedrFr%)rr'Údrrr r%‰szMultiDecoder.decompressN)r)r*r+Ú__doc__r!r=r%rrrr r>zsr>cCs:d|krt|ƒS|dkrtƒStdk r4|dkr4tƒStƒS)NrDÚgzipÚbr)r>r1r:r9r)Úmoderrr r?�sr?c@sleZdZdZddgZedk r&edg7Zdddd d gZdOdd„Zdd„Zdd„Z dd„Z e dd„ƒZ e dd„ƒZ dd„Zdd„Zdd „Zd!d"„ZeejfZedk r¬eejf7Zd#d$„Zd%d&„Zed'd(„ƒZdPd)d*„ZdRd-d.„Zed/d0„ƒZd1d2„ZdSd3d4„Zd5d6„Z d7d8„Z!e d9d:„ƒZ"d;d<„Z#d=d>„Z$d?d@„Z%dAdB„Z&dCdD„Z'dEdF„Z(dGdH„Z)dTdIdJ„Z*dKdL„Z+dMdN„Z,dS)UÚ 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. rKÚdeflateNrLi-i.i/i3i4ÚrTFcCst|tƒr||_n t|ƒ|_||_||_||_||_||_| |_||_ ||_ d|_ d|_ d|_ | |_d|_| |_||_|rŽt|ttfƒrŽ||_ | |_| |_t|dƒrª||_ d|_d|_|jjddƒjƒ}dd„|jdƒDƒ}d |krêd |_|j|ƒ|_|�r|j �r|j|d �|_ dS) NrÚreadFztransfer-encodingrPcss|]}|jƒVqdS)N)r@)rAÚencrrr ú úsz(HTTPResponse.__init__..rDÚchunkedT)Údecode_content)Ú isinstancerÚheadersÚstatusÚversionÚreasonÚstrictrUÚretriesÚenforce_content_lengthÚ auto_closeÚ_decoderÚ_bodyÚ_fpÚ_original_responseÚ_fp_bytes_readÚmsgÚ _request_urlÚ basestringr5Ú_poolÚ _connectionr;rTÚ chunk_leftÚgetÚlowerrEÚ _init_lengthÚlength_remainingrQ)rÚbodyrWrXrYrZr[Úpreload_contentrUÚoriginal_responseÚpoolÚ connectionrdr\r]Úrequest_methodÚ request_urlr^Útr_encÚ encodingsrrr r!ÂsB    zHTTPResponse.__init__cCs|j|jkr|jjdƒ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)rXÚREDIRECT_STATUSESrWrj)rrrr Úget_redirect_locations  z"HTTPResponse.get_redirect_locationcCs,|j s|j rdS|jj|jƒd|_dS)N)rgrhÚ _put_conn)rrrr Ú release_connszHTTPResponse.release_conncCs.y |jƒ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)rQrÚ SocketErrorrr)rrrr Ú drain_conns zHTTPResponse.drain_conncCs"|jr |jS|jr|jdd�SdS)NT)Ú cache_content)r`rarQ)rrrr r'$szHTTPResponse.datacCs|jS)N)rh)rrrr rr-szHTTPResponse.connectioncCs t|jƒS)N)rra)rrrr Ú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). )rc)rrrr Útell4szHTTPResponse.tellcCsâ|jjdƒ}|dk rŠ|jr(tjdƒdSy.rDrz8Content-Length contained multiple unmatching values (%s)réÌé0édéÈÚHEAD)rƒr„) rWrjrTÚlogÚwarningÚsetrEÚlenrÚpopÚ ValueErrorr�rX)rrsÚlengthÚlengthsrXrrr rl<s0     (zHTTPResponse._init_lengthcshˆjjddƒjƒ}ˆjdkrd|ˆjkr2t|ƒˆ_n2d|krd‡fdd„|jdƒDƒ}t|ƒrdt|ƒˆ_dS)z= Set-up the _decoder attribute if necessary. zcontent-encodingrPNrDcs"g|]}|jƒˆjkr|jƒ‘qSr)r@ÚCONTENT_DECODERS)rAÚe)rrr rC|sz.HTTPResponse._init_decoder..)rWrjrkr_r�r?rEr‹)rÚcontent_encodingrvr)rr Ú _init_decoderps    zHTTPResponse._init_decodercCsx|s|Sy|jr|jj|ƒ}WnD|jk rb}z&|jjddƒjƒ}td||ƒ‚WYdd}~XnX|rt||jƒ7}|S)zN Decode the data passed in and potentially flush the decoder. zcontent-encodingrPzEReceived response with content-encoding: %s, but failed to decode it.N)r_r%ÚDECODER_ERROR_CLASSESrWrjrkr Ú_flush_decoder)rr'rUÚ flush_decoderr‘r’rrr Ú_decode‡s zHTTPResponse._decodecCs$|jr |jjdƒ}||jjƒSdS)zk Flushes the decoder. Should only be called if the decoder is actually being used. r)r_r%r=)rÚbufrrr r•�s zHTTPResponse._flush_decoderccsìd}z¤y dVWn�tk r2t|jddƒ‚Ynptk rn}z"dt|ƒkrP‚t|jddƒ‚WYdd}~Xn4ttfk r }ztd||ƒ‚WYdd}~XnXd}Wd|sÎ|jr¾|jj ƒ|j rÎ|j j ƒ|jræ|jj ƒræ|j ƒ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) Ú SocketTimeoutr rgrÚstrrr|r rbÚcloserhrr{)rÚ clean_exitr‘rrr Ú_error_catcher¨s(      zHTTPResponse._error_catcherc Cs|jƒ|dkr|j}|jdkr$dSd}t|jddƒ}|jƒ�x|dkr`|sV|jjƒnd}d}nRd}|st|jj|ƒnd}|dkr²| r²|jjƒd}|jr²|jdkr²t |j |jƒ‚WdQRX|�r |j t |ƒ7_ |jdk rð|jt |ƒ8_|j |||ƒ}|�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“rUrar"r�rQr›r]rmr rcr‹r—r`)rÚamtrUr~r–Ú fp_closedr'rrr rQás8     zHTTPResponse.readr-r2ccsZ|jr.|jƒr.xF|j||d�D] }|VqWn(x&t|jƒsT|j||d�}|r0|Vq0WdS)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. )rU)rŸrUN)rTÚsupports_chunked_readsÚ read_chunkedrrarQ)rrŸrUÚliner'rrr Ústream+s  zHTTPResponse.streamc Ks`|j}t|tƒs,tr"t|jƒƒ}n tj|ƒ}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``. r[r)rnrWrXrYrZr[rp) rdrVrrÚitemsÚ from_httplibr"rXrYrZ)Ú ResponseClsÚrÚ response_kwrWr[Úresprrr r¦Es    zHTTPResponse.from_httplibcCs|jS)N)rW)rrrr Ú getheadersfszHTTPResponse.getheaderscCs|jj||ƒS)N)rWrj)rr#Údefaultrrr Ú getheaderiszHTTPResponse.getheadercCs|jS)N)rW)rrrr ÚinfomszHTTPResponse.infocCs6|js|jjƒ|jr |jjƒ|js2tjj|ƒdS)N)ržrar›rhr^ÚioÚIOBase)rrrr r›qs   zHTTPResponse.closecCsT|jstjjj|ƒS|jdkr"dSt|jdƒr8|jjƒSt|jdƒrL|jjSdSdS)NTrrž)r^r¯r°ržÚ__get__rar;r)rrrr rž{s    zHTTPResponse.closedcCs6|jdkrtdƒ‚nt|jdƒr*|jjƒ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)raÚIOErrorr;r²)rrrr r²ˆs     zHTTPResponse.filenocCs4|jdk r0t|jdƒr0t|jddƒ r0|jjƒSdS)Nr=ržF)rar;r"r=)rrrr r=“s  zHTTPResponse.flushcCsdS)NTr)rrrr Úreadable›szHTTPResponse.readablecCs:|jt|ƒƒ}t|ƒdkrdS||dt|ƒ…<t|ƒSdS)Nr)rQr‹)rÚbÚtemprrr Ú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)r;ra)rrrr r¡¨sz#HTTPResponse.supports_chunked_readsc Csf|jdk rdS|jjjƒ}|jddƒd}yt|dƒ|_Wn&tk r`|jƒtj |ƒ‚YnXdS)Nó;rrr2) rirar¸ÚreadlinerEr�r�r›Úhttplibr )rr£rrr Ú_update_chunk_length±s  z!HTTPResponse._update_chunk_lengthcCs¬d}|dkr2|jj|jƒ}|}|jjdƒd|_nv||jkrZ|jj|ƒ}|j||_|}nN||jkrˆ|jj|ƒ}|jjdƒd|_|}n |jj|jƒ}|jjdƒd|_|S)Nr-)raÚ _safe_readri)rrŸÚreturned_chunkÚchunkÚvaluerrr Ú _handle_chunk¿s&        zHTTPResponse._handle_chunkc csò|jƒ|jstdƒ‚|jƒs&tdƒ‚|jƒ�º|jrNt|jƒrN|jjƒdS|j j dkr^dSx<|j ƒ|j dkrtP|j |ƒ}|j||dd�}|r`|Vq`W|r²|jƒ}|r²|Vx |j j jƒ}|sÆP|dkr´Pq´W|jrä|jjƒWdQRXdS)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)rUr–s )r“rTr r¡rr�rbrr›rar¸r¼rirÁr—r•rº)rrŸrUr¿Údecodedr£rrr r¢ÕsD        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. Nréÿÿÿÿ)r\r‹ÚhistoryÚredirect_locationre)rrrr ÚgeturlszHTTPResponse.geturlccsœg}x‚|jdd�D]r}d|krz|jdƒ}dj|ƒ|ddVx|dd…D]}|dVqNW|drt|d g}q„g}q|j|ƒqW|r˜dj|ƒVdS) NT)rUó rrrrÃrÃrÃ)r¤rEÚjoinÚappend)rÚbufferr¿Úxrrr Ú__iter__&s  zHTTPResponse.__iter__)rPNrrNrTTNNNNNFNNT)NNFé)rÍN)N)NN)-r)r*r+rJr�r:rxr!ryr{r}Úpropertyr'rrrr€rlr“r³rrr”r—r•rr�rQr¤Ú classmethodr¦r«r­r®r›ržr²r=r´r·r¡r¼rÁr¢rÆrÌrrrr rNœsn  1  4   9 J  !      F rN)2Ú __future__rÚ contextlibrrr¯ÚloggingÚsocketrr™rr|r:Ú ImportErrorÚ _collectionsrÚ exceptionsrr r r r r rrZ packages.sixrrfrZpackages.six.movesrr»rrrrZ util.responserrÚ getLoggerr)rˆÚobjectrr,r1r9r>r?r°rNrrrr Ús2       (