fZddZddlZddlZddlmZddlmZmZm 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@mAZAmBZBmCZCe6je6je6je6je6jfZIdZJdZKdZLGddZMGddZNGdd eNZOGd!d"eMeNZPGd#d$ZQy)%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<eZdZedZedZedZy)RequestEncodingMixincg}t|j}|j}|sd}|j||j}|r"|jd|j|dj |S)zBuild the path URL to use./?)rurlpathappendqueryjoin)selfr:pr;r=s X/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/requests/models.pypath_urlzRequestEncodingMixin.path_urlUse TXX vvD 4  JJsO JJu wws|c t|ttfr|St|dr|St|drg}t |D]\}}t|t s t|ds|g}|D]Z}||j t|tr|jdn|t|tr|jdn|f\t|dS|S)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__utf-8T)doseq) isinstancestrbyteshasattrr2rr<encoder)dataresultkvsvs rA_encode_paramsz#RequestEncodingMixin._encode_paramsjs dS%L )K T6 "K T: &F(.2b*-WR5LBA} 5?35G 1Q5?35G 1Q/V40 0KrCc |s tdt|tr tdg}t|xsi}t|xsi}|D]\}}t|ts t |ds|g}|D]u}|t|t s t |}|jt|t r|jdn|t|t r|jdn|fw|D]\}}d}d} t|ttfr1t|dk(r|\} } n.t|dk(r|\} } }n|\} } }} nt|xs|} |} t| t t tfr| } n"t | dr| j} n| | } t!|| | | } | j#| |j| t%|\}}||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.rFNrGrE)namerNfilenameheaders) content_type) ValueErrorrIrr2rLrKrJr<decoderMtuplelistlenr+ bytearrayrEr make_multipartr )filesrN new_fieldsfieldsfieldvalrRrPftfhfnfpfdatarfbodyrZs rA _encode_filesz"RequestEncodingMixin._encode_filess67 7 j )9: :  , , JE3#z*'#z2Je=%a/F%% *%7"LL1!&1;As1CAHHW-  !$DAqBB!eT]+q6Q;FBVq[!"JBB%&NBB#A&+!"sE956V$ 152rJB   2  .   b !587zBl\!!rCN)__name__ __module__ __qualname__propertyrB staticmethodrSrnrCrAr5r5Ts> (:B"B"rCr5ceZdZdZdZy)RequestHooksMixinc||jvrtd|dt|tr|j|j |yt |dr&|j|j d|Dyy)zProperly register a hook.z.Unsupported event specified, with event name ""rFc3BK|]}t|ts|ywN)rIr).0hs rA z2RequestHooksMixin.register_hook..s$P1 1h8OQ$PsN)hooksr[rIrr<rLextendr?eventhooks rA register_hookzRequestHooksMixin.register_hookss  "MeWTUVW W dH % JJu  $ $T * T: & JJu  $ $$P$P P'rCc` |j|j|y#t$rYywxYw)ziDeregister a previously registered hook. Returns True if the hook existed, False if not. TF)r~remover[rs rAderegister_hookz!RequestHooksMixin.deregister_hooks3   JJu  $ $T *  s ! --N)rorprqrrrtrCrArvrvs  Q rCrvc8eZdZdZ ddZdZdZy)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 D|gn|}|gn|}|in|}|in|}| in| } t|_t| jD]\} } |j | | ||_||_||_||_||_ | |_ ||_ ||_ ||_ y)N)rr)r&r~r^itemsrmethodr:rYrbrNrparamsauthcookies) r?rr:rYrbrNrrrr~rrPrRs rA__init__zRequest.__init__s\rtm"W~6m"_ 'DAq   QQ  /(        rCc"d|jdS)Nz rr?s rA__repr__zRequest.__repr__$sDKK=++rCc t}|j|j|j|j|j |j |j|j|j|j|j |S)zXConstructs a :class:`PreparedRequest ` for transmission and returns it.) rr:rYrbrNrrrrr~) PreparedRequestpreparerr:rYrbrNrrrrr~r?r@s rArzRequest.prepare'sh   ;;LL**;;LL**  rC NNNNNNNNNN)rorprq__doc__rrrrtrCrArrs7:     D,rCrceZdZdZdZ ddZdZdZdZe dZ d Z d Z dd Z d Zdd ZdZdZy)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) cvd|_d|_d|_d|_d|_t |_d|_yrz)rr:rY_cookiesrmr&r~_body_positionrs rArzPreparedRequest.__init__Ns8    "_ "rCNc |j||j|||j||j||j ||| |j |||j | y)z6Prepares the entire request with the given parameters.N)prepare_method prepare_urlprepare_headersprepare_cookies prepare_body prepare_auth prepare_hooks) r?rr:rYrbrNrrrr~rs rArzPreparedRequest.prepare_sp F# f% W% W% $t, $$ 5!rCc"d|jdS)Nz?DK #rCcddl} |j|djd}|S#|j$rtwxYw)NrT)uts46rG)idnarMr\ IDNAError UnicodeError)hostrs rA_get_idna_encoded_hostz&PreparedRequest._get_idna_encoded_hostsI ;;t4;077@D ~~   s "*Ac 2t|tr|jd}n t|}|j }d|vr'|j j ds||_y t|\}}}}}}} |std|d|d|std|dt|s |j|}n|j d r td |xsd } | r| d z } | |z } |r| d|z } |sd }t|ttfr t!|}|j#|} | r |r|d| }n| }t%t'|| |d|| g}||_y#t$r} t| jd} ~ wwxYw#t$r td wxYw)zPrepares the given HTTP URL.utf8:httpNz Invalid URL z0: No scheme supplied. Perhaps you meant https://r8z: No host suppliedzURL has an invalid label.)*.r9@r7&)rIrKr\rJlstriplower startswithr:r rr#argsr$rrrr rSr/r) r?r:rschemerrportr;r=fragmentenetloc enc_paramss rArzPreparedRequest.prepare_urls c5 !**V$Cc(Cjjl #:ciik44V<DH  &>Gn ;FD$dE8sg&--0E4  |C72DEF F  % >2248__Z (89 9  cMF$  $j FD fsEl +%f-F((0  ':,/"*ffdD%%RST_" &aff% % &&  > !<== >s$*E.F E>'E99E>Fct|_|r>|jD]*}t||\}}||jt |<,yy)z Prepares the given HTTP headers.N)r(rYrr)r )r?rYheaderrWvalues rArzPreparedRequest.prepare_headerssK+, !--/%f-$ e7< -d34 * rCc d}d}|s=|;d} tj|d}t |t s|j d}tt|dt |ttttf g}|rw t|}|}t#|dd |j%|_|r t-d |r t/||j0d <||_yd |j0d <||_y|r|j3||\}}n4|r2|j5|}t |ts t|d rd}nd}|j7||rd|j0vr||j0d<||_y#t$r}t||d}~wwxYw#ttt f$rd}Y&wxYw#t($rt+|_Y wxYw)z"Prepares the given HTTP body data.Nzapplication/jsonF) allow_nan)requestrGrFtellz1Streamed bodies and files are mutually exclusive.Content-LengthchunkedzTransfer-EncodingrEz!application/x-www-form-urlencodedz content-typez Content-Type) complexjsondumpsr[r"rIrKrMallrLrr^r]rr1 TypeErrorAttributeErrorrgetattrrrOSErrorobjectNotImplementedErrorrrYrnrSprepare_content_lengthrm) r?rNrbrrmrZve is_streamlengths rArzPreparedRequest.prepare_bodys (.L 9"((?dE*{{7+j)tj$w%GHH    "4DtVT*63*.))+D' )G1 01& !'+'9'9%'F$|..t4D!$ 3wtV7L'+ 'J  ' ' -t||!C/; ^, w 9&r488 9 ~/CD  3+1(D'3s;E7= FF27 F F  FF/.F/2G Gc|'t|}|rt||jd<yy|jdvr,|jj dd|jd<yyy)z>Prepare Content-Length header based on request method and bodyNr)GETHEAD0)r1rrYrget)r?rmrs rArz&PreparedRequest.prepare_content_length<sn  t_F2=V1D -. KK .   !12:.1DLL) * ; /rCc2|$t|j}t|r|nd}|rot|trt |dk(rt |}||}|jj|j|j|jyy)z"Prepares the given HTTP auth data.NrU) r*r:anyrIr]r_r__dict__updaterrm)r?rr:url_authrs rArzPreparedRequest.prepare_authLs <(2H"8}8$D $&3t9>$d+T A MM  ,  ' ' 2 rCct|tjr||_nt ||_t |j|}|||j d<yy)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)rIr CookieJarrrrrY)r?r cookie_headers rArzPreparedRequest.prepare_cookiesbsP gy22 3#DM/8DM)$-->  $%2DLL " %rCcH|xsg}|D]}|j|||y)zPrepares the given hooks.N)r)r?r~rs rArzPreparedRequest.prepare_hooksvs+  E   ueEl 3rCrrz)r9)rorprqrrrrrrrsrrrrrrrrrtrCrArr9s|(#&    "84 @ HT =L\1 3,3(4rCrceZdZdZgdZdZdZdZdZdZ dZ d Z d Z d Z ed Zed ZedZedZedZddZeddfdZedZedZdZedZdZdZy)ResponsezhThe :class:`Response ` object, which contains a server's response to an HTTP request. ) _content status_coderYr:historyencodingreasonrelapsedrcd|_d|_d|_d|_t |_d|_d|_d|_g|_ d|_ ti|_ tjd|_d|_y)NFr)r_content_consumed_nextrr(rYrawr:rrrrrdatetime timedeltarrrs rArzResponse.__init__s !&   +,    +2.  ))!,  rCc|Srzrtrs rA __enter__zResponse.__enter__s rCc$|jyrz)close)r?rs rA__exit__zResponse.__exit__s  rCc |js |j|jDcic]}|t||dc}Scc}wrz)rcontent __attrs__r)r?attrs rA __getstate__zResponse.__getstate__s:%% LL<@NNKDgdD$//KKKs?c|jD]\}}t|||t|ddt|ddy)NrTr)rsetattr)r?staterWrs rA __setstate__zResponse.__setstate__s= ;;=KD% D$ &) )40eT"rCc"d|jdS)Nz .>..PPrCczd|jvxr,|jtjtjfvS)z@True if this Response one of the permanent versions of redirect.r)rYrr'moved_permanentlypermanent_redirectrs rAis_permanent_redirectzResponse.is_permanent_redirects?T\\) d.>.>  # #  $ $C /  rCc|jS)zTReturns a PreparedRequest for the next request in a redirect chain, if there is one.)rrs rAnextz Response.nextszzrCcTt"tj|jdSy)zOThe apparent encoding, provided by the charset_normalizer or chardet libraries.rrG)rdetectrrs rAapparent_encodingzResponse.apparent_encodings'  >>$,,/ ; ;rCFc@fd}jr$tjtr t (tt st dtdtj}|}jr|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. c3Ktjdr. jjdEd{d_ y jj}|s d_ y|+78#t$r}t |d}~wt $r}t |d}~wt$r}t|d}~wt$r}t|d}~wwxYww)NstreamT)decode_content) rLrr$rrrr rrrRequestsSSLErrorrEr)rchunk chunk_sizer?s rAgeneratez'Response.iter_content..generate0stxx* .#xxz$OOO"&*D "  HHMM*5E &*D " K P$2.q11"2.q11'-)!,,.*1--.s\C A6A4A64C4A66 C? B  C B!! C- B88 C CCCz+chunk_size must be an int, it is instead a r) rrIrboolr%intrtyper-r0)r?r(decode_unicoder) reused_chunks stream_chunkschunkss`` rArzResponse.iter_contents" *.  ! !j&E%' '  #Jz3,G=d:>N=OqQ $DMM:>  "&"8"8m 3FDAF rCNc#Kd}|j||D]a}|||z}|r|j|}n|j}|r&|dr!|r|dd|dk(r|j}nd}|Ed{c||yy7w)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)r(r-)rsplit splitlinespop)r?r(r- delimiterpendingr'liness rA iter_lineszResponse.iter_linesYs&&!.' E"% I.((*rur2%)1K))+  ! $  M  sA3B5B6Bc|jdurg|jr td|jdk(s |jd|_n-dj |j txsd|_d|_|jS)z"Content of the response, in bytes.Fz2The content for this response was already consumedrNrCT)rr RuntimeErrorrrr>rCONTENT_CHUNK_SIZErs rArzResponse.contentzsy ==E !%%"#WXX1$(8 $ #):):;M)N O VSV !%}}rCcd}|j}|jsy|j |j} t|j|d}|S#tt f$rt|jd}Y|SwxYw)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. Nr9replace)errors)rrr!rJ LookupErrorr)r?rrs rAtextz Response.texts~==|| == --H :$,,CGY' :$,,y9G :sA&A98A9c 6|jsk|jr_t|jdkDrGt|j}|0 t j |jj |fi|S t j |jfi|S#t$rY,t$r0}t|j|j|jd}~wwxYw#t$r0}t|j|j|jd}~wwxYw)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. rVN)rrr_r,rloadsr\UnicodeDecodeErrorrRequestsJSONDecodeErrormsgdocposrA)r?kwargsrrs rArz Response.jsons}}#dll2Ca2G &dll3H# G&,,T\\-@-@-JUfUU ?$$TYY9&9 9* &G1!%%FFG  ?*!%%> > ?s6 .B9C C$C,+CC D(+DDc|jjd}i}|r;t|}|D]+}|jdxs|jd}|||<-|S)z8Returns the parsed header links of the response, if any.linkrelr:)rYrr.)r?rresolved_linkslinksrKkeys rArNzResponse.linkss`!!&) &v.Ehhuo8%&*s#rCcd}t|jtr |jjd}n |j}d|j cxkrdkr"nn|j d|d|j }n6d|j cxkrdkr!nn|j d |d|j }|r t|| y #t$r|jjd}YwxYw) z+Raises :class:`HTTPError`, if one occurred.r9rGz iso-8859-1iiz Client Error: z for url: iXz Server Error: )responseN)rIrrKr\rDrr:r!)r?http_error_msgrs rArzResponse.raise_for_statuss dkk5 )  :++G4[[F $"" (S (##$OF8:dhhZP D$$ *s *##$OF8:dhhZP  NT: : & :++L9 :sC$C*)C*c|js|jjt|jdd}||yy)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?rTs rArzResponse.closes= %% HHNN txx>  # N $rC)r F)rorprqrrrrrrrrr rrFrrr rrrr!rITER_CHUNK_SIZEr9rrArrNrrrtrCrArrs I-^L#2&  QQ   8v)$B$##J?B ;: rCr)Rrrencodings.idna encodingsiorurllib3.exceptionsrrrrrurllib3.fieldsr urllib3.filepostr urllib3.utilr _internal_utilsr rrrcompatrrrrrrrrrrrrrrrr exceptionsrrr r!r"r#rEr$r&r%r~r& status_codesr' structuresr(utilsr)r*r+r,r-r.r/r0r1r2movedfoundothertemporary_redirectrrDEFAULT_REDIRECT_LIMITr<rUr5rvrrrrtrCrArhs  #(6"?(33MMC%4+ +     KK KK KK   w"w"t0PPfD4*,=D4N MMrC