Viewing File: /opt/alt/python35/lib/python3.5/site-packages/urllib3/__pycache__/response.cpython-35.opt-1.pyc



`WnH@s7ddlmZddlmZddlZddlZddlmZddlm	Z
ddlmZddl
mZmZmZmZdd	lmZmZmZdd
lmZddlmZmZddlmZmZGd
dde Z!Gddde Z"ddZ#Gdddej$Z%dS))absolute_import)contextmanagerN)timeout)error)HTTPHeaderDict)
ProtocolErrorDecodeErrorReadTimeoutErrorResponseNotChunked)string_typesbinary_typePY3)http_client)
HTTPExceptionBaseSSLError)is_fp_closedis_response_to_headc@s4eZdZddZddZddZdS)DeflateDecodercCs(d|_t|_tj|_dS)NT)
_first_tryr
_datazlib
decompressobj_obj)selfr/response.py__init__s	zDeflateDecoder.__init__cCst|j|S)N)getattrr)rnamerrr__getattr__szDeflateDecoder.__getattr__cCs|s
|S|js#|jj|S|j|7_y|jj|SWnUtjk
rd|_tjtj|_z|j|jSWdd|_XYnXdS)NF)rr
decompressrrrr	MAX_WBITS)rdatarrrr!s		zDeflateDecoder.decompressN)__name__
__module____qualname__rr r!rrrrrsrc@s4eZdZddZddZddZdS)GzipDecodercCstjdtj|_dS)N)rrr"r)rrrrr1szGzipDecoder.__init__cCst|j|S)N)rr)rrrrrr 4szGzipDecoder.__getattr__cCs|s
|S|jj|S)N)rr!)rr#rrrr!7szGzipDecoder.decompressN)r$r%r&rr r!rrrrr'/sr'cCs|dkrtStS)Ngzip)r'r)moderrr_get_decoder=sr+c
@seZdZdZddgZdddddgZd	d
ddd
dddd
d
d
d
dZddZddZe	ddZ
ddZddZddZ
ddZeddZd
d
dd d!Zd>d
d$d%Zed&d'Zd(d)Zd
d*d+Zd,d-Ze	d.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zd
d
d<d=Zd
S)?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, attempts to decode specific content-encoding's based on headers
        (like 'gzip' and 'deflate') will be skipped and raw data will be used
        instead.

    :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.
    r)Zdeflatei-i.i/i3i4NrTcCsYt|tr||_nt||_||_||_||_||_||_d|_d|_	d|_
|	|_d|_|rt|t
tfr||_	|
|_||_t|dr||_
d|_d|_|jjddj}dd|jdD}
d	|
kr0d
|_|rU|j	rU|jd||_	dS)NrreadFztransfer-encodingr-css|]}|jVqdS)N)strip).0encrrr	<genexpr>sz(HTTPResponse.__init__.<locals>.<genexpr>,chunkedTdecode_content)
isinstancerheadersstatusversionreasonstrictr5_decoder_body_fp_original_response_fp_bytes_read
basestringr
_pool_connectionhasattrr4
chunk_leftgetlowersplitr.)rbodyr7r8r9r:r;Zpreload_contentr5original_responsepool
connectionZtr_enc	encodingsrrrras6																	zHTTPResponse.__init__cCs&|j|jkr"|jjdSdS)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)r8REDIRECT_STATUSESr7rF)rrrrget_redirect_locationsz"HTTPResponse.get_redirect_locationcCs8|js|jrdS|jj|jd|_dS)N)rBrCZ	_put_conn)rrrrrelease_connszHTTPResponse.release_conncCs-|jr|jS|jr)|jddSdS)N
cache_contentT)r=r>r.)rrrrr#s		zHTTPResponse.datacCs|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).
        )r@)rrrrtellszHTTPResponse.tellcCsL|jjddj}|jdkrH||jkrHt||_dS)z<
        Set-up the _decoder attribute if necessar.
        zcontent-encodingr-N)r7rFrGr<CONTENT_DECODERSr+)rcontent_encodingrrr
_init_decoderszHTTPResponse._init_decodercCsy%|r$|jr$|jj|}Wn\ttjfk
r}z3|jjddj}td||WYdd}~XnX|r|r||j	7}|S)zN
        Decode the data passed in and potentially flush the decoder.
        zcontent-encodingr-zEReceived response with content-encoding: %s, but failed to decode it.N)
r<r!IOErrorrrr7rFrGr	_flush_decoder)rr#r5
flush_decodererUrrr_decodes zHTTPResponse._decodecCs0|jr,|jjd}||jjSdS)zk
        Flushes the decoder. Should only be called if the decoder is actually
        being used.
        )r<r!flush)rbufrrrrXs	zHTTPResponse._flush_decoderccs*d}zy	dVWntk
r;t|jddYntk
r}z/dt|krbt|jddWYdd}~Xn>ttfk
r}ztd||WYdd}~XnXd}Wd|s|jr|jj	|j
r|j
j	|jr%|jjr%|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
rBrstrrSocketErrorrr?closerCisclosedrQ)rZ
clean_exitrZrrr_error_catchers(		
'&
	
	
zHTTPResponse._error_catcherFcCs|j|dkr|j}|jdkr2dSd}d}|jg|dkro|jj}d}n>d}|jj|}|dkr|r|jjd}WdQRX|r|jt|7_|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.)
        NFTr)
rVr5r>rdr.rbr@lenr[r=)ramtr5rRrYr#rrrr.s,
	
	

	zHTTPResponse.readr(ccsn|jr1x^|j|d|D]}|VqWn9x6t|jsi|jd|d|}|r4|Vq4WdS)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.
        r5rfN)r4read_chunkedrr>r.)rrfr5liner#rrrstreamLs	zHTTPResponse.streamcKs|j}t|tsBtr3t|j}ntj|}t|dd}|d|d|d|jd|jd|j	d|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;rrIr7r8r9r:rJ)
msgr6rritemsfrom_httplibrr8r9r:)ZResponseClsrZresponse_kwr7r;Zresprrrrmfs						zHTTPResponse.from_httplibcCs|jS)N)r7)rrrr
getheadersszHTTPResponse.getheaderscCs|jj||S)N)r7rF)rrdefaultrrr	getheaderszHTTPResponse.getheadercCs0|js|jj|jr,|jjdS)N)closedr>rbrC)rrrrrbs	
	zHTTPResponse.closecCsV|jdkrdSt|jdr/|jjSt|jdrN|jjSdSdS)NTrrrc)r>rDrrrc)rrrrrrs

zHTTPResponse.closedcCsM|jdkrtdn+t|jdr=|jjStddS)Nz-HTTPResponse has no file to get a fileno fromfilenozOThe file-like object this HTTPResponse is wrapped around has no file descriptor)r>rWrDrs)rrrrrss

zHTTPResponse.filenocCs2|jdk	r.t|jdr.|jjSdS)Nr])r>rDr])rrrrr]s!zHTTPResponse.flushcCsdS)NTr)rrrrreadableszHTTPResponse.readablecCsO|jt|}t|dkr+dS||dt|<t|SdS)Nr)r.re)rbZtemprrrreadintos
zHTTPResponse.readintocCs|jdk	rdS|jjj}|jddd}yt|d|_Wn+tk
r~|jtj	|YnXdS)N;rrr()
rEr>fpreadlinerHint
ValueErrorrbhttplibZIncompleteRead)rrirrr_update_chunk_lengths

z!HTTPResponse._update_chunk_lengthcCsd}|dkrI|jj|j}|}|jjdd|_n||jkr|jj|}|j||_|}nq||jkr|jj|}|jjdd|_|}n.|jj|j}|jjdd|_|S)Nrg)r>Z
_safe_readrE)rrfZreturned_chunkchunkvaluerrr
_handle_chunks&				zHTTPResponse._handle_chunkc
cs|j|jstd|jrHt|jrH|jjdS|jxS|j|jdkrrP|j	|}|j
|d|dd}|rX|VqXW|r|j}|r|Vx*|jj
j}|sP|dkrPqW|jr|jjWdQRXdS)z
        Similar to :meth:`HTTPResponse.read`, but with an additional
        parameter: ``decode_content``.

        :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.Nrr5rYFs
)rVr4rr?rrbrdr}rErr[rXr>rxry)rrfr5r~Zdecodedrirrrrhs:	
		


			zHTTPResponse.read_chunkedi) r$r%r&__doc__rTrOrrPrQpropertyr#rSrVr[rXrrdr.rjclassmethodrmrorqrbrrrsr]rtrvr}rrhrrrrr,Ds8	(
	
9<		r,)&Z
__future__r
contextlibrriosocketrr_rra_collectionsr
exceptionsrr	r
rZpackages.sixrrAr
rZpackages.six.movesrr|rLrrZ
util.responserrobjectrr'r+IOBaser,rrrr<module>s"
Back to Directory File Manager