ó >´­_c@@sÒddlmZddlZddlZddlZddlmZddlmZ ddlm Z yddl Z Wne k rdZ nXddlmZddlmZmZdd lmZmZmZmZmZmZmZmZmZmZdd lm Z dd l!m"Z"m#Z#ej$e%ƒZ&d e'fd „ƒYZ(de'fd„ƒYZ)de'fd„ƒYZ*e dk r–de'fd„ƒYZ+nde'fd„ƒYZ,d„Z-dej.fd„ƒYZ/dS(i(tabsolute_importN(tcontextmanager(terror(ttimeouti(tHTTPHeaderDict(t BaseSSLErrort HTTPException( tBodyNotHttplibCompatiblet DecodeErrort HTTPErrortIncompleteReadtInvalidChunkLengtht InvalidHeadert ProtocolErrortReadTimeoutErrortResponseNotChunkedtSSLError(tsix(t is_fp_closedtis_response_to_headtDeflateDecodercB@s#eZd„Zd„Zd„ZRS(cC@s%t|_d|_tjƒ|_dS(Nt(tTruet _first_tryt_datatzlibt decompressobjt_obj(tself((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyt__init__$s  cC@st|j|ƒS(N(tgetattrR(Rtname((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyt __getattr__)scC@sÂ|s |S|js#|jj|ƒS|j|7_y5|jj|ƒ}|rbt|_d|_n|SWnTtjk r½t|_tjtj ƒ|_z|j|jƒSWdd|_XnXdS(N( RRt decompressRtFalsetNoneRRRt MAX_WBITS(Rtdatat decompressed((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR!,s"    (t__name__t __module__RR R!(((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR#s  tGzipDecoderStatecB@seZdZdZdZRS(iii(R'R(t FIRST_MEMBERt OTHER_MEMBERSt SWALLOW_DATA(((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR)Cst GzipDecodercB@s#eZd„Zd„Zd„ZRS(cC@s)tjdtjƒ|_tj|_dS(Ni(RRR$RR)R*t_state(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyRKscC@st|j|ƒS(N(RR(RR((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR OscC@sàtƒ}|jtjks"| r,t|ƒSx­trÛy||jj|ƒ7}WnEtj k r–|j}tj|_|tj krt|ƒS‚nX|jj }|s³t|ƒStj |_tj dtj ƒ|_q/WdS(Ni(t bytearrayR.R)R,tbytesRRR!RRR+t unused_dataRR$(RR%trettprevious_state((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR!Rs"         (R'R(RR R!(((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR-Js  t BrotliDecodercB@seZd„Zd„ZRS(cC@sFtjƒ|_t|jdƒr3|jj|_n|jj|_dS(NR!(tbrotlit DecompressorRthasattrR!tprocess(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyRnscC@s#t|jdƒr|jjƒSdS(NtflushR(R7RR9(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR9us (R'R(RR9(((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR4js t MultiDecodercB@s)eZdZd„Zd„Zd„ZRS(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|jdƒD]}t|jƒƒ^q|_dS(Nt,(tsplitt _get_decodertstript _decoders(Rtmodestm((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR„scC@s|jdjƒS(Ni(R?R9(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR9‡scC@s-x&t|jƒD]}|j|ƒ}qW|S(N(treversedR?R!(RR%td((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR!Šs(R'R(t__doc__RR9R!(((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR:{s  cC@sOd|krt|ƒS|dkr)tƒStdk rH|dkrHtƒStƒS(NR;tgziptbr(R:R-R5R#R4R(tmode((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR=s   t HTTPResponsecB@sùeZdZddgZed,k r4edg7ZndddddgZd d,d d d,d eed,d,d,d,d,ed,d,ed „Z d „Z d „Z d„Z e d„ƒZe d„ƒZd„Zd„Zd„Zd„ZeejfZed,k reejf7Znd„Zd„Zed„ƒZd,d,ed„Zd-d,d„Zed„ƒZd„Z d,d„Z!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. REtdeflateRFi-i.i/i3i4RicC@s¤t|tƒr||_nt|ƒ|_||_||_||_||_||_| |_||_ ||_ d|_ d|_ d|_| |_d|_| |_||_|rÛt|tjtfƒrÛ||_ n| |_| |_t|dƒr||_nt|_d|_|jjddƒjƒ}d„|jdƒDƒ}d|krft|_n|j |ƒ|_!|r |j r |j"d|ƒ|_ ndS( Nitreadstransfer-encodingRcs@s|]}|jƒVqdS(N(R>(t.0tenc((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pys ûsR;tchunkedtdecode_content(#t isinstanceRtheaderststatustversiontreasontstrictRNtretriestenforce_content_lengtht auto_closeR#t_decodert_bodyt_fpt_original_responset_fp_bytes_readtmsgt _request_urlRt string_typesR0t_poolt _connectionR7R"RMt chunk_lefttgettlowerR<Rt _init_lengthtlength_remainingRJ(RtbodyRPRQRRRSRTtpreload_contentRNtoriginal_responsetpoolt connectionR]RURVtrequest_methodt request_urlRWttr_enct encodings((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyRÃsB                        cC@s&|j|jkr"|jjdƒStS(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(RQtREDIRECT_STATUSESRPRcR"(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pytget_redirect_locationscC@s8|j s|j rdS|jj|jƒd|_dS(N(R`Rat _put_connR#(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyt release_connscC@s2y|jƒWnttttfk 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(RJR t SocketErrorRR(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyt drain_connscC@s-|jr|jS|jr)|jdtƒSdS(Nt cache_content(RYRZRJR(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR%%s  cC@s|jS(N(Ra(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyRk.scC@s t|jƒS(N(RRZ(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pytisclosed2scC@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((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyttell5scC@s;|jjdƒ}|d k rÍ|jr8tjdƒd Syctg|jdƒD]}t|ƒ^qNƒ}t |ƒdkrŽt d|ƒ‚n|j ƒ}Wnt k r´d }qÍX|dkrÍd }qÍnyt|j ƒ}Wnt k rùd}nX|d ks.d |kod kns.|d kr7d}n|S(sM Set initial length value for Response content if available. scontent-lengthsÒReceived 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)iiÌi0idiÈtHEADN(iÌi0(RPRcR#RMtlogtwarningtsetR<tinttlenR tpopt ValueErrorRQ(RRltlengthtvaltlengthsRQ((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyRe=s0  .       4 cC@s¼|jjddƒjƒ}|jdkr¸||jkrKt|ƒ|_q¸d|kr¸g|jdƒD]'}|jƒ|jkrg|jƒ^qg}t |ƒrµt|ƒ|_qµq¸ndS(s= Set-up the _decoder attribute if necessary. scontent-encodingRR;N( RPRcRdRXR#tCONTENT_DECODERSR=R<R>R(Rtcontent_encodingteRo((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyt _init_decoderqs ' cC@s|s |Sy"|jr+|jj|ƒ}nWnD|jk rr}|jjddƒjƒ}td||ƒ‚nX|rŒ||jƒ7}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.(RXR!tDECODER_ERROR_CLASSESRPRcRdRt_flush_decoder(RR%RNt flush_decoderR‡R†((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyt_decodeˆs  cC@s0|jr,|jjdƒ}||jjƒSdS(sk Flushes the decoder. Should only be called if the decoder is actually being used. R(RXR!R9(Rtbuf((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyRŠžs cc@st}z¯y dVWn™tk r:t|jddƒ‚nttk r‚}dt|ƒkrjt|ƒ‚nt|jddƒ‚n,tt fk r­}t d||ƒ‚nXt }Wd|só|j r×|j j ƒn|jró|jj ƒqón|j r|j jƒr|jƒnXdS(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 SocketTimeoutRR`R#RtstrRRRuR RR[tcloseRaRxRt(Rt clean_exitR‡((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyt_error_catcher©s(      cC@s€|jƒ|dkr"|j}n|jdkr5dSt}t|jdtƒ}|jƒ²|dkr|s~|jjƒnd}t}n}t}|s«|jj|ƒnd}|dkr | r |jj ƒt}|j r |j dkr t |j |j ƒ‚q nWdQX|r||j t|ƒ7_ |j dk rR|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(RˆR#RNRZR"RR’RJRRRVRfR R\RRŒRY(RtamtRNRwR‹t fp_closedR%((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyRJás8        !iicc@s}|jr=|jƒr=xa|j|d|ƒD] }|Vq+Wn<x9t|jƒsx|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. RNR”N(RMtsupports_chunked_readst read_chunkedRRZRJ(RR”RNtlineR%((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pytstream+s cK@s|j}t|tƒsHtjr3tj|ƒ}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``. RTiRgRPRQRRRSRi( R]RORRtPY2t from_httplibtitemsRRQRRRS(t ResponseClstrt response_kwRPRTtresp((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR›Es      cC@s|jS(N(RP(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyt getheadersfscC@s|jj||ƒS(N(RPRc(RRtdefault((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyt getheaderiscC@s|jS(N(RP(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pytinfomscC@sR|js|jjƒn|jr2|jjƒn|jsNtjj|ƒndS(N(R“RZRRaRWtiotIOBase(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyRqs    cC@sr|jstjjj|ƒS|jdkr/tSt|jdƒrN|jj ƒSt|jdƒrj|jjStSdS(NRxR“( RWR¥R¦R“t__get__RZR#RR7Rx(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR“{s   cC@sM|jdkrtdƒ‚n+t|jdƒr=|jjƒStdƒ‚dS(Ns-HTTPResponse has no file to get a fileno fromtfilenosOThe file-like object this HTTPResponse is wrapped around has no file descriptor(RZR#tIOErrorR7R¨(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR¨ˆs  cC@sH|jdk rDt|jdƒrDt|jdtƒ rD|jjƒSdS(NR9R“(RZR#R7RR"R9(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR9“scC@stS(N(R(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pytreadable›scC@sI|jt|ƒƒ}t|ƒdkr+dS||t|ƒ*t|ƒSdS(Ni(RJR(Rtbttemp((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pytreadintoŸs cC@st|jdƒS(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(R7RZ(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR–¨scC@s‚|jdk rdS|jjjƒ}|jddƒd}yt|dƒ|_Wn*tk r}|jƒt ||ƒ‚nXdS(Nt;iii( RbR#RZR®treadlineR<R~RRR (RR˜((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyt_update_chunk_length±s  cC@sød}|dkrI|jj|jƒ}|}|jjdƒd|_n«||jkrƒ|jj|ƒ}|j||_|}nq||jkrÆ|jj|ƒ}|jjdƒd|_|}n.|jj|jƒ}|jjdƒd|_|S(Ni(R#RZt _safe_readRb(RR”treturned_chunktchunktvalue((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyt _handle_chunk¿s&      c c@sj|jƒ|js"tdƒ‚n|jƒs=tdƒ‚n|jƒ|jrst|jƒrs|jjƒdS|j j dkr‰dSx_t rê|j ƒ|jdkr¯Pn|j|ƒ}|j|d|dtƒ}|rŒ|VqŒqŒW|r|jƒ}|r|Vqnx6t rF|j j jƒ}|s3Pn|dkrPqqW|jr`|jjƒnWdQXdS(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.NiRNR‹s (RˆRMRR–RR’R[RRRZR®R#RR±RbR¶RŒR"RŠR°(RR”RNR´tdecodedR˜((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyR—ÕsD               cC@s=|jdk r2t|jjƒr2|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. iÿÿÿÿN(RUR#Rthistorytredirect_locationR^(R((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pytgeturls!cc@sÄg}x |jdtƒD]Œ}d|kr˜|jdƒ}dj|ƒ|ddVx|dd!D]}|dVqbW|dr|dg}q¥g}q|j|ƒqW|rÀdj|ƒVndS(NRNs Riiiÿÿÿÿ(R™RR<tjointappend(RtbufferR´tx((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyt__iter__&s    Ni(/R'R(RDR…R5R#RqRR"RRrRtRvtpropertyR%RkRxRyReRˆR©RRR‰RŒRŠRR’RJR™t classmethodR›R¡R£R¤RR“R¨R9RªR­R–R±R¶R—RºR¿(((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyRHsn   1      4    8J!        F (0t __future__RR¥tloggingRt contextlibRtsocketRRuRRŽR5t ImportErrorR#t _collectionsRRkRRt exceptionsRRR R R R R RRRtpackagesRt util.responseRRt getLoggerR'R{tobjectRR)R-R4R:R=R¦RH(((s;/opt/awscli/lib/python2.7/site-packages/urllib3/response.pyts0     F