Eu\dc@@sddlmZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z y4yddlZWnek rddlZnXWnek rdZnXddlmZddlmZdd lmZmZdd lmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#dd l$m%Z%dd l&m'Z'm(Z(ej)e*Z+d e,fdYZ-de,fdYZ.de,fdYZ/edk rde,fdYZ0nde,fdYZ1dZ2dej3fdYZ4dS(i(tabsolute_importN(tcontextmanager(terror(ttimeouti(tutil(tHTTPHeaderDict(t BaseSSLErrort HTTPException( tBodyNotHttplibCompatiblet DecodeErrort HTTPErrortIncompleteReadtInvalidChunkLengtht InvalidHeadert ProtocolErrortReadTimeoutErrortResponseNotChunkedtSSLError(tsix(t is_fp_closedtis_response_to_headtDeflateDecodercB@s#eZdZdZdZRS(cC@s%t|_d|_tj|_dS(Nt(tTruet _first_tryt_datatzlibt decompressobjt_obj(tself((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt__init__*s  cC@st|j|S(N(tgetattrR(Rtname((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt __getattr__/scC@s|s |S|js#|jj|S|j|7_y5|jj|}|rbt|_d|_n|SWnTtjk rt|_tjtj |_z|j|jSWdd|_XnXdS(N( RRt decompressRtFalsetNoneRRRt MAX_WBITS(Rtdatat decompressed((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR"2s"    (t__name__t __module__RR!R"(((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR)s  tGzipDecoderStatecB@seZdZdZdZRS(iii(R(R)t FIRST_MEMBERt OTHER_MEMBERSt SWALLOW_DATA(((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR*Ist GzipDecodercB@s#eZdZdZdZRS(cC@s)tjdtj|_tj|_dS(Ni(RRR%RR*R+t_state(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRQscC@st|j|S(N(RR(RR ((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR!UscC@st}|jtjks"| r,t|Sxtry||jj|7}WnEtj k r|j}tj|_|tj krt|SnX|jj }|st|Stj |_tj dtj |_q/WdS(Ni(t bytearrayR/R*R-tbytesRRR"RRR,t unused_dataRR%(RR&trettprevious_state((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR"Xs"         (R(R)RR!R"(((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR.Ps  t BrotliDecodercB@seZdZdZRS(cC@sFtj|_t|jdr3|jj|_n|jj|_dS(NR"(tbrotlit DecompressorRthasattrR"tprocess(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRtscC@s#t|jdr|jjSdS(NtflushR(R8RR:(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR:{s (R(R)RR:(((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR5ps t MultiDecodercB@s)eZdZdZdZdZRS(s 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. cC@s5g|jdD]}t|j^q|_dS(Nt,(tsplitt _get_decodertstript _decoders(Rtmodestm((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRscC@s|jdjS(Ni(R@R:(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR:scC@s-x&t|jD]}|j|}qW|S(N(treversedR@R"(RR&td((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR"s(R(R)t__doc__RR:R"(((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR;s  cC@sOd|krt|S|dkr)tStdk rH|dkrHtStS(NR<tgziptbr(R;R.R6R$R5R(tmode((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR>s   t HTTPResponsecB@seZdZddgZed-k r4edg7ZndddddgZd d-d d d-d eed-d-d-d-d-ed-d-ed Z d Z d Z dZ e dZe dZdZdZdZdZeejfZed-k reejf7ZndZdZedZdZd-d-edZd.d-dZedZ dZ!d-dZ"d Z#d!Z$e d"Z%d#Z&d$Z'd%Z(d&Z)d'Z*d(Z+d)Z,d-d-d*Z-d+Z.d,Z/RS(/s 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. RFtdeflateRGi-i.i/i3i4RicC@st|tr||_nt||_||_||_||_||_||_| |_||_ ||_ d|_ d|_ d|_| |_d|_| |_||_|rt|tjtfr||_ n| |_| |_t|dr||_nt|_d|_|jjddj}d|jdD}d|krft|_n|j ||_!|r|j r|j"d||_ ndS( Nitreadstransfer-encodingRcs@s|]}|jVqdS(N(R?(t.0tenc((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pys sR<tchunkedtdecode_content(#t isinstanceRtheaderststatustversiontreasontstrictROtretriestenforce_content_lengtht auto_closeR$t_decodert_bodyt_fpt_original_responset_fp_bytes_readtmsgt _request_urlRt string_typesR1t_poolt _connectionR8R#RNt chunk_lefttgettlowerR=Rt _init_lengthtlength_remainingRK(RtbodyRQRRRSRTRUtpreload_contentROtoriginal_responsetpoolt connectionR^RVRWtrequest_methodt request_urlRXttr_enct encodings((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRsB                        cC@s&|j|jkr"|jjdStS(s 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. tlocation(RRtREDIRECT_STATUSESRQRdR#(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pytget_redirect_location scC@s8|j s|j rdS|jj|jd|_dS(N(RaRbt _put_connR$(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt release_connscC@s2y|jWnttttfk r-nXdS(s 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(RKR t SocketErrorRR(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt drain_conn scC@s-|jr|jS|jr)|jdtSdS(Nt cache_content(RZR[RKR(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR&+s  cC@s|jS(N(Rb(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRl4scC@s t|jS(N(RR[(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pytisclosed8scC@s|jS(s 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). (R](R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyttell;scC@s;|jjd}|d k r|jr8tjdd Syctg|jdD]}t|^qN}t |dkrt d|n|j }Wnt k rd }qX|dkrd }qnyt|j }Wnt k rd}nX|d ks.d |kod kns.|d kr7d}n|S(sM Set initial length value for Response content if available. scontent-lengthsReceived 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.R<is8Content-Length contained multiple unmatching values (%s)iii0iditHEADN(ii0(RQRdR$RNtlogtwarningtsetR=tinttlenR tpopt ValueErrorRR(RRmtlengthtvaltlengthsRR((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRfCs0  .       4 cC@s|jjddj}|jdkr||jkrKt||_qd|krg|jdD]'}|j|jkrg|j^qg}t |rt||_qqndS(s= Set-up the _decoder attribute if necessary. scontent-encodingRR<N( RQRdReRYR$tCONTENT_DECODERSR>R=R?R(Rtcontent_encodingteRp((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt _init_decoderws ' cC@s|s |Sy"|jr+|jj|}nWnD|jk rr}|jjddj}td||nX|r||j7}n|S(sN Decode the data passed in and potentially flush the decoder. scontent-encodingRsEReceived response with content-encoding: %s, but failed to decode it.(RYR"tDECODER_ERROR_CLASSESRQRdReR t_flush_decoder(RR&ROt flush_decoderRR((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt_decodes  cC@s0|jr,|jjd}||jjSdS(sk Flushes the decoder. Should only be called if the decoder is actually being used. R(RYR"R:(Rtbuf((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRs cc@st}zy dVWntk r:t|jddnttk r}dt|krjt|nt|jddn,tt fk r}t d||nXt }Wd|s|j r|j j n|jr|jj qn|j r|j jr|jnXdS(s 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. NsRead timed out.sread operation timed outsConnection broken: %r(R#t SocketTimeoutRRaR$RtstrRRRvRRR\tcloseRbRyRu(Rt clean_exitR((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt_error_catchers(      cC@s#|jstd }|r'||ks?|jr|j|krtj rtjsatjd krtj }d }xv|dks|dkr|dk rt ||}||8}n|}|jj |}|sPn|j |~qvW|jS|dk r|jj |S|jj SdS( s_ 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. iiiii iiNIi(ii i(R[tAssertionErrorRgRtIS_SECURETRANSPORTt IS_PYOPENSSLtsyst version_infotiotBytesIOR$tminRKtwritetgetvalue(Rtamtt c_int_maxtbuffert max_chunk_amtt chunk_amtR&((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt_fp_reads(      cC@sb|j|dkr"|j}n|jdkr5dSt}t|jdt}|j|sr|j|nd}|dkrt}n_t}|dkr| r|jj t}|j r|j dkrt |j |j qnWdQX|r^|j t|7_ |j dk r4|j t|8_ n|j|||}|r^||_q^n|S(sT 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.) NtclosedRi(iN(RR$ROR[R#RRRRRRWRgR R]RRRZ(RRRORxRt fp_closedR&((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRKs6        !iicc@s}|jr=|jr=xa|j|d|D] }|Vq+Wn<x9t|jsx|jd|d|}|r@|Vq@q@WdS(s_ 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. RORN(RNtsupports_chunked_readst read_chunkedRR[RK(RRROtlineR&((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pytstream_s cK@s|j}t|tsHtjr3tj|}qHt|j}nt|dd}|d|d|d|jd|j d|j d|d||}|S( s 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``. RUiRhRQRRRSRTRj( R^RPRRtPY2t from_httplibtitemsRRRRSRT(t ResponseClstrt response_kwRQRUtresp((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRys      cC@s tjddtdd|jS(Ns|HTTPResponse.getheaders() is deprecated and will be removed in urllib3 v2.1.0. Instead access HTTPResponse.headers directly.tcategoryt stackleveli(twarningstwarntDeprecationWarningRQ(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt getheaderss cC@s,tjddtdd|jj||S(NsHTTPResponse.getheader() is deprecated and will be removed in urllib3 v2.1.0. Instead use HTTPResponse.headers.get(name, default).RRi(RRRRQRd(RR tdefault((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt getheaders cC@s|jS(N(RQ(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pytinfoscC@sR|js|jjn|jr2|jjn|jsNtjj|ndS(N(RR[RRbRXRtIOBase(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRs    cC@sr|jstjjj|S|jdkr/tSt|jdrN|jj St|jdrj|jjStSdS(NRyR( RXRRRt__get__R[R$RR8Ry(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRs   cC@sM|jdkrtdn+t|jdr=|jjStddS(Ns-HTTPResponse has no file to get a fileno fromtfilenosOThe file-like object this HTTPResponse is wrapped around has no file descriptor(R[R$tIOErrorR8R(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRs  cC@sH|jdk rDt|jdrDt|jdt rD|jjSdS(NR:R(R[R$R8RR#R:(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyR:scC@stS(N(R(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pytreadablescC@sI|jt|}t|dkr+dS||t|*t|SdS(Ni(RKR(Rtbttemp((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pytreadintos cC@st|jdS(s 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(). tfp(R8R[(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRscC@s|jdk rdS|jjj}|jddd}yt|d|_Wn*tk r}|jt ||nXdS(Nt;iii( RcR$R[RtreadlineR=RRRR (RR((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt_update_chunk_lengths  cC@sd}|dkrI|jj|j}|}|jjdd|_n||jkr|jj|}|j||_|}nq||jkr|jj|}|jjdd|_|}n.|jj|j}|jjdd|_|S(Ni(R$R[t _safe_readRc(RRtreturned_chunktchunktvalue((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt _handle_chunks&      c c@sj|j|js"tdn|js=tdn|j|jrst|jrs|jjdS|j j dkrdSx_t r|j |jdkrPn|j|}|j|d|dt}|r|VqqW|r|j}|r|Vqnx6t rF|j j j}|s3Pn|dkrPqqW|jr`|jjnWdQXdS(s 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. sHResponse is not chunked. Header 'transfer-encoding: chunked' is missing.skBody should be http.client.HTTPResponse like. It should have have an fp attribute which returns raw chunks.NiRORs (RRNRRRRR\RRR[RR$RRRcRRR#RR(RRRORtdecodedR((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRsD               cC@s=|jdk r2t|jjr2|jjdjS|jSdS(s 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. iN(RVR$Rthistorytredirect_locationR_(R((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pytgeturl[s!cc@sg}x|jdtD]}d|kr|jd}dj||ddVx|dd!D]}|dVqbW|dr|dg}qg}q|j|qW|rdj|VndS(NROs Riii(RRR=tjointappend(RRRtx((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyt__iter__fs    Ni(0R(R)RERR6R$RrRR#RRsRuRwtpropertyR&RlRyRzRfRRRRRRRRRRRKRt classmethodRRRRRRRR:RRRRRRRR(((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyRIsp   1      4    8 0H!      F (5t __future__RRtloggingRRRt contextlibRtsocketRRvRRt brotlicffiR6t ImportErrorR$RRt _collectionsRRlRRt exceptionsRR R R R R RRRRtpackagesRt util.responseRRt getLoggerR(R|tobjectRR*R.R5R;R>RRI(((si/private/var/folders/49/mc35vj0j30g7w0ryjvyy2vz80000gs/T/pip-target-MP7kiJ/lib/python/urllib3/response.pyts<        F