U cf@sdZddlZddlZddlmZddlmZmZm Z m Z m Z ddl m Z ddlmZddlmZdd lmZmZdd lmZdd lmZmZmZmZmZmZmZdd lmZ dd lm!Z!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.ddl(mZ/ddl(m0Z0ddl(m Z1ddl(m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:m;Z;mZ>m?Z?m@Z@mAZAmBZBmCZCe6jDe6jEe6jFe6jGe6jHfZIdZJdZKdZLGdddZMGdddZNGdd d eNZOGd!d"d"eMeNZPGd#d$d$ZQdS)%z` requests.models ~~~~~~~~~~~~~~~ This module contains the primary objects that power Requests. N)UnsupportedOperation) DecodeErrorLocationParseError ProtocolErrorReadTimeoutErrorSSLError) RequestField)encode_multipart_formdata) parse_url)to_native_stringunicode_is_ascii) HTTPBasicAuth)CallableJSONDecodeErrorMapping basestring builtin_strchardet cookielib)json) urlencodeurlsplit urlunparse)_copy_cookie_jarcookiejar_from_dictget_cookie_header)ChunkedEncodingErrorConnectionErrorContentDecodingError HTTPErrorInvalidJSONError InvalidURL)r) MissingSchema)r)StreamConsumedError) default_hooks)codes)CaseInsensitiveDict) check_header_validityget_auth_from_urlguess_filenameguess_json_utf iter_slicesparse_header_links requote_uristream_decode_response_unicode super_lento_key_val_listi(ic@s0eZdZeddZeddZeddZdS)RequestEncodingMixincCsNg}t|j}|j}|sd}|||j}|rD|d||d|S)zBuild the path URL to use./?)rurlpathappendqueryjoin)selfr7pr8r:r>I/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/requests/models.pypath_urlUs    zRequestEncodingMixin.path_urlcCst|ttfr|St|dr |St|drg}t|D]j\}}t|tsRt|dsX|g}|D]B}|dk r\|t|tr|dn|t|tr|dn|fq\q6t|ddS|SdS)zEncode 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. read__iter__Nutf-8T)doseq) isinstancestrbyteshasattrr1rr9encoder)dataresultkvsvr>r>r?_encode_paramsjs$    z#RequestEncodingMixin._encode_paramscCs|stdnt|tr tdg}t|p,i}t|p8i}|D]|\}}t|ts\t|dsb|g}|D]T}|dk rft|tst|}|t|tr|dn|t|tr| dn|fqfq@|D]\}}d}d} t|t t fr t |dkr|\} } n&t |dkr|\} } }n |\} } }} nt |p,|} |} t| tttfrJ| } n(t| dr`| } n| dkrnqn| } t|| | | d } | j|d || qt|\}}||fS) aBuild the body for a multipart/form-data request. Will successfully encode files when passed as a dict or a list of tuples. Order is retained if data is a list of tuples but arbitrary if parameters are supplied as a dict. The tuples may be 2-tuples (filename, fileobj), 3-tuples (filename, fileobj, contentype) or 4-tuples (filename, fileobj, contentype, custom_headers). zFiles must be provided.zData must not be a string.rBNrCrA)namerJfilenameheaders) content_type) ValueErrorrErr1rHrGrFr9decoderItuplelistlenr* bytearrayrArmake_multipartr )filesrJ new_fieldsfieldsfieldvalrNrLftfhfnfpfdatarfbodyrUr>r>r? _encode_filessX                  z"RequestEncodingMixin._encode_filesN)__name__ __module__ __qualname__propertyr@ staticmethodrOrir>r>r>r?r3Ts   r3c@seZdZddZddZdS)RequestHooksMixincCs^||jkrtd|dt|tr6|j||n$t|drZ|j|dd|DdS)zProperly register a hook.z.Unsupported event specified, with event name ""rBcss|]}t|tr|VqdSN)rEr).0hr>r>r? s z2RequestHooksMixin.register_hook..N)hooksrVrErr9rHextendr<eventhookr>r>r? register_hooks    zRequestHooksMixin.register_hookcCs2z|j||WdStk r,YdSXdS)ziDeregister a previously registered hook. Returns True if the hook existed, False if not. TFN)ruremoverVrwr>r>r?deregister_hooks z!RequestHooksMixin.deregister_hookN)rjrkrlrzr|r>r>r>r?ros roc @s*eZdZdZd ddZddZddZdS) Requesta{A 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 to the request. If a dictionary or list of tuples ``[(key, value)]`` is provided, form-encoding will take place. :param json: json for the body to attach to the request (if files or data is not specified). :param params: URL parameters to append to the URL. If a dictionary or list of tuples ``[(key, value)]`` is provided, form-encoding will take place. :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', 'https://httpbin.org/get') >>> req.prepare() Nc Cs|dkr gn|}|dkrgn|}|dkr,in|}|dkrr>r?__init__s"zRequest.__init__cCsd|jdS)Nz rr<r>r>r?__repr__$szRequest.__repr__c Cs<t}|j|j|j|j|j|j|j|j|j |j |j d |S)zXConstructs a :class:`PreparedRequest ` for transmission and returns it.) rr7rTr]rJrrrrru) PreparedRequestpreparerr7rTr]rJrrrrrur<r=r>r>r?r's zRequest.prepare) NNNNNNNNNN)rjrkrl__doc__rrrr>r>r>r?r}s "r}c @seZdZdZddZdddZddZd d Zd d Ze d dZ ddZ ddZ dddZ ddZd ddZddZddZdS)!ra)The fully mutable :class:`PreparedRequest ` object, containing the exact bytes that will be sent to the server. Instances are generated from a :class:`Request ` object, and should not be instantiated manually; doing so may produce undesirable effects. Usage:: >>> import requests >>> req = requests.Request('GET', 'https://httpbin.org/get') >>> r = req.prepare() >>> r >>> s = requests.Session() >>> s.send(r) cCs0d|_d|_d|_d|_d|_t|_d|_dSrq)rr7rT_cookiesrhr%ru_body_positionrr>r>r?rNszPreparedRequest.__init__Nc CsR||||||||||||| ||||| dS)z6Prepares the entire request with the given parameters.N)prepare_method prepare_urlprepare_headersprepare_cookies prepare_body prepare_auth prepare_hooks) r<rr7rTr]rJrrrrurr>r>r?r_s     zPreparedRequest.preparecCsd|jdS)Nzr>r?r{szPreparedRequest.__repr__cCsXt}|j|_|j|_|jdk r*|jnd|_t|j|_|j|_|j|_|j |_ |Srq) rrr7rTcopyrrrhrurrr>r>r?r~s zPreparedRequest.copycCs$||_|jdk r t|j|_dS)zPrepares the given HTTP method.N)rr upper)r<rr>r>r?rs zPreparedRequest.prepare_methodcCsDddlm}z|j|ddd}Wn|jk r>tYnX|S)Nr)idnaT)uts46rC) pip._vendorrrIrW IDNAError UnicodeError)hostrr>r>r?_get_idna_encoded_hosts   z&PreparedRequest._get_idna_encoded_hostc Cst|tr|d}nt|}|}d|krF|dsF||_dSzt|\}}}}}}} Wn,t k r} zt | j W5d} ~ XYnX|st d|d|d|st d|dt |sz||}Wntk rt d YnXn|d rt d |pd } | r| d 7} | |7} |r:| d|7} |sDd }t|ttfr\t|}||} | r|r|d| }n| }tt|| |d|| g}||_dS)zPrepares the given HTTP URL.utf8:httpNz Invalid URL z0: No scheme supplied. Perhaps you meant https://r5z: No host suppliedzURL has an invalid label.)*.r6@r4&)rErGrWrFlstriplower startswithr7r rr"argsr#r rrr rOr.r) r<r7rschemerrportr8r:fragmentenetloc enc_paramsr>r>r?rsR     zPreparedRequest.prepare_urlcCs<t|_|r8|D]"}t||\}}||jt|<qdS)z Prepares the given HTTP headers.N)r'rTr~r(r )r<rTheaderrRvaluer>r>r?rs  zPreparedRequest.prepare_headersc Csd}d}|sn|dk rnd}ztj|dd}Wn.tk rX}zt||dW5d}~XYnXt|tsn|d}tt|dt|t t t t f g}|r6z t |}Wntttfk rd}YnX|}t|dddk rz||_Wntk rt|_YnX|rtd |r*t||jd <n d |jd <np|rN|||\}}n2|r||}t|t svt|d r|d}nd}|||rd|jkr||jd<||_dS)z"Prepares the given HTTP body data.Nzapplication/jsonF) allow_nan)requestrCrBtellz1Streamed bodies and files are mutually exclusive.Content-LengthchunkedzTransfer-EncodingrAz!application/x-www-form-urlencodedz content-typez Content-Type) complexjsondumpsrVr!rErGrIallrHrrYrXrr0 TypeErrorAttributeErrorrgetattrrrOSErrorobjectNotImplementedErrorrrTrirOprepare_content_lengthrh) r<rJr]rrhrUve is_streamlengthr>r>r?rsX         zPreparedRequest.prepare_bodycCsL|dk r$t|}|rHt||jd<n$|jdkrH|jddkrHd|jd<dS)z>Prepare Content-Length header based on request method and bodyNr)GETHEAD0)r0rrTrget)r<rhrr>r>r?r<sz&PreparedRequest.prepare_content_lengthr6cCsj|dkr"t|j}t|r|nd}|rft|trDt|dkrDt|}||}|j|j| |j dS)z"Prepares the given HTTP auth data.NrP) r)r7anyrErXrZr__dict__updaterrh)r<rr7url_authrr>r>r?rLs zPreparedRequest.prepare_authcCs@t|tjr||_n t||_t|j|}|dk r<||jd<dS)aPrepares the given HTTP cookie data. This function eventually generates a ``Cookie`` header from the given cookies using cookielib. Due to cookielib's design, the header will not be regenerated if it already exists, meaning this function can only be called once for the life of the :class:`PreparedRequest ` object. Any subsequent calls to ``prepare_cookies`` will have no actual effect, unless the "Cookie" header is removed beforehand. NCookie)rEr CookieJarrrrrT)r<r cookie_headerr>r>r?rbs   zPreparedRequest.prepare_cookiescCs&|pg}|D]}||||q dS)zPrepares the given hooks.N)rz)r<rurxr>r>r?rvszPreparedRequest.prepare_hooks) NNNNNNNNNN)N)r6)rjrkrlrrrrrrrnrrrrrrrrr>r>r>r?r9s2   J N rc @seZdZdZdddddddd d d g Zd d ZddZddZddZddZ ddZ ddZ ddZ ddZ eddZed d!Zed"d#Zed$d%Zed&d'Zd;d*d+Zed)d,fd-d.Zed/d0Zed1d2Zd3d4Zed5d6Zd7d8Zd9d:Zd,S)<ResponsezhThe :class:`Response ` object, which contains a server's response to an HTTP request. _content status_coderTr7historyencodingreasonrelapsedrcCs^d|_d|_d|_d|_t|_d|_d|_d|_g|_ d|_ t i|_ t d|_d|_dS)NFr)r_content_consumed_nextrr'rTrawr7rrrrrdatetime timedeltarrrr>r>r?rs  zResponse.__init__cCs|Srqr>rr>r>r? __enter__szResponse.__enter__cGs |dSrq)close)r<rr>r>r?__exit__szResponse.__exit__cs js jfddjDS)Ncsi|]}|t|dqSrq)r)rrattrrr>r? sz)Response.__getstate__..)rcontent __attrs__rr>rr? __getstate__szResponse.__getstate__cCs:|D]\}}t|||qt|ddt|dddS)NrTr)r~setattr)r<staterRrr>r>r? __setstate__s zResponse.__setstate__cCsd|jdS)Nz r>r?rszResponse.__repr__cCs|jSakReturns True if :attr:`status_code` is less than 400. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. okrr>r>r?__bool__szResponse.__bool__cCs|jSrrrr>r>r? __nonzero__szResponse.__nonzero__cCs |dS)z,Allows you to use a response as an iterator.) iter_contentrr>r>r?rBszResponse.__iter__cCs(z |Wntk r"YdSXdS)axReturns True if :attr:`status_code` is less than 400, False if not. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. FT)raise_for_statusr rr>r>r?rs  z Response.okcCsd|jko|jtkS)zTrue if this Response is a well-formed HTTP redirect that could have been processed automatically (by :meth:`Session.resolve_redirects`). location)rTrREDIRECT_STATIrr>r>r? is_redirectszResponse.is_redirectcCsd|jko|jtjtjfkS)z@True if this Response one of the permanent versions of redirect.r)rTrr&moved_permanentlypermanent_redirectrr>r>r?is_permanent_redirectszResponse.is_permanent_redirectcCs|jS)zTReturns a PreparedRequest for the next request in a redirect chain, if there is one.)rrr>r>r?nextsz Response.nextcCs tdk rt|jdSdSdS)zOThe apparent encoding, provided by the charset_normalizer or chardet libraries.NrrC)rdetectrrr>r>r?apparent_encodingszResponse.apparent_encodingr Fcsfdd}jr(tjtr(tn&dk rNttsNtdtdtj}|}jrj|n|}|r|t |}|S)aIterates 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. chunk_size must be of type int or None. A value of None will function differently depending on the value of `stream`. stream=True will read data as it arrives in whatever size the chunks are received. If stream=False, data is returned as a single chunk. If decode_unicode is True, content will be decoded using the best available encoding based on the response. c 3stjdrzjjddEdHWqtk rP}z t|W5d}~XYqtk rx}z t|W5d}~XYqtk r}z t|W5d}~XYqt k r}z t |W5d}~XYqXnj }|sq|Vqd_ dS)NstreamT)decode_content) rHrrrrrrrrrRequestsSSLErrorrAr)rchunk chunk_sizer<r>r?generate0s   z'Response.iter_content..generateNz+chunk_size must be an int, it is instead a r) rrErboolr$intrtyper,r/)r<rdecode_unicoder reused_chunks stream_chunkschunksr>rr?rs  zResponse.iter_contentNccsd}|j||dD]h}|dk r&||}|r6||}n|}|rl|drl|rl|dd|dkrl|}nd}|EdHq|dk r|VdS)zIterates 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. .. note:: This method is not reentrant safe. N)rr)rsplit splitlinespop)r<rr delimiterpendingrlinesr>r>r? iter_linesYs   $  zResponse.iter_linescCsV|jdkrJ|jrtd|jdks,|jdkr4d|_nd|tpFd|_d|_|jS)z"Content of the response, in bytes.Fz2The content for this response was already consumedrNT)rr RuntimeErrorrrr;rCONTENT_CHUNK_SIZErr>r>r?rzs zResponse.contentc Csdd}|j}|jsdS|jdkr$|j}zt|j|dd}Wn&ttfk r^t|jdd}YnX|S)aContent of the response, in unicode. If Response.encoding is None, encoding will be guessed using ``charset_normalizer`` or ``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. Nr6replace)errors)rrrrF LookupErrorr)r<rrr>r>r?texts z Response.textc Ks|js|jrt|jdkrt|j}|dk rztj|j|f|WStk rXYn4tk r}zt |j |j |j W5d}~XYnXztj|j f|WStk r}zt |j |j |j W5d}~XYnXdS)zReturns the json-encoded content of a response, if any. :param \*\*kwargs: Optional arguments that ``json.loads`` takes. :raises requests.exceptions.JSONDecodeError: If the response body does not contain valid json. rQN)rrrZr+rloadsrWUnicodeDecodeErrorrRequestsJSONDecodeErrormsgdocposr)r<kwargsrrr>r>r?rs $z Response.jsoncCsF|jd}i}|rBt|}|D] }|dp6|d}|||<q |S)z8Returns the parsed header links of the response, if any.linkrelr7)rTrr-)r<rresolved_linkslinksrkeyr>r>r?rs  zResponse.linkscCsd}t|jtrDz|jd}WqJtk r@|jd}YqJXn|j}d|jkr`dkr~nn|jd|d|j}n2d|jkrdkrnn|jd |d|j}|rt||d d S) z+Raises :class:`HTTPError`, if one occurred.r6rCz iso-8859-1iiz Client Error: z for url: iXz Server Error: )responseN)rErrGrWrrr7r )r<http_error_msgrr>r>r?rs zResponse.raise_for_statuscCs0|js|jt|jdd}|dk r,|dS)zReleases 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.* release_connN)rrrr)r<r"r>r>r?rs  zResponse.close)r F)rjrkrlrrrrrrrrrrrBrmrrrrrrITER_CHUNK_SIZEr rrrrrrr>r>r>r?rsZ /       ; !  %! r)Rrrencodings.idna encodingsiorZpip._vendor.urllib3.exceptionsrrrrrZpip._vendor.urllib3.fieldsrZpip._vendor.urllib3.filepostr pip._vendor.urllib3.utilr _internal_utilsr r rrcompatrrrrrrrrrrrrrrrr exceptionsrrrr r!r"rr#rr$rur% status_codesr& structuresr'utilsr(r)r*r+r,r-r.r/r0r1movedfoundothertemporary_redirectrrDEFAULT_REDIRECT_LIMITrr#r3ror}rrr>r>r>r?sL     $         0zSI