a „oe—‰ã@sìdZddlZddlZddlmZddlmZmZm 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@mAZAmBZBmCZCe6jDe6jEe6jFe6jGe6jHfZIdZJdZKdZLGdd„dƒZMGdd„dƒZNGdd „d eNƒZOGd!d"„d"eMeNƒZPGd#d$„d$ƒZQdS)%z` requests.models ~~~~~~~~~~~~~~~ This module contains the primary objects that power Requests. éN)ÚUnsupportedOperation)Ú DecodeErrorÚLocationParseErrorÚ ProtocolErrorÚReadTimeoutErrorÚSSLError)Ú RequestField)Úencode_multipart_formdata)Ú parse_urlé)Úto_native_stringÚunicode_is_ascii)Ú HTTPBasicAuth)ÚCallableÚJSONDecodeErrorÚMappingÚ basestringÚ builtin_strÚchardetÚ cookielib)Újson)Ú urlencodeÚurlsplitÚ urlunparse)Ú_copy_cookie_jarÚcookiejar_from_dictÚget_cookie_header)ÚChunkedEncodingErrorÚConnectionErrorÚContentDecodingErrorÚ HTTPErrorÚInvalidJSONErrorÚ InvalidURL)r)Ú MissingSchema)r)ÚStreamConsumedError)Ú default_hooks)Úcodes)ÚCaseInsensitiveDict) Úcheck_header_validityÚget_auth_from_urlÚguess_filenameÚguess_json_utfÚ iter_slicesÚparse_header_linksÚ requote_uriÚstream_decode_response_unicodeÚ super_lenÚto_key_val_listéi(ic@s0eZdZedd„ƒZedd„ƒZedd„ƒZdS)ÚRequestEncodingMixincCsNg}t|jƒ}|j}|sd}| |¡|j}|rD| d¡| |¡d |¡S)zBuild the path URL to use.ú/ú?Ú)rÚurlÚpathÚappendÚqueryÚjoin)Úselfr7Úpr8r:©r>ú0C:\Program Files\Certbot\pkgs\requests\models.pyÚpath_urlUs    zRequestEncodingMixin.path_urlcCs¶t|ttfƒr|St|dƒr |St|dƒr®g}t|ƒD]j\}}t|tƒsRt|dƒsX|g}|D]B}|dur\| t|tƒr€| d¡n|t|tƒr–| d¡n|f¡q\q6t|dd�S|SdS)züEncode 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__Núutf-8T)Údoseq) Ú isinstanceÚstrÚbytesÚhasattrr1rr9Úencoder)ÚdataÚresultÚkZvsÚvr>r>r?Ú_encode_paramsjs$   þÿ z#RequestEncodingMixin._encode_paramscCs®|stdƒ‚nt|tƒr tdƒ‚g}t|p,iƒ}t|p8iƒ}|D]|\}}t|tƒs\t|dƒsb|g}|D]T}|durft|tƒs„t|ƒ}| t|tƒrœ| d¡n|t|tƒr²|  d¡n|f¡qfq@|D]Ö\}}d}d} t|t t fƒ�r t |ƒdkrø|\} } n&t |ƒdk�r|\} } }n |\} } }} nt |ƒ�p,|} |} t| tttfƒ�rJ| } n(t| dƒ�r`|  ¡} n| du�rnqÂn| } t|| | | d �} | j|d �| | ¡qÂt|ƒ\}}||fS) a¥Build 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.rBNrCéérA)ÚnamerJÚfilenameÚheaders)Ú content_type)Ú ValueErrorrErr1rHrGrFr9ÚdecoderIÚtupleÚlistÚlenr*Ú bytearrayrArZmake_multipartr )ÚfilesrJZ new_fieldsÚfieldsZfieldÚvalrMrLZftZfhÚfnÚfpZfdataZrfÚbodyrTr>r>r?Ú _encode_filesˆsX       ÿ üÿ          z"RequestEncodingMixin._encode_filesN)Ú__name__Ú __module__Ú __qualname__Úpropertyr@Ú staticmethodrNrar>r>r>r?r3Ts   r3c@seZdZdd„Zdd„ZdS)ÚRequestHooksMixincCs^||jvrtd|›d�ƒ‚t|tƒr6|j| |¡n$t|dƒrZ|j| dd„|Dƒ¡dS)zProperly register a hook.z.Unsupported event specified, with event name "ú"rBcss|]}t|tƒr|VqdS©N)rEr)Ú.0Úhr>r>r?Ú Øóz2RequestHooksMixin.register_hook..N)ÚhooksrUrErr9rHÚextend©r<ÚeventÚhookr>r>r?Ú register_hookÏs    zRequestHooksMixin.register_hookcCs0z|j| |¡WdSty*YdS0dS)ziDeregister a previously registered hook. Returns True if the hook existed, False if not. TFN)rnÚremoverUrpr>r>r?Úderegister_hookÚs  z!RequestHooksMixin.deregister_hookN)rbrcrdrsrur>r>r>r?rgÎs rgc @s*eZdZdZd dd„Zdd„Zdd„ZdS) Ú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¶|dur gn|}|durgn|}|dur,in|}|durr>r?Ú__init__s"zRequest.__init__cCsd|j›d�S)Nz ©rx©r<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.) rxr7rSr[rJrryrzr{rn) ÚPreparedRequestÚpreparerxr7rSr[rJrryrzr{rn©r<r=r>r>r?r‚(sö zRequest.prepare) NNNNNNNNNN)rbrcrdÚ__doc__r|r€r‚r>r>r>r?rvæsõ #rvc @s‚eZdZdZdd„Zddd„Zdd„Zd d „Zd d „Ze d d„ƒZ dd„Z dd„Z ddd„Z dd„Zd dd„Zdd„Zdd„ZdS)!r�a)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|_dSri)rxr7rSÚ_cookiesr`r%rnÚ_body_positionrr>r>r?r|OszPreparedRequest.__init__Nc CsR| |¡| ||¡| |¡| |¡| ||| ¡| ||¡| | ¡dS)z6Prepares the entire request with the given parameters.N)Úprepare_methodÚ prepare_urlÚprepare_headersÚprepare_cookiesÚ prepare_bodyÚ prepare_authÚ prepare_hooks) r<rxr7rSr[rJryrzr{rnrr>r>r?r‚`s     zPreparedRequest.preparecCsd|j›d�S)Nzr>r?r€|szPreparedRequest.__repr__cCsXtƒ}|j|_|j|_|jdur*|j ¡nd|_t|jƒ|_|j|_|j|_|j |_ |Sri) r�rxr7rSÚcopyrr…r`rnr†rƒr>r>r?rŽs zPreparedRequest.copycCs$||_|jdur t|j ¡ƒ|_dS)zPrepares the given HTTP method.N)rxr Úupper)r<rxr>r>r?r‡Šs zPreparedRequest.prepare_methodcCs>ddl}z|j|dd� d¡}Wn|jy8t‚Yn0|S)NrT)Zuts46rC)ÚidnarIrVZ IDNAErrorÚ UnicodeError)Úhostr�r>r>r?Ú_get_idna_encoded_host�s  z&PreparedRequest._get_idna_encoded_hostc Cs¨t|tƒr| d¡}nt|ƒ}| ¡}d|vrF| ¡ d¡sF||_dSzt|ƒ\}}}}}}} Wn.t yŽ} zt | j Ž‚WYd} ~ n d} ~ 00|sªt d|›d|›d�ƒ‚|s¾t d|›d�ƒ‚t |ƒsòz| |¡}Wntyît d ƒ‚Yn0n| d ¡�rt d ƒ‚|�pd } | �r| d 7} | |7} |�r:| d|›�7} |�sDd }t|ttfƒ�r\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ú&)rErGrVrFÚlstripÚlowerÚ startswithr7r rr"Úargsr#r r“r‘r rNr.r) r<r7ryÚschemerzr’Úportr8r:ÚfragmentÚeÚnetlocZ enc_paramsr>r>r?rˆšsV   ÿÿ    zPreparedRequest.prepare_urlcCs<tƒ|_|r8| ¡D]"}t|ƒ|\}}||jt|ƒ<qdS)z Prepares the given HTTP headers.N)r'rSrwr(r )r<rSÚheaderrQÚvaluer>r>r?r‰äs  zPreparedRequest.prepare_headersc Cs®d}d}|sp|durpd}ztj|dd�}Wn0tyZ}zt||d�‚WYd}~n d}~00t|tƒsp| d¡}tt|dƒt|t t t t fƒ gƒ}|�r4z t |ƒ}WntttfyÀd}Yn0|}t|ddƒdu�rz| ¡|_Wnt�ytƒ|_Yn0|�rtd ƒ‚|�r(t|ƒ|jd <n d |jd <np|�rL| ||¡\}}n2|�r~| |¡}t|t ƒ�stt|d ƒ�rzd}nd}| |¡|�r¤d|jv�r¤||jd<||_dS)z"Prepares the given HTTP body data.Nzapplication/jsonF)Z allow_nan)ÚrequestrCrBÚtellz1Streamed bodies and files are mutually exclusive.úContent-LengthZchunkedzTransfer-EncodingrAz!application/x-www-form-urlencodedz content-typez Content-Type)Ú complexjsonÚdumpsrUr!rErGrIÚallrHrrXrWrr0Ú TypeErrorÚAttributeErrorrÚgetattrr§r†ÚOSErrorÚobjectÚNotImplementedErrorrrSrarNÚprepare_content_lengthr`) r<rJr[rr`rTÚveZ is_streamÚlengthr>r>r?r‹ïsX "  þÿ  ÿ    zPreparedRequest.prepare_bodycCsL|dur$t|ƒ}|rHt|ƒ|jd<n$|jdvrH|j d¡durHd|jd<dS)z>Prepare Content-Length header based on request method and bodyNr¨)ZGETZHEADÚ0)r0rrSrxÚget)r<r`r´r>r>r?r²=sÿþz&PreparedRequest.prepare_content_lengthr6cCsj|dur"t|jƒ}t|ƒr|nd}|rft|tƒrDt|ƒdkrDt|Ž}||ƒ}|j |j¡|  |j ¡dS)z"Prepares the given HTTP auth data.NrO) r)r7ÚanyrErWrYrÚ__dict__Úupdater²r`)r<rzr7Zurl_authÚrr>r>r?rŒMs zPreparedRequest.prepare_authcCs@t|tjƒr||_n t|ƒ|_t|j|ƒ}|dur<||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. NZCookie)rErZ CookieJarr…rrrS)r<r{Z cookie_headerr>r>r?rŠcs   zPreparedRequest.prepare_cookiescCs&|pg}|D]}| |||¡q dS)zPrepares the given hooks.N)rs)r<rnrqr>r>r?r�wszPreparedRequest.prepare_hooks) NNNNNNNNNN)N)r6)rbrcrdr„r|r‚r€rŽr‡rfr“rˆr‰r‹r²rŒrŠr�r>r>r>r?r�:s2õ   J N r�c@sòeZdZdZgd¢Zdd„Zdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z edd„ƒZedd„ƒZedd„ƒZedd„ƒZedd„ƒZd2d!d"„Zed d#fd$d%„Zed&d'„ƒZed(d)„ƒZd*d+„Zed,d-„ƒZd.d/„Zd0d1„Zd#S)3ÚResponsezhThe :class:`Response ` object, which contains a server's response to an HTTP request. ) Ú_contentÚ status_coderSr7ÚhistoryÚencodingÚreasonr{Úelapsedr¦cCs^d|_d|_d|_d|_tƒ|_d|_d|_d|_g|_ d|_ t iƒ|_ t  d¡|_d|_dS)NFr)r¼Ú_content_consumedÚ_nextr½r'rSÚrawr7r¿r¾rÀrr{ÚdatetimeZ timedeltarÁr¦rr>r>r?r|“s  zResponse.__init__cCs|Srir>rr>r>r?Ú __enter__ÂszResponse.__enter__cGs | ¡dSri)Úclose)r<ržr>r>r?Ú__exit__ÅszResponse.__exit__cs ˆjs ˆj‡fdd„ˆjDƒS)Ncsi|]}|tˆ|dƒ“qSri)r®)rjÚattrrr>r?Ú Îrmz)Response.__getstate__..)rÂÚcontentÚ __attrs__rr>rr?Ú __getstate__ÈszResponse.__getstate__cCs:| ¡D]\}}t|||ƒqt|ddƒt|ddƒdS)NrÂTrÄ)rwÚsetattr)r<ÚstaterQr¥r>r>r?Ú __setstate__Ðs zResponse.__setstate__cCsd|j›d�S)Nz r>r?r€ØszResponse.__repr__cCs|jS©akReturns 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|jSrÑrÒrr>r>r?Ú __nonzero__åszResponse.__nonzero__cCs | d¡S)z,Allows you to use a response as an iterator.é€)Ú iter_contentrr>r>r?rBïszResponse.__iter__cCs&z | ¡Wnty YdS0dS)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?rÓós   z Response.okcCsd|jvo|jtvS)zšTrue if this Response is a well-formed HTTP redirect that could have been processed automatically (by :meth:`Session.resolve_redirects`). Úlocation)rSr½ÚREDIRECT_STATIrr>r>r?Ú is_redirectszResponse.is_redirectcCsd|jvo|jtjtjfvS)z@True if this Response one of the permanent versions of redirect.rÙ)rSr½r&Zmoved_permanentlyÚpermanent_redirectrr>r>r?Úis_permanent_redirect sþzResponse.is_permanent_redirectcCs|jS)zTReturns a PreparedRequest for the next request in a redirect chain, if there is one.)rÃrr>r>r?Únextsz Response.nextcCst |j¡dS)zOThe apparent encoding, provided by the charset_normalizer or chardet libraries.r¿)rZdetectrËrr>r>r?Úapparent_encodingszResponse.apparent_encodingr Fcs€‡‡fdd„}ˆjr(tˆjtƒr(tƒ‚n&ˆdurNtˆtƒsNtdtˆƒ›d�ƒ‚tˆjˆƒ}|ƒ}ˆjrj|n|}|r|t |ˆƒ}|S)aøIterates 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 3søtˆjdƒrÔzˆjjˆdd�EdHWqîtyR}zt|ƒ‚WYd}~qîd}~0ty|}zt|ƒ‚WYd}~qîd}~0ty¦}zt|ƒ‚WYd}~qîd}~0t yÐ}zt |ƒ‚WYd}~qîd}~00nˆj  ˆ¡}|sæqî|VqÔdˆ_ dS)NÚstreamT)Zdecode_content) rHrÄràrrrrrrrÚRequestsSSLErrorrArÂ)r¢Úchunk©Ú chunk_sizer<r>r?Úgenerate,s    z'Response.iter_content..generateNz+chunk_size must be an int, it is instead a r˜) rÂrEr¼Úboolr$Úintr¬Útyper,r/)r<räÚdecode_unicoderåZ reused_chunksZ stream_chunksÚchunksr>rãr?r×sÿ  zResponse.iter_contentNccsŽd}|j||d�D]h}|dur&||}|r6| |¡}n| ¡}|rl|drl|rl|dd|dkrl| ¡}nd}|EdHq|durŠ|VdS)zõIterates 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)rärééÿÿÿÿ)r×ÚsplitÚ splitlinesÚpop)r<räréZ delimiterÚpendingrâÚlinesr>r>r?Ú iter_linesUs ÿ  $  zResponse.iter_linescCsV|jdurJ|jrtdƒ‚|jdks,|jdur4d|_nd | t¡¡pFd|_d|_|jS)z"Content of the response, in bytes.Fz2The content for this response was already consumedrNrmT)r¼rÂÚ RuntimeErrorr½rÄr;r×ÚCONTENT_CHUNK_SIZErr>r>r?rËws zResponse.contentc Csbd}|j}|jsdS|jdur$|j}zt|j|dd�}Wn$ttfy\t|jdd�}Yn0|S)aÚContent 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. Nr6Úreplace)Úerrors)r¿rËrßrFÚ LookupErrorr¬)r<rËr¿r>r>r?ÚtextŠs z Response.textc Ksâ|js�|jr�t|jƒdkr�t|jƒ}|dur�ztj|j |¡fi|¤ŽWStyZYn6tyŽ}zt |j |j |j ƒ‚WYd}~n d}~00ztj|j fi|¤ŽWStyÜ}zt |j |j |j ƒ‚WYd}~n d}~00dS)zýReturns 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. rPN)r¿rËrYr+r©ÚloadsrVÚUnicodeDecodeErrorrÚRequestsJSONDecodeErrorÚmsgÚdocÚposr÷)r<Úkwargsr¿r¢r>r>r?r°s  (z Response.jsoncCsF|j d¡}i}|rBt|ƒ}|D] }| d¡p6| d¡}|||<q |S)z8Returns the parsed header links of the response, if any.ÚlinkÚrelr7)rSr¶r-)r<r¤Zresolved_linksÚlinksrÿÚkeyr>r>r?rÑs  zResponse.linkscCsÂd}t|jtƒrBz|j d¡}WqHty>|j d¡}YqH0n|j}d|jkr^dkr|nn|j›d|›d|j›�}n2d|jkr’dkr®nn|j›d |›d|j›�}|r¾t||d �‚d S) z+Raises :class:`HTTPError`, if one occurred.r6rCz iso-8859-1i�iôz Client Error: z for url: iXz Server Error: )ZresponseN)rErÀrGrVrùr½r7r )r<Zhttp_error_msgrÀr>r>r?rØâs  ÿÿzResponse.raise_for_statuscCs0|js|j ¡t|jddƒ}|dur,|ƒdS)zØReleases 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)rÂrÄrÇr®)r<rr>r>r?rÇÿs  zResponse.close)r F)rbrcrdr„rÌr|rÆrÈrÍrÐr€rÔrÕrBrerÓrÛrÝrÞrßr×ÚITER_CHUNK_SIZErñrËr÷rrrØrÇr>r>r>r?r»�sB /        ;ÿ "  %! r»)Rr„rÅZencodings.idnaÚ encodingsÚiorZurllib3.exceptionsrrrrrZurllib3.fieldsrZurllib3.filepostr Z urllib3.utilr Z_internal_utilsr r rzrÚcompatrrrrrrrrr©rrrr{rrrÚ exceptionsrrrr r!r"rúr#rár$rnr%Z status_codesr&Z structuresr'Zutilsr(r)r*r+r,r-r.r/r0r1ZmovedÚfoundÚotherZtemporary_redirectrÜrÚZDEFAULT_REDIRECT_LIMITrórr3rgrvr�r»r>r>r>r?ÚsL     $         0ûzTI