a †oe)xã@s’ddlmZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z z,z ddlZWney€ddlZYn0WneyšdZYn0ddlmZddlmZdd lmZmZdd lmZmZmZmZmZmZmZm Z m!Z!m"Z"dd l#m$Z$dd l%m&Z&m'Z'e (e)¡Z*Gd d„de+ƒZ,Gdd„de+ƒZ-Gdd„de+ƒZ.edu�rdGdd„de+ƒZ/Gdd„de+ƒZ0dd„Z1Gdd„dej2ƒZ3dS)é)Úabsolute_importN)Úcontextmanager)Úerror)Útimeouté)Úutil)ÚHTTPHeaderDict)Ú BaseSSLErrorÚ HTTPException) ÚBodyNotHttplibCompatibleÚ DecodeErrorÚ HTTPErrorÚIncompleteReadÚInvalidChunkLengthÚ InvalidHeaderÚ ProtocolErrorÚReadTimeoutErrorÚResponseNotChunkedÚSSLError)Úsix)Ú 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!ú1C:\Program Files\Certbot\pkgs\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|_|WStjy–d|_t tj ¡|_z| |j¡Wd|_YSd|_0Yn0dS)NF)rrÚ decompressrrrrÚ MAX_WBITS)r ÚdataZ decompressedr!r!r"r*2s&   þ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"r1Isr1c@s$eZdZdd„Zdd„Zdd„ZdS)Ú GzipDecodercCst dtj¡|_tj|_dS©Né)rrr+rr1r3Ú_staterr!r!r"r#QszGzipDecoder.__init__cCs t|j|ƒSr$r%r'r!r!r"r)UszGzipDecoder.__getattr__cCs¢tƒ}|jtjks|st|ƒSz||j |¡7}Wn:tjyl|j}tj|_|tj krft|ƒYS‚Yn0|jj }|s‚t|ƒStj |_t  dtj ¡|_qdSr7) Ú bytearrayr9r1r5Úbytesrr*rrr4Ú unused_datarr+)r r,ÚretZprevious_stater!r!r"r*Xs   zGzipDecoder.decompressNr-r!r!r!r"r6Psr6c@seZdZdd„Zdd„ZdS)Ú BrotliDecodercCs0t ¡|_t|jdƒr"|jj|_n |jj|_dS)Nr*)ÚbrotliZ DecompressorrÚhasattrr*Zprocessrr!r!r"r#ts   zBrotliDecoder.__init__cCst|jdƒr|j ¡SdS)NÚflushr)r@rrArr!r!r"rA{s  zBrotliDecoder.flushN)r.r/r0r#rAr!r!r!r"r>psr>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"Ú ‹rz)MultiDecoder.__init__..ú,)ÚsplitÚ _decoders)r Zmodesr!r!r"r#ŠszMultiDecoder.__init__cCs|jd ¡S©Nr)rJrArr!r!r"rA�szMultiDecoder.flushcCst|jƒD]}| |¡}q |Sr$)ÚreversedrJr*)r r,Údr!r!r"r*�s zMultiDecoder.decompressN)r.r/r0Ú__doc__r#rAr*r!r!r!r"rB�srBcCs:d|vrt|ƒS|dkrtƒStdur4|dkr4tƒStƒS)NrHÚgzipÚbr)rBr6r?r>r)Úmoder!r!r"rC–srCc@sneZdZdZddgZedur&edg7Zgd¢ZdLd d „Zd d„Zdd„Z dd„Z e dd„ƒZ e dd„ƒZ dd„Zdd„Zdd„Zdd„ZeejfZedur¦eejf7Zdd „Zd!d"„Zed#d$„ƒZd%d&„ZdMd'd(„ZdNd*d+„Zed,d-„ƒZd.d/„ZdOd0d1„Z d2d3„Z!d4d5„Z"e d6d7„ƒZ#d8d9„Z$d:d;„Z%dd?„Z'd@dA„Z(dBdC„Z)dDdE„Z*dPdFdG„Z+dHdI„Z,dJdK„Z-dS)QÚ 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. rOZdeflateNrP)i-i.i/i3i4ÚrTFcCst|tƒr||_n t|ƒ|_||_||_||_||_||_| |_||_ ||_ d|_ d|_ d|_ | |_d|_| |_||_|r�t|tjtfƒr�||_ | |_| |_t|dƒr¬||_ d|_d|_|j dd¡ ¡}dd„| d¡Dƒ}d |vrìd |_| |¡|_|�r|j �s|j|d �|_ dS) NrÚreadFztransfer-encodingrScss|]}| ¡VqdSr$)rD)rEÚencr!r!r"Ú rz(HTTPResponse.__init__..rHÚchunkedT©Údecode_content) Ú isinstancerÚheadersÚstatusÚversionÚreasonÚstrictrYÚretriesÚenforce_content_lengthÚ auto_closeÚ_decoderÚ_bodyÚ_fpÚ_original_responseÚ_fp_bytes_readÚmsgÚ _request_urlrZ string_typesr;Ú_poolÚ _connectionr@rWÚ chunk_leftÚgetÚlowerrIÚ _init_lengthÚlength_remainingrT)r Úbodyr[r\r]r^r_Zpreload_contentrYÚoriginal_responseZpoolÚ connectionrhr`raÚrequest_methodZ request_urlrbZtr_encÚ encodingsr!r!r"r#ÉsB    zHTTPResponse.__init__cCs|j|jvr|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[rmrr!r!r"Úget_redirect_location s  z"HTTPResponse.get_redirect_locationcCs(|jr |jsdS|j |j¡d|_dSr$)rjrkZ _put_connrr!r!r"Ú release_conns zHTTPResponse.release_connc Cs,z | ¡Wnttttfy&Yn0dS)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)rTr Ú SocketErrorr r rr!r!r"Ú drain_conn s zHTTPResponse.drain_conncCs"|jr |jS|jr|jdd�SdS)NT)Ú cache_content)rdrerTrr!r!r"r,+szHTTPResponse.datacCs|jSr$)rkrr!r!r"rs4szHTTPResponse.connectioncCs t|jƒSr$)rrerr!r!r"Úisclosed8szHTTPResponse.isclosedcCs|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). )rgrr!r!r"Útell;szHTTPResponse.tellcCsÜ|j d¡}|durˆ|jr(t d¡dSz.rHrz8Content-Length contained multiple unmatching values (%s)r)éÌi0édéÈZHEAD) r[rmrWÚlogZwarningÚsetrIÚlenrÚpopÚ ValueErrorrr\)r rtÚlengthZlengthsr\r!r!r"roCs6 ÿ ÿÿ     &zHTTPResponse._init_lengthcshˆj dd¡ ¡}ˆjdurd|ˆjvr2t|ƒˆ_n2d|vrd‡fdd„| d¡Dƒ}t|ƒrdt|ƒˆ_dS)z= Set-up the _decoder attribute if necessary. úcontent-encodingrSNrHcs"g|]}| ¡ˆjvr| ¡‘qSr!)rDÚCONTENT_DECODERS)rEÚerr!r"rG‚sþz.HTTPResponse._init_decoder..)r[rmrnrcr‹rCrIr†)r Úcontent_encodingrur!rr"Ú _init_decoderws    þzHTTPResponse._init_decoderc Csz|s|Sz|jr|j |¡}WnF|jyd}z,|j dd¡ ¡}td||ƒ‚WYd}~n d}~00|rv|| ¡7}|S)zN Decode the data passed in and potentially flush the decoder. rŠrSzEReceived response with content-encoding: %s, but failed to decode it.N)rcr*ÚDECODER_ERROR_CLASSESr[rmrnr Ú_flush_decoder)r r,rYÚ 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)rcr*rA)r Úbufr!r!r"r�¤s zHTTPResponse._flush_decoderc cs:d}zèz dVWn˜ty0t|jddƒ‚Ynztyt}z.dt|ƒvrRt|ƒ‚t|jddƒ‚WYd}~n>d}~0ttfy¨}ztd||ƒ‚WYd}~n d}~00d}W|sÔ|j rÄ|j   ¡|j rÔ|j   ¡|j rì|j   ¡rì|  ¡nH|�s|j �r|j   ¡|j �r|j   ¡|j �r4|j   ¡�r4|  ¡0dS)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)Ú SocketTimeoutrrjr Ústrrr rzrrfÚcloserkr}ry)r Z clean_exitrŒr!r!r"Ú_error_catcher¯s6    "$   ð  zHTTPResponse._error_catchercCsÆ|js J‚d}|r||ks*|jr¤|j|kr¤tjs¤tjs@tjdkr¤t ¡}d}|dus\|dkrœ|durxt ||ƒ}||8}n|}|j  |¡}|sŽqœ|  |¡~qL|  ¡S|dur¸|j  |¡S|j  ¡SdS)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) rerprZIS_SECURETRANSPORTZ IS_PYOPENSSLÚsysÚ version_infoÚioÚBytesIOÚminrTÚwriteÚgetvalue)r ÚamtZ c_int_maxÚbufferZ max_chunk_amtZ chunk_amtr,r!r!r"Ú_fp_readçs< þþýýûúú    zHTTPResponse._fp_readcCs | ¡|dur|j}|jdur$dSd}t|jddƒ}| ¡�l|sN| |¡nd}|dur`d}nrBrCr·rRr!r!r!r"Ús<          0