ó _XîTc@sèddlZddlZddlmZddlmZddlmZm Z m Z ddl m Z mZmZddlmZmZddlmZd efd „ƒYZd efd „ƒYZd „Zdejfd„ƒYZdS(iÿÿÿÿN(ttimeouti(tHTTPHeaderDict(t ProtocolErrort DecodeErrortReadTimeoutError(t string_typest binary_typetPY3(t HTTPExceptiont BaseSSLError(t is_fp_closedtDeflateDecodercBs#eZd„Zd„Zd„ZRS(cCs(t|_tƒ|_tjƒ|_dS(N(tTruet _first_tryRt_datatzlibt decompressobjt_obj(tself((s4/usr/lib/python2.7/site-packages/urllib3/response.pyt__init__s  cCst|j|ƒS(N(tgetattrR(Rtname((s4/usr/lib/python2.7/site-packages/urllib3/response.pyt __getattr__scCs¡|s |S|js#|jj|ƒS|j|7_y|jj|ƒSWnTtjk rœt|_tjtj ƒ|_z|j|jƒSWdd|_XnXdS(N( R Rt decompressRRterrortFalseRt MAX_WBITStNone(Rtdata((s4/usr/lib/python2.7/site-packages/urllib3/response.pyRs  (t__name__t __module__RRR(((s4/usr/lib/python2.7/site-packages/urllib3/response.pyR s  t GzipDecodercBs#eZd„Zd„Zd„ZRS(cCstjdtjƒ|_dS(Ni(RRRR(R((s4/usr/lib/python2.7/site-packages/urllib3/response.pyR+scCst|j|ƒS(N(RR(RR((s4/usr/lib/python2.7/site-packages/urllib3/response.pyR.scCs|s |S|jj|ƒS(N(RR(RR((s4/usr/lib/python2.7/site-packages/urllib3/response.pyR1s(RRRRR(((s4/usr/lib/python2.7/site-packages/urllib3/response.pyR)s  cCs|dkrtƒStƒS(Ntgzip(RR (tmode((s4/usr/lib/python2.7/site-packages/urllib3/response.pyt _get_decoder7s t HTTPResponsec BseZdZddgZdddddgZddd d dd eedddd „ Zd „Zd „Z e d „ƒZ d„Z dde d„Zddd„Zed„ƒZd„Zdd„Zd„Ze d„ƒZd„Zd„Zd„Zd„ZRS(sÅ 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 tdeflatei-i.i/i3i4tic Cst|tƒr||_nt|ƒ|_||_||_||_||_||_d|_ d|_ d|_ | |_ d|_ |r«t|ttfƒr«||_ n| |_| |_t|dƒrØ||_ n|r|j r|jd|ƒ|_ ndS(Nitreadtdecode_content(t isinstanceRtheaderststatustversiontreasontstrictR'Rt_decodert_bodyt_fpt_original_responset_fp_bytes_readt basestringRt_poolt _connectionthasattrR&( RtbodyR)R*R+R,R-tpreload_contentR'toriginal_responsetpoolt connection((s4/usr/lib/python2.7/site-packages/urllib3/response.pyR[s*               cCs&|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(R*tREDIRECT_STATUSESR)tgetR(R((s4/usr/lib/python2.7/site-packages/urllib3/response.pytget_redirect_location{scCs8|j s|j rdS|jj|jƒd|_dS(N(R4R5t _put_connR(R((s4/usr/lib/python2.7/site-packages/urllib3/response.pyt release_connˆscCs-|jr|jS|jr)|jdtƒSdS(Nt cache_content(R/R0R&R (R((s4/usr/lib/python2.7/site-packages/urllib3/response.pyRs  cCs|jS(sÛ 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). (R2(R((s4/usr/lib/python2.7/site-packages/urllib3/response.pyttell˜sc Cso|jjddƒjƒ}|jdkrN||jkrNt|ƒ|_qNn|dkrf|j}n|jdkrydSt }zÃyi|dkr©|jj ƒ}t }nAt }|jj |ƒ}|dkrê| rê|jj ƒt }nWnŠt k rt|jddƒ‚netk rR}dt|ƒkr:‚nt|jddƒ‚n&tk rw}td||ƒ‚nX|jt|ƒ7_y(|r´|jr´|jj|ƒ}nWn/ttjfk ræ}td||ƒ‚nX|r+|r+|jr+|jjtƒƒ}|||jjƒ7}n|r=||_n|SWd|jrj|jjƒrj|j ƒnXdS( sP 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.) scontent-encodingR%NisRead timed out.sread operation timed outsConnection broken: %rsEReceived response with content-encoding: %s, but failed to decode it.(!R)R>tlowerR.RtCONTENT_DECODERSR"R'R0RR&R tcloset SocketTimeoutRR4R tstrRRR2tlenRtIOErrorRRRRtflushR/R1tisclosedRA( RtamtR'RBtcontent_encodingt flush_decoderRtetbuf((s4/usr/lib/python2.7/site-packages/urllib3/response.pyR& sV        iiccs@x9t|jƒs;|jd|d|ƒ}|r|VqqWdS(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. RMR'N(R R0R&(RRMR'R((s4/usr/lib/python2.7/site-packages/urllib3/response.pytstreamscKsš|j}t|tƒsEtr3t|jƒƒ}qEtj|ƒ}nt|ddƒ}|d|d|d|jd|jd|j d|d||}|S( s  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-iR7R)R*R+R,R9( tmsgR(RRtitemst from_httplibRR*R+R,(t ResponseClstrt response_kwR)R-tresp((s4/usr/lib/python2.7/site-packages/urllib3/response.pyRUs      cCs|jS(N(R)(R((s4/usr/lib/python2.7/site-packages/urllib3/response.pyt getheaders3scCs|jj||ƒS(N(R)R>(RRtdefault((s4/usr/lib/python2.7/site-packages/urllib3/response.pyt getheader6scCs|js|jjƒndS(N(tclosedR0RF(R((s4/usr/lib/python2.7/site-packages/urllib3/response.pyRF:s cCsV|jdkrtSt|jdƒr/|jjSt|jdƒrN|jjƒStSdS(NR]RL(R0RR R6R]RL(R((s4/usr/lib/python2.7/site-packages/urllib3/response.pyR]>s  cCsM|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(R0RRJR6R^(R((s4/usr/lib/python2.7/site-packages/urllib3/response.pyR^Is  cCs2|jdk r.t|jdƒr.|jjƒSdS(NRK(R0RR6RK(R((s4/usr/lib/python2.7/site-packages/urllib3/response.pyRKRs!cCstS(N(R (R((s4/usr/lib/python2.7/site-packages/urllib3/response.pytreadableVscCsI|jt|ƒƒ}t|ƒdkr+dS||t|ƒ*t|ƒSdS(Ni(R&RI(Rtbttemp((s4/usr/lib/python2.7/site-packages/urllib3/response.pytreadintoZs Ni(RRt__doc__RER=RR RR?RAtpropertyRRCRR&RRt classmethodRURZR\RFR]R^RKR_Rb(((s4/usr/lib/python2.7/site-packages/urllib3/response.pyR#>s*    `     (RtiotsocketRRGt _collectionsRt exceptionsRRRt packages.sixRR3RRR;RR t util.responseR tobjectR RR"tIOBaseR#(((s4/usr/lib/python2.7/site-packages/urllib3/response.pyts