2{Yc@s;dZddlZddlZddlmZmZddlmZddlm Z ddl m Z ddl m Z mZdd lmZdd lmZdd lmZdd lmZdd lmZmZmZmZmZmZddlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6ddl7m8Z8e8j9e8j:e8j;e8j<fZ=dZ>dZ?dZ@deAfdYZBdeAfdYZCdeCfdYZDdeBeCfdYZEdeAfdYZFdS( s` requests.models ~~~~~~~~~~~~~~~ This module contains the primary objects that power Requests. iN(tBytesIOtUnsupportedOperationi(t default_hooks(tCaseInsensitiveDict(t HTTPBasicAuth(tcookiejar_from_dicttget_cookie_header(t RequestField(tencode_multipart_formdata(t parse_url(t DecodeError(t HTTPErrortRequestExceptiont MissingSchemat InvalidURLtChunkedEncodingErrortContentDecodingError( tguess_filenametget_auth_from_urlt requote_uritstream_decode_response_unicodetto_key_val_listtparse_header_linkst iter_slicestguess_json_utft super_lentto_native_string( t cookielibt urlunparseturlsplitt urlencodetstrtbytestStringIOtis_py2tchardettjsont builtin_strt basestringtIncompleteRead(tcodesii iitRequestEncodingMixincBs5eZedZedZedZRS(cCssg}t|j}|j}|s-d}n|j||j}|rf|jd|j|ndj|S(sBuild the path URL to use.t/t?t(Rturltpathtappendtquerytjoin(tselfR-tpR.R0((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pytpath_url1s     cCst|ttfr|St|dr,|St|drg}xt|D]\}}t|tsyt|d r|g}nxl|D]d}|dk r|jt|tr|jdn|t|tr|jdn|fqqWqNWt |dt S|SdS(sEncode parameters in a piece of data. Will successfully encode parameters when passed as a dict or a list of 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary if parameters are supplied as a dict. treadt__iter__sutf-8tdoseqN( t isinstanceRR thasattrRR&tNoneR/tencodeRtTrue(tdatatresulttktvstv((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyt_encode_paramsFs    !3c Csr|stdnt|tr3tdng}t|pEi}t|pWi}x|D]\}}t|tst|d r|g}nx|D]}|d k rt|tst|}n|jt|tr|j dn|t|tr|j dn|fqqWqdWx'|D]\}}d }d } t|t t frt |dkr|\} } qt |dkr|\} } }q|\} } }} nt|p|} |} t| trt| } nt| trt| } ntd|d| jd | d | } | jd ||j| q3Wt|\} }| |fS( sBuild the body for a multipart/form-data request. Will successfully encode files when passed as a dict or a list of 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary if parameters are supplied as a dict. sFiles must be provided.sData must not be a string.R6sutf-8iitnameR=tfilenametheaderst content_typeN(t ValueErrorR8R&RR9R:R RR/tdecodeR;ttupletlisttlenRR!RRR5tmake_multipartR(tfilesR=t new_fieldstfieldstfieldtvalRAR?tfttfhtfntfptrftbodyRF((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyt _encode_filesasL    !3(t__name__t __module__tpropertyR4t staticmethodRBRX(((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyR)0stRequestHooksMixincBseZdZdZRS(cCs||jkr"td|nt|tjrK|j|j|n0t|dr{|j|jd|DndS(sProperly register a hook.s1Unsupported event specified, with event name "%s"R6css'|]}t|tjr|VqdS(N(R8t collectionstCallable(t.0th((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pys sN(thooksRGR8R^R_R/R9textend(R2teventthook((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyt register_hooks cCs5y|j|j|tSWntk r0tSXdS(siDeregister a previously registered hook. Returns True if the hook existed, False if not. N(RbtremoveR<RGtFalse(R2RdRe((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pytderegister_hooks  (RYRZRfRi(((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyR]s tRequestc BsDeZdZdddddddddd ZdZdZRS(sA user-created :class:`Request ` object. Used to prepare a :class:`PreparedRequest `, which is sent to the server. :param method: HTTP method to use. :param url: URL to send. :param headers: dictionary of headers to send. :param files: dictionary of {filename: fileobject} files to multipart upload. :param data: the body to attach the request. If a dictionary is provided, form-encoding will take place. :param params: dictionary of URL parameters to append to the URL. :param auth: Auth handler or (user, pass) tuple. :param cookies: dictionary or CookieJar of cookies to attach to this request. :param hooks: dictionary of callback hooks, for internal usage. Usage:: >>> import requests >>> req = requests.Request('GET', 'http://httpbin.org/get') >>> req.prepare() c Cs |dkrgn|}|dkr*gn|}|dkrBin|}|dkrZin|}| dkrrin| } t|_x6t| jD]"\} } |jd| d| qW||_||_||_||_ ||_ ||_ ||_ ||_ dS(NRdRe(R:RRbRJtitemsRftmethodR-RERMR=tparamstauthtcookies( R2RlR-RERMR=RmRnRoRbR?RA((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyt__init__s         cCs d|jS(Ns(Rl(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyt__repr__scCsht}|jd|jd|jd|jd|jd|jd|jd|jd|j d |j |S( sXConstructs a :class:`PreparedRequest ` for transmission and returns it.RlR-RERMR=RmRnRoRb( tPreparedRequesttprepareRlR-RERMR=RmRnRoRb(R2R3((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRss           N(RYRZt__doc__R:RpRqRs(((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRjs  Rrc BseZdZdZdddddddddd ZdZdZdZdZ dZ dZ d Z d d Z d Zd ZRS(sThe fully mutable :class:`PreparedRequest ` object, containing the exact bytes that will be sent to the server. Generated from either a :class:`Request ` object or manually. Usage:: >>> import requests >>> req = requests.Request('GET', 'http://httpbin.org/get') >>> r = req.prepare() >>> s = requests.Session() >>> s.send(r) cCs=d|_d|_d|_d|_d|_t|_dS(N(R:RlR-REt_cookiesRWRRb(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRps      c Csh|j||j|||j||j||j|||j|||j| dS(s6Prepares the entire request with the given parameters.N(tprepare_methodt prepare_urltprepare_headerstprepare_cookiest prepare_bodyt prepare_autht prepare_hooks( R2RlR-RERMR=RmRnRoRb((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRs!s   cCs d|jS(Ns(Rl(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRq1scCsat}|j|_|j|_|jj|_|jj|_|j|_|j|_|S(N(RrRlR-REtcopyRuRWRb(R2R3((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyR}4s     cCs1||_|jdk r-|jj|_ndS(sPrepares the given HTTP method.N(RlR:tupper(R2Rl((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRv>s c Csnyt|}Wn-tk r/t|}ntk r?nXd|kro|jjd ro||_dSt|\}}}}}}} |stdj |n|st d|ny|j dj d}Wnt k rt dnX|p d } | r"| d 7} n| |7} |rI| dt|7} n|sXd }ntrt|tr|j d}nt| tr| j d} nt|tr|j d}nt|tr|j d}nt| tr| j d} qn|j|} | r=|r4d || f}q=| }ntt|| |d|| g}||_dS( sPrepares the given HTTP URL.t:thttpNsDInvalid URL {0!r}: No schema supplied. Perhaps you meant http://{0}?s Invalid URL %r: No host suppliedtidnasutf-8sURL has an invalid label.R,t@R*s%s&%s(tunicodet NameErrorRtUnicodeDecodeErrortlowert startswithR-R R tformatRR;RHt UnicodeErrorR"R8RBRRR:( R2R-RmtschemeRnthosttportR.R0tfragmenttnetloct enc_params((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRwDsZ  " !       $cCs8|r(td|jD|_n t|_dS(s Prepares the given HTTP headers.css'|]\}}t||fVqdS(N(R(R`RCtvalue((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pys sN(RRkRE(R2RE((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRxs"cCs}d }d }d }tt|dt|ttttf g}yt|}Wn t t t fk rud }nX|r|}|rt dn|d k rt ||jd|j|}t|ts,t|t s,t|dr5d }q>d}n|j||rpd|jkrp||jd ` object, which contains a server's response to an HTTP request. t_contentt status_codeRER-thistorytencodingtreasonRotelapsedtrequestcCstt|jt|_t|_d|_t|_ d|_ d|_ d|_ g|_ d|_ti|_tjd|_dS(Ni(tsuperRRpRhRt_content_consumedR:RRREtrawR-RRRRRotdatetimet timedeltaR(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRps         cs0jsjntfdjDS(Nc3s'|]}|t|dfVqdS(N(tgetattrR:(R`tattr(R2(sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pys 6s(RtcontentRt __attrs__(R2((R2sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyt __getstate__/s    cCsQx*|jD]\}}t|||q Wt|dtt|dddS(NRR(RktsetattrR<R:(R2tstateRCR((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyt __setstate__:scCs d|jS(Ns(R(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRqBscCs|jS(s,Returns true if :attr:`status_code` is 'OK'.(tok(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyt__bool__EscCs|jS(s,Returns true if :attr:`status_code` is 'OK'.(R(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyt __nonzero__IscCs |jdS(s,Allows you to use a response as an iterator.i(t iter_content(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyR6MscCs'y|jWntk r"tSXtS(N(traise_for_statusR RhR<(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRQs  cCsd|jko|jtkS(sTrue if this Response is a well-formed HTTP redirect that could have been processed automatically (by :meth:`Session.resolve_redirects`). tlocation(RERtREDIRECT_STATI(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyt is_redirectYscCstj|jdS(s6The apparent encoding, provided by the chardet libraryR(R#tdetectR(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pytapparent_encoding`sics^fd}tj}|}jr<|n|}|rZt|}n|S(sIterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place. If decode_unicode is True, content will be decoded using the best available encoding based on the response. c3sypy,x%jjdtD] }|VqWWn=tk rP}t|ntk rn}t|nXWn?tk rx/trjj}|sPn|VqWnXt_ dS(Ntdecode_content( RtstreamR<R'RR RRR5R(tchunkte(t chunk_sizeR2(sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pytgenerateos    (RRRR(R2Rtdecode_unicodeRt reused_chunkst stream_chunkstchunks((RR2sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRes  ccsd}x|jd|d|D]}|dk r>||}n|j}|r|dr|r|dd|dkr|j}nd}x|D] }|VqWqW|dk r|VndS(sIterates over the response data, one line at a time. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. RRiN(R:Rt splitlinestpop(R2RRtpendingRtlinestline((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyt iter_liness   .   cCs|jtkry^|jr*tdn|jdkrEd|_n'tj|jt pft|_Wqt k rd|_qXnt |_|jS(s"Content of the response, in bytes.s2The content for this response was already consumediN( RRhRt RuntimeErrorRR:R R1RtCONTENT_CHUNK_SIZERR<(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRs   +  cCsd}|j}|js"tdS|jdkr=|j}nyt|j|dd}Wn,ttfk rt|jdd}nX|S(sContent of the response, in unicode. If Response.encoding is None, encoding will be guessed using ``chardet``. The encoding of the response content is determined based solely on HTTP headers, following RFC 2616 to the letter. If you can take advantage of non-HTTP knowledge to make a better guess at the encoding, you should set ``r.encoding`` appropriately before accessing this property. R,terrorstreplaceN(R:RRRRt LookupErrorR(R2RR((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyttexts    cKs|j rtt|jdkrtt|j}|dk rty tj|jj||SWqqtk rmqqXqtntj|j |S(sReturns the json-encoded content of a response, if any. :param \*\*kwargs: Optional arguments that ``json.loads`` takes. iN( RRKRRR:R$tloadsRHRR(R2tkwargsR((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyR$s    cCsj|jjd}i}|rft|}x9|D].}|jdpR|jd}|||d|j|jf}n8d|jkoXdknrvd|j|jf}n|rt|d|ndS( s2Raises stored :class:`HTTPError`, if one occurred.R,iis%s Client Error: %siXs%s Server Error: %stresponseN(RRR (R2thttp_error_msg((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRscCs |jjS(sReleases the connection back to the pool. Once this method has been called the underlying ``raw`` object must not be accessed again. *Note: Should not normally need to be called explicitly.* (Rt release_conn(R2((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pytclosesN(RYRZRtRRpRRRqRRR6R[RRRRhRtITER_CHUNK_SIZER:RRRR$RRR(((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyRs:  (     *&  i((GRtR^RtioRRRbRt structuresRRnRRoRRtpackages.urllib3.fieldsRtpackages.urllib3.filepostRtpackages.urllib3.utilR tpackages.urllib3.exceptionsR t exceptionsR R R RRRtutilsRRRRRRRRRRtcompatRRRRRR R!R"R#R$R%R&R't status_codesR(tmovedtfoundtotherttemporary_movedRtDEFAULT_REDIRECT_LIMITRRtobjectR)R]RjRrR(((sL/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/requests/models.pyts6  .FX mJ