U 淀gw@sRddlmZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z dZddlmZddlmZdd lmZmZdd lmZmZmZmZmZmZmZmZmZm Z dd l!m"Z"dd l#m$Z$m%Z%e&e'Z(Gd dde)Z*Gddde)Z+Gddde)Z,edk r$Gddde)Z-Gddde)Z.ddZ/Gdddej0Z1dS))absolute_importN)contextmanager)error)timeout)util)HTTPHeaderDict) BaseSSLError HTTPException) BodyNotHttplibCompatible DecodeError HTTPErrorIncompleteReadInvalidChunkLength InvalidHeader ProtocolErrorReadTimeoutErrorResponseNotChunkedSSLError)six) is_fp_closedis_response_to_headc@s$eZdZddZddZddZdS)DeflateDecodercCsd|_d|_t|_dS)NT) _first_try_datazlib decompressobj_objselfr!J/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py__init__$szDeflateDecoder.__init__cCs t|j|SNgetattrrr namer!r!r" __getattr__)szDeflateDecoder.__getattr__c Cs|s|S|js|j|S|j|7_z"|j|}|rFd|_d|_|WStjk rd|_ttj |_z||jWYSd|_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)GzipDecoderStaterrN)r/r0r1 FIRST_MEMBER OTHER_MEMBERS SWALLOW_DATAr!r!r!r"r2Csr2c@s$eZdZddZddZddZdS) GzipDecodercCstdtj|_tj|_dSN)rrr+rr2r4_staterr!r!r"r#KszGzipDecoder.__init__cCs t|j|Sr$r%r'r!r!r"r)OszGzipDecoder.__getattr__cCst}|jtjks|st|Sz||j|7}Wn<tjk rn|j}tj|_|tj krht|YSYnX|jj }|st|Stj |_t dtj |_qdSr8) bytearrayr:r2r6bytesrr*rrr5 unused_datarr+)r r,retprevious_stater!r!r"r*Rs   zGzipDecoder.decompressNr.r!r!r!r"r7Jsr7c@seZdZddZddZdS) BrotliDecodercCs0t|_t|jdr"|jj|_n |jj|_dS)Nr*)brotliZ Decompressorrhasattrr*processrr!r!r"r#ns   zBrotliDecoder.__init__cCst|jdr|jSdS)Nflushr)rBrrDrr!r!r"rDus  zBrotliDecoder.flushN)r/r0r1r#rDr!r!r!r"r@jsr@c@s(eZdZdZddZddZddZdS) 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|dD|_dS)NcSsg|]}t|qSr!) _get_decoderstrip).0mr!r!r" sz)MultiDecoder.__init__..,)split _decoders)r modesr!r!r"r#szMultiDecoder.__init__cCs|jdSNr)rMrDrr!r!r"rDszMultiDecoder.flushcCst|jD]}||}q |Sr$)reversedrMr*)r r,dr!r!r"r*s zMultiDecoder.decompressN)r/r0r1__doc__r#rDr*r!r!r!r"rE{srEcCs:d|krt|S|dkrtStdk r4|dkr4tStS)NrKgzipbr)rEr7rAr@r)moder!r!r"rFsrFc@steZdZdZddgZedk r&edg7Zdddd d gZdPddZddZddZ ddZ e ddZ e ddZ ddZddZdd Zd!d"ZeejfZedk reejf7Zd#d$Zd%d&Zed'd(Zd)d*ZdQd+d,ZdRd.d/Zed0d1Zd2d3ZdSd4d5Z d6d7Z!d8d9Z"e d:d;Z#dd?Z%d@dAZ&dBdCZ'dDdEZ(dFdGZ)dHdIZ*dTdJdKZ+dLdMZ,dNdOZ-dS)U 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. rSdeflateNrTi-i.i/i3i4rTFcCst|tr||_n t||_||_||_||_||_||_| |_||_ ||_ d|_ d|_ d|_ | |_d|_| |_||_|rt|tjtfr||_ | |_| |_t|dr||_ d|_d|_|jdd}dd|dD}d |krd |_|||_|r|j s|j|d |_ dS) NrreadFztransfer-encodingrXcss|]}|VqdSr$)rG)rHencr!r!r" sz(HTTPResponse.__init__..rKchunkedTdecode_content) isinstancerheadersstatusversionreasonstrictr^retriesenforce_content_length auto_close_decoder_body_fp_original_response_fp_bytes_readmsg _request_urlr string_typesr<_pool _connectionrBr\ chunk_leftgetlowerrL _init_lengthlength_remainingrY)r bodyr`rarbrcrdpreload_contentr^original_responsepool connectionrmrerfrequest_method request_urlrgtr_enc encodingsr!r!r"r#sB    zHTTPResponse.__init__cCs|j|jkr|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)raREDIRECT_STATUSESr`rsrr!r!r"get_redirect_locations  z"HTTPResponse.get_redirect_locationcCs(|jr |jsdS|j|jd|_dSr$)rprq _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)rYr SocketErrorr r rr!r!r" drain_conns zHTTPResponse.drain_conncCs"|jr |jS|jr|jddSdS)NT) cache_content)rirjrYrr!r!r"r,%szHTTPResponse.datacCs|jSr$)rqrr!r!r"r{.szHTTPResponse.connectioncCs t|jSr$)rrjrr!r!r"isclosed2szHTTPResponse.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). )rlrr!r!r"tell5szHTTPResponse.tellcCs|jd}|dk r|jr(tddSz.rKrz8Content-Length contained multiple unmatching values (%s)r)i0dHEAD) r`rsr\logwarningsetrLlenrpop ValueErrorrra)r r|lengthlengthsrar!r!r"ru=s6     &zHTTPResponse._init_lengthcshjdd}jdkrd|jkr2t|_n2d|krdfdd|dD}t|rdt|_dS)z= Set-up the _decoder attribute if necessary. content-encodingrXNrKcs"g|]}|jkr|qSr!)rGCONTENT_DECODERS)rHerr!r"rJ|sz.HTTPResponse._init_decoder..)r`rsrtrhrrFrLr)r content_encodingrr!rr" _init_decoderqs    zHTTPResponse._init_decoderc Csx|s|Sz|jr|j|}WnD|jk rb}z$|jdd}td||W5d}~XYnX|rt||7}|S)zN Decode the data passed in and potentially flush the decoder. rrXzEReceived response with content-encoding: %s, but failed to decode it.N)rhr*DECODER_ERROR_CLASSESr`rsrtr _flush_decoder)r r,r^ flush_decoderrrr!r!r"_decodes  zHTTPResponse._decodecCs$|jr |jd}||jSdS)zk Flushes the decoder. Should only be called if the decoder is actually being used. r)rhr*rD)r bufr!r!r"rs zHTTPResponse._flush_decoderc csd}zz dVWntk r2t|jddYnvtk rt}z&dt |krVt |t|jddW5d}~XYn4t t fk r}zt d||W5d}~XYnXd}W5|s|jr|j|jr|j|jr|jr|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)rkcloserqrr SocketTimeoutrrpr strrr rr)r clean_exitrr!r!r"_error_catchers(      zHTTPResponse._error_catchercCs|js td}|r||ks*|jr|j|krtjstjs@tjdkrt }d}|dks\|dkr|dk rxt ||}||8}n|}|j |}|sq| |~qL| S|dk r|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)rjAssertionErrorrvrIS_SECURETRANSPORT IS_PYOPENSSLsys version_infoioBytesIOminrYwritegetvalue)r amt c_int_maxbuffer max_chunk_amt chunk_amtr,r!r!r"_fp_reads<     zHTTPResponse._fp_readc Cs||dkr|j}|jdkr$dSd}t|jdd}|b|sN||nd}|dkr`d}ns0      0