MA;P7jdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZmZddlmZddlmZddlmZmZmZmZdd lmZmZmZmZmZmZm Z dd lm!Z"dd lm#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)dd l*m+Z+dd l,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2dZ3ej4Z5dddZ6d7ej8deddZ9ej:dkrdZ;dZ#dZdZ?d Z@ejAd!ZBd"ZCd#ZDd$ZEd%ZFdJd&ZGd'ZHd(ZId)ZJd*ZKd+ZLd,ZMd-ZNd.ZOePd/ZQd0ZRd1ZSd2ZTd3ZUd4ZVd5ZWejAd6ZXd7ZYdKd8ZZd9Z[dLd:Z\dMd<Z]d=Z^d>Z_d?`d@ZaeadAzZbeadBzZcdCZddDZedEZfdFZgdGZhdHZidIZjdS)Nz requests.utils ~~~~~~~~~~~~~~ This module provides utility functions that are used within Requests that are also useful for external consumption. N) OrderedDict) make_headers parse_url)certs __version__)_HEADER_VALIDATORS_BYTE_HEADER_VALIDATORS_STRHEADER_VALIDATORSto_native_string)Mapping basestringbytes getproxiesgetproxies_environment integer_types is_urllib3_1)parse_http_list) proxy_bypassproxy_bypass_environmentquotestrunquoteurlparse urlunparsecookiejar_from_dict)FileModeWarning InvalidHeader InvalidURLUnrewindableBodyError)CaseInsensitiveDict)z.netrc_netrcPi)httphttpsz, z,\s*T)accept_encodingzaccept-encodingwin32cl ddl}n#t$rYdSwxYw ||jd}t ||dd}||dd}n#t tf$rYdSwxYw|r|sdS|d}td|}|D]t}|dkrd|vrd S| dd }| d d }| d d}tj ||tj rd SudS)NrFz;Software\Microsoft\Windows\CurrentVersion\Internet Settings ProxyEnable ProxyOverride;z.Tz\.*z.*?)winreg ImportErrorOpenKeyHKEY_CURRENT_USERint QueryValueExOSError ValueErrorsplitfilterreplacerematchI)hostr1internetSettings proxyEnable proxyOverridetests l/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/pip/_vendor/requests/utils.pyproxy_bypass_registryrEMs  MMMM   55  %~~(N    f112BMRRSTUVVK"//0@/RRSTUMM$   55  - 5 &++C00 t]33 !  Dy  d??44<<U++D<<U++D<<T**DxdBD)) tt us A A::BBcZtrt|St|S)zReturn True, if the host should be bypassed. Checks proxy settings gathered from the environment, if specified, or the registry. )rrrE)r?s rDrrss. " # # /+D11 1(.. .cNt|dr|}|S)z/Returns an internal sequence dictionary update.items)hasattrrI)ds rDdict_to_sequencerLs(q' GGII HrGcHd}d}ts*t|tr|d}t |drt |}nt |dr|j}n~t |drn |}tj|j }d|j vrtj dtn#tjt f$rYnwxYwt |dr |}t |d rW|U |dd |}||pdn'#t&$rd}YnwxYwn#t&$r||}YnwxYw|d}t)d||z S) Nrutf-8__len__lenfilenoba%Requests has determined the content-length for this request using the binary size of the file: however, the file has been opened in text mode (i.e. without the 'b' flag in the mode). This may lead to an incorrect content-length. In Requests 3.0, support will be removed for files in text mode.tellseek)r isinstancerencoderJrPrQosfstatst_sizemodewarningswarnrioUnsupportedOperationAttributeErrorrSrTr7max)o total_lengthcurrent_positionrQs rD super_lenresL Jq#.. HHW  q)1vv E  u H   XXZZF8F++3L!&   2$   '8    D  .q&% % vvxx q&!! %l&: %FF1aLLL#$6688LFF+0q1111%%%#$LLL%% 0 0 0 '#/  0* q,!11 2 22s7?CC)(C)=E9$AE&& E54E59F  F Fc tjd}||f}ndtD} ddlm}m}d}|D]D}tj|}tj|r|}nE|dSt|} | j } || | } | r| drdnd} | | | dfSdS#|tf$r|rYdSwxYw#ttf$rYdSwxYw)z;Returns the Requests tuple auth for a given url from netrc.NETRCNc3 K|] }d|V dS)z~/N).0fs rD z!get_netrc_auth..s(99888999999rGr)NetrcParseErrornetrcrrU)rXenvironget NETRC_FILESrnrmpath expanduserexistsrhostnameauthenticatorsr7r2r`) url raise_errors netrc_filenetrc_locationsrmrn netrc_pathrklocrir?r$login_is rDget_netrc_authrs((J%-99[999  00000000    A'$$Q''Cw~~c""      F c]]{ U:&&55d;;F 4%ay/!!aw33 4 4 )          (     s6AC8 C8$;C""C51C84C55C88D  D ct|dd}|rLt|tr9|ddkr/|ddkr%tj|SdSdSdSdS)z0Tries to guess the filename of the given object.nameNr<>)getattrrVrrXrrbasename)objrs rDguess_filenamersw 3 % %D & 4,,&aCDHPSOOw%%%&&&&OOrGctj|r|Stj|\}}|r|tj|s]tj|\}}|sn8d||g}|rtj|]t j|s|St j|}||vr|Stj }tj||dd}tj|sOt|5}| | |dddn #1swxYwY|S)zReplace nonexistent paths that look like they refer to a member of a zip archive with the location of an extracted copy of the target, or else just return the provided path unchanged. /rN)rXrrrtr9joinzipfile is_zipfileZipFilenamelisttempfile gettempdir atomic_openwriteread)rrarchivememberprefixzip_filetmpextracted_path file_handlers rDextract_zipped_pathsrs  w~~d gmmD))OGV ,"'..11,'--00  66*++ ,"'..11,  g & & w''H X&&((((     CW\\#v||C'8'8'<==N 7>>. ) )6  ( ( 6L   x}}V44 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 s>)F33F7:F7c#HKtjtj|\}} tj|d5}|Vdddn #1swxYwYtj||dS#t$rtj|wxYw)z-Write a file to the disk in an atomic fashion)dirwbN) rmkstemprXrrdirnamefdopenr; BaseExceptionremove)filenametmp_descriptortmp_name tmp_handlers rDrr's (/BGOOH4M4MNNNNH Y~t , ,                     8X&&&&&  ( s/BA BA##B&A#'B B!c|dSt|ttttfrt dt |S)aTake an object and test to see if it can be represented as a dictionary. Unless it can not be represented as such, return an OrderedDict, e.g., :: >>> from_key_val_list([('key', 'val')]) OrderedDict([('key', 'val')]) >>> from_key_val_list('string') Traceback (most recent call last): ... ValueError: cannot encode objects that are not 2-tuples >>> from_key_val_list({'key': 'val'}) OrderedDict([('key', 'val')]) :rtype: OrderedDict N+cannot encode objects that are not 2-tuples)rVrrboolr5r8rvalues rDfrom_key_val_listr4sG$ }t%#udC011HFGGG u  rGc|dSt|ttttfrt dt|t r|}t|S)aTake an object and test to see if it can be represented as a dictionary. If it can be, return a list of tuples, e.g., :: >>> to_key_val_list([('key', 'val')]) [('key', 'val')] >>> to_key_val_list({'key': 'val'}) [('key', 'val')] >>> to_key_val_list('string') Traceback (most recent call last): ... ValueError: cannot encode objects that are not 2-tuples :rtype: list Nr) rVrrrr5r8rrIlistrs rDto_key_val_listrOsd" }t%#udC011HFGGG%!!  ;;rGcg}t|D]N}|dd|ddcxkrdkrnnt|dd}||O|S)aParse lists as described by RFC 2068 Section 2. In particular, parse comma-separated lists where the elements of the list may include quoted-strings. A quoted-string could contain a comma. A non-quoted string could have quotes in the middle. Quotes are removed automatically after parsing. It basically works like :func:`parse_set_header` just that items may appear multiple times and case sensitivity is preserved. The return value is a standard :class:`list`: >>> parse_list_header('token, "quoted value"') ['token', 'quoted value'] To create a header from the :class:`list` again, use the :func:`dump_header` function. :param value: a string with a list header. :return: :class:`list` :rtype: list Nrr")_parse_list_headerunquote_header_valueappend)rresultitems rDparse_list_headerrms.F"5)) 8tBCCy ' ' ' 'C ' ' ' ' ''QrT 33D d MrGci}t|D]a}d|vrd||< |dd\}}|dd|ddcxkrdkrnnt|dd}|||<b|S)a^Parse lists of key, value pairs as described by RFC 2068 Section 2 and convert them into a python dict: >>> d = parse_dict_header('foo="is a fish", bar="as well"') >>> type(d) is dict True >>> sorted(d.items()) [('bar', 'as well'), ('foo', 'is a fish')] If there is no value for a key it will be `None`: >>> parse_dict_header('key_without_value') {'key_without_value': None} To create a header from the :class:`dict` again, use the :func:`dump_header` function. :param value: a string with a dict header. :return: :class:`dict` :rtype: dict =Nrrr)rr9r)rrrrs rDparse_dict_headerrs,F"5)) d??F4L jja(( e !9bcc ) ) ) )c ) ) ) ) )(qt55Et MrGc|r`|d|dcxkrdkrGnnD|dd}|r|dddkr*|ddd dS|S) zUnquotes a header value. (Reversal of :func:`quote_header_value`). This does not use the real unquoting but what browsers are actually using for quoting. :param value: the header value to unquote. :rtype: str rrrrNrUz\\\z\")r;)r is_filenames rDrrs CqU2Y----#----- ad  CeBQBi611==..66ucBB B LrGcd|D}|S)zReturns a key/value dictionary from a CookieJar. :param cj: CookieJar object to extract cookies from. :rtype: dict c(i|]}|j|jSri)rr)rjcookies rD z'dict_from_cookiejar..s>>>6; >>>rGricj cookie_dicts rDdict_from_cookiejarrs?>2>>>K rGc"t||S)zReturns a CookieJar from a key/value dictionary. :param cj: CookieJar to insert cookies into. :param cookie_dict: Dict of key/values to insert into CookieJar. :rtype: CookieJar rrs rDadd_dict_to_cookiejarrs {B / //rGc`tjdttjdtj}tjdtj}tjd}||||z||zS)zlReturns encodings from given content string. :param content: bytestring to extract encodings from. zIn requests 3.0, get_encodings_from_content will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)z!])flagsz+]z$^<\?xml.*?encoding=["\']*(.+?)["\'>])r\r]DeprecationWarningr<compiler>findall)content charset_re pragma_rexml_res rDget_encodings_from_contentrs  M 1  @MMMJ IQSQUVVVI Z? @ @F 7##   G $ $ % .. ! ! "rGc|d}|d|dd}}i}d}|D]}|}|rs|d}}|d} | dkr=|d| |}|| dzd|}|||<||fS) zReturns content type and parameters from given header :param header: string :return: tuple containing content type and dictionary of parameters r-rrNz"' Trr)r9stripfindlower) headertokens content_typeparams params_dictitems_to_stripparamkeyrindex_of_equalss rD_parse_content_type_headerrs\\#  F!!9??,,fQRRj&LKN--   -C#jjooO"$$,_,-33NCCo1334::>JJ',K $  $$rGc|d}|sdSt|\}}d|vr|ddSd|vrdSd|vrdSdS) z}Returns encodings from given HTTP Header Dict. :param headers: dictionary to extract encoding from. :rtype: str z content-typeNcharsetz'"textz ISO-8859-1zapplication/jsonrN)rprr)headersrrs rDget_encoding_from_headersrs;;~..L t5lCCL&Fi &&u--- |\))w*)rGc#K|j |Ed{VdStj|jd}|D]}||}|r|V|dd}|r|VdSdS)zStream decodes an iterator.Nr;errorsrGT)final)encodingcodecsgetincrementaldecoderdecode)iteratorrdecoderchunkrvs rDstream_decode_response_unicoder*s z6f*1:66iHHHG ^^E " "  HHH 4 ( (B rGc#Kd}||dkrt|}|t|kr)||||zV||z }|t|k'dSdS)z Iterate over slices of a string.rN)rP)string slice_lengthposs rD iter_slicesr;s{ C|q006{{ F  S3--.... | F      rGc:tjdtg}t|j}|r; t |j|S#t$r||YnwxYw t |j|dS#t$r |jcYSwxYw)zReturns the requested content back in unicode. :param r: Response object to get unicode content from. Tried: 1. charset from content-type 2. fall back and replace all unicode characters :rtype: str zIn requests 3.0, get_unicode_from_response will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)r;r) r\r]rrrrr UnicodeErrorr TypeError)rtried_encodingsrs rDget_unicode_from_responserEs M 1  O)33H- -qy(++ + - - -  " "8 , , , , , -19hy9999 ys#A A+*A+/BBBzBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~c|d}tdt|D]}||dd}t|dkr|ro t t |d}n!#t $rtd|dwxYw|tvr|||ddz||<d||||<d||||<d |S) zUn-escape any percent-escape sequences in a URI that are unreserved characters. This leaves all reserved, illegal and non-ASCII bytes encoded. :rtype: str %rrrUz"Invalid percent-escape sequence: ''N) r9rangerPisalnumchrr5r8r!UNRESERVED_SETr)uripartsihcs rDunquote_unreservedr rs IIcNNE 1c%jj ! ! & & !HQqSM q66Q;;199;;; LAr OO L L L !Ja!J!J!JKKK LN""uQx|+a)uQx>>a%58~~E!HH 775>>s -B  B)cd}d} tt||S#t$rt||cYSwxYw)zRe-quote the given URI. This function passes the given URI through an unquote/quote cycle to ensure that it is fully and consistently quoted. :rtype: str z!#$%&'()*+,/:;=?@[]~z!#$&'()*+,/:;=?@[]~)safe)rr r!)rsafe_with_percentsafe_without_percents rD requote_urirsk/0 5',,3DEEEE 555S3444444 5s$AAc tjdtj|d}|d\}}tjdtjt t |d}tjdtj|d|z}||z||zkS)zThis function allows you to check if an IP belongs to a network subnet Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24 returns False if ip = 192.168.1.1 and net = 192.168.100.0/24 :rtype: bool z=Lrr)structunpacksocket inet_atonr9dotted_netmaskr5)ipnetipaddrnetaddrbitsnetmasknetworks rDaddress_in_networkr s]4!1"!5!5 6 6q 9FIIcNNMGTmD&"2>#d))3L3L"M"MNNqQGmD&"27";";<I)r inet_ntoarpack)maskrs rDrrs8 b4i1, ,D  FKd33 4 44rGcT tj|n#t$rYdSwxYwdS)z :rtype: bool FT)rrr7) string_ips rDis_ipv4_addressr(sB#### uu 4s  %%cN|ddkr t|dd}n#t$rYdSwxYw|dks|dkrdS t j|ddn#t $rYdSwxYwdSdS)zV Very simple check of the cidr format in no_proxy variable. :rtype: bool rrFr"rT)countr5r9r8rrr7)string_networkr%s rD is_valid_cidrr,s C  A%% ~++C00344DD   55  !88tbyy5   ^11#66q9 : : : :   55 u 4s#(A AA$-B B B c#K|du}|r.tj|}|tj|< dV|r"|tj|=dS|tj|<dSdS#|r|tj|=n|tj|<wxYw)zSet the environment variable 'env_name' to 'value' Save previous value, yield, and then restore the previous value stored in the environment variable 'env_name'. If 'value' is None, do nothingN)rXrorp)env_namer value_changed old_values rD set_environr1s%M%JNN8,, $ 81   1 Jx((('0 8$$$  1 1= 1 Jx(('0 8$0000s A""#Bcd}|}| |d}t|}|jdS|rd|dddD}t |jr<|D]8}t |rt |j|rdS*|j|krdS9nR|j}|jr |d |jz }|D]4}|j|s||rdS5td|5 t|j}n#ttj f$rd }YnwxYwdddn #1swxYwY|rdSd S) zL Returns whether we should bypass proxies or not. :rtype: bool ctj|p0tj|SN)rXrorpupper)rs rD get_proxyz(should_bypass_proxies..get_proxys1z~~c""AbjnnSYY[[&A&AArGNno_proxyTc3K|]}||V dSr4ri)rjr?s rDrlz(should_bypass_proxies.. s'RRTTRDRRRRRRrG r,:F)rrur;r9r(r,r portendswithr1rrrgaierror) rwr7r6 no_proxy_argparsedproxy_iphost_with_portr?bypasss rDshould_bypass_proxiesrDs#BBB L9Z(( c]]F t SRX%5%5c2%>%>%D%DS%I%IRRR 6? + + $   ** )&/8DD$#tt$_00 441  $_N{ 4"3fk"3"33   ?++D11 ^5L5LT5R5R  44 Z . . !&/22FF6?+   FFF  t 5s6ED)(E)EEEEEEcDt||riStS)zA Return a dict of environment proxies. :rtype: dict r7)rDr)rwr7s rDget_environ_proxiesrG0s( S8444 ||rGc|pi}t|}|j.||j|dS|jdz|jz|jd|jzdg}d}|D]}||vr ||}n|S)zSelect a proxy for the url, if applicable. :param url: The url being for the request :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs Nallz://zall://)rrurpscheme)rwproxiesurlparts proxy_keysproxy proxy_keys rD select_proxyrP<s mG}}H {{8?GKK,>,>??? %("338$$ J E   I&E E  LrGcd||ni}|j}t|j}|d}|}|rct ||sRt ||}|||d}|r||||S)aThis method takes proxy information from a request and configuration input to resolve a mapping of target proxies. This will consider settings such as NO_PROXY to strip proxy configurations. :param request: Request or PreparedRequest :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs :param trust_env: Boolean declaring whether to trust environment configs :rtype: dict Nr7rFrI)rwrrJrpcopyrDrG setdefault) requestrK trust_envrwrJr7 new_proxiesenviron_proxiesrNs rDresolve_proxiesrXVs!,gg"G +C c]] !F{{:&&H,,..K2.sXFFF2-cHEEE##FO,?,?,F,FGG  2  " "65 1 1 1 rGpython-requestsc|dtS)zO Return a string representing the default user agent. :rtype: str rr)rs rDdefault_user_agentr[qs  " "[ " ""rGcLtttdddS)z9 :rtype: requests.structures.CaseInsensitiveDict z*/*z keep-alive)z User-AgentzAccept-EncodingAccept Connection)r#r[DEFAULT_ACCEPT_ENCODINGrirGrDdefault_headersr`zs2 ,..6&     rGcg}d}||}|s|Stjd|D]} |dd\}}n#t$r|d}}YnwxYwd|di}|dD]X} |d\}}n#t$rYn0wxYw|||||<Y|||S) zReturn a list of parsed link headers proxies. i.e. Link: ; rel=front; type="image/jpeg",; rel=back;type="image/jpeg" :rtype: list z '"z, * '"r)rr<r9r8r) rlinks replace_charsvalrwrlinkrrs rDparse_header_linksrfsA EM KK & &E  x&& "))C++KC " " "rCCC "syy**+\\#&& H HE "[[-- UU    .3[[-G-GD=)) * * T Ls#AA! A!B,, B:9B:asciirUc|dd}|tjtjfvrdS|ddtjkrdS|ddtjtjfvrdS|t}|dkrd S|dkr,|dddtkrd S|d ddtkrd S|dkr*|ddtkrd S|d dtkrdSdS)z :rtype: str Nzutf-32riz utf-8-sigrUzutf-16rrNz utf-16-berz utf-16-lez utf-32-bez utf-32-le) r BOM_UTF32_LE BOM_UTF32_BEBOM_UTF8 BOM_UTF16_LE BOM_UTF16_BEr*_null_null2_null3)datasample nullcounts rDguess_json_utfrws"1"XF &%v':;;;x bqbzV_$${ bqbzf)6+>???x U##IA~~wA~~ ##A#;& ; !$Q$<6 ! !;A~~ "1":  ; !"":  ; 4rGct|}|\}}}}}}} |j} | s|| }} |rd|| g} ||}|d}t|| |d|| fS)zGiven a URL that may or may not have a scheme, prepend the given scheme. Does not replace a present scheme with the one provided as an argument. :rtype: str @Nr)rnetlocrr) rw new_schemer@rJauthr?r<rrqueryfragmentrzs rDprepend_scheme_if_neededrs s^^F6<3FD$dE8 ]F $V *4.)) ~ | vvtRA B BBrGct|} t|jt|jf}n#tt f$rd}YnwxYw|S)z{Given a url with authentication components, extract them into a tuple of username,password. :rtype: (str,str) )rr)rrusernamepasswordr`r)rwr@r|s rDget_auth_from_urlrsd c]]F(('&/*B*BC I & Ks(:AAcT|\}}t||dt||ddS)zVerifies that header parts don't contain leading whitespace reserved characters, or return characters. :param header: tuple, in the format (name, value). rrN)_validate_header_part)rrrs rDcheck_header_validityrs7 KD%&$***&%+++++rGc Dt|trt|}nHt|trt|}n%t d|d|dt |||s|dkrdnd}t d|d|dS) Nz Header part (z) from z# must be of type str or bytes, not rrrzTInvalid leading whitespace, reserved character(s), or return character(s) in header z: )rVrr rr r typer=)r header_partheader_validator_index validator header_kinds rDrr s+s## *+AB K ' ' +,BC  EK E E& E E15k1B1B E E   ??; ' ' 6! ; ;ff  E&1 E E5@ E E     rGct|\}}}}}}|s||}}|ddd}t|||||dfS)zW Given a url remove the fragment and the authentication part. :rtype: str ryrrr)rrsplitr)rwrJrzrrrr}r~s rD urldefragauthrsb 5=SMM1FFD&% $V ]]3 " "2 &F vvtVUB? @ @@rGct|jdd}|Jt|jtr0 ||jdS#t $rt dwxYwt d)zfMove file pointer back to its recorded starting position so it can be read again on redirect. rTNz;An error occurred when rewinding request body for redirect.z+Unable to rewind request body for redirect.)rbodyrV_body_positionrr7r")prepared_request body_seeks rD rewind_bodyr/s(-vt<rs  ######<<<<<<<<$$$$$$ :99999)((((( ,+++++" $c** )) BHWll48889JKLL <7$$$L / / /   D3D3D3N) ) ) ) X&&&"""J    6<@F20002%%%22"$$$PM 0555, 5 5 55550 111*:::z    46####   """L  g  @CCC:    ,,,   &AAA"SSSSSrG