xL i.TddlmZddlZddlmZmZmZddlZddlm Z ddl m Z ddl m Z dd gZGd dZGd d ej eefZy) ) annotationsN)parse_qsunquote urlencode)QueryParamTypes)urlparse)primitive_value_to_strURL QueryParamsceZdZdZdd dZed!dZed"dZed"dZed!dZ ed!dZ ed!dZ ed"d Z ed#d Z ed"d Zed!d Zed"d Zed$dZed"dZed!dZed%dZed%dZd&dZd'd(dZd'd(dZd)dZd*dZd+dZd,dZd-dZd!dZd!dZed.dZ y)/r u( url = httpx.URL("HTTPS://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink") assert url.scheme == "https" assert url.username == "jo@email.com" assert url.password == "a secret" assert url.userinfo == b"jo%40email.com:a%20secret" assert url.host == "müller.de" assert url.raw_host == b"xn--mller-kva.de" assert url.port == 1234 assert url.netloc == b"xn--mller-kva.de:1234" assert url.path == "/pa th" assert url.query == b"?search=ab" assert url.raw_path == b"/pa%20th?search=ab" assert url.fragment == "anchorlink" The components of a URL are broken down like this: https://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink [scheme] [ username ] [password] [ host ][port][ path ] [ query ] [fragment] [ userinfo ] [ netloc ][ raw_path ] Note that: * `url.scheme` is normalized to always be lowercased. * `url.host` is normalized to always be lowercased. Internationalized domain names are represented in unicode, without IDNA encoding applied. For instance: url = httpx.URL("http://中国.icom.museum") assert url.host == "中国.icom.museum" url = httpx.URL("http://xn--fiqs8s.icom.museum") assert url.host == "中国.icom.museum" * `url.raw_host` is normalized to always be lowercased, and is IDNA encoded. url = httpx.URL("http://中国.icom.museum") assert url.raw_host == b"xn--fiqs8s.icom.museum" url = httpx.URL("http://xn--fiqs8s.icom.museum") assert url.raw_host == b"xn--fiqs8s.icom.museum" * `url.port` is either None or an integer. URLs that include the default port for "http", "https", "ws", "wss", and "ftp" schemes have their port normalized to `None`. assert httpx.URL("http://example.com") == httpx.URL("http://example.com:80") assert httpx.URL("http://example.com").port is None assert httpx.URL("http://example.com:80").port is None * `url.userinfo` is raw bytes, without URL escaping. Usually you'll want to work with `url.username` and `url.password` instead, which handle the URL escaping. * `url.raw_path` is raw bytes of both the path and query, without URL escaping. This portion is used as the target when constructing HTTP requests. Usually you'll want to work with `url.path` instead. * `url.query` is raw bytes, without URL escaping. A URL query string portion can only be properly URL escaped when decoding the parameter names and values themselves. c |r ttttttttttttd }|j D]\}}||vr|d}t ||It |||s:||j}t|j}d|d|d|}t |t |tsv|jd||<d|vr,|jd} | sdntt| |d<t |trt|fi||_ yt |tr"|jjd i||_ yt d t|d |) N) schemeusernamepassworduserinfohostportnetlocpathqueryraw_pathfragmentparamsz) is an invalid keyword argument for URL()z Argument z must be z but got asciirrz6Invalid type for url. Expected str or httpx.URL, got z: )strbytesintobjectitems TypeError isinstance__name__typedecodepopr r _uri_referencer copy_with) selfurlkwargsallowedkeyvaluemessageexpectedseenrs Q/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/httpx/_urls.py__init__z URL.__init__Msv !!  G %lln 8 Ug%!$'PQG#G,,$Zws|-L&s|44H;//D )# (9TFSG#G,,eU+"',,w"7F3K 86!  H-.4$#k&>Q:Rw c3 "*3"9&"9D  S !">#"4"4">">"H"HD S {"SG- c.|jjS)zb The URL scheme, such as "http", "https". Always normalised to lowercase. )r(rr*s r3rz URL.scheme~s "")))r5cL|jjjdS)z The raw bytes representation of the URL scheme, such as b"http", b"https". Always normalised to lowercase. r)r(rencoder7s r3 raw_schemezURL.raw_schemes! ""))0099r5cL|jjjdS)zj The URL userinfo as a raw bytestring. For example: b"jo%40email.com:a%20secret". r)r(rr9r7s r3rz URL.userinfos! ""++227;;r5ch|jj}t|jddS)zn The URL username as a string, with URL decoding applied. For example: "jo@email.com" :rr(rr partitionr*rs r3rz URL.username0 &&//x))#.q122r5ch|jj}t|jddS)zj The URL password as a string, with URL decoding applied. For example: "a secret" r=r>r@s r3rz URL.passwordrAr5c~|jj}|jdrtj|}|S)u% The URL host as a string. Always normalized to lowercase, with IDNA hosts decoded into unicode. Examples: url = httpx.URL("http://www.EXAMPLE.org") assert url.host == "www.example.org" url = httpx.URL("http://中国.icom.museum") assert url.host == "中国.icom.museum" url = httpx.URL("http://xn--fiqs8s.icom.museum") assert url.host == "中国.icom.museum" url = httpx.URL("https://[::ffff:192.168.0.1]") assert url.host == "::ffff:192.168.0.1" zxn--)r(r startswithidnar&)r*rs r3rzURL.hosts4('',, ??6 ";;t$D r5cL|jjjdS)uA The raw bytes representation of the URL host. Always normalized to lowercase, and IDNA encoded. Examples: url = httpx.URL("http://www.EXAMPLE.org") assert url.raw_host == b"www.example.org" url = httpx.URL("http://中国.icom.museum") assert url.raw_host == b"xn--fiqs8s.icom.museum" url = httpx.URL("http://xn--fiqs8s.icom.museum") assert url.raw_host == b"xn--fiqs8s.icom.museum" url = httpx.URL("https://[::ffff:192.168.0.1]") assert url.raw_host == b"::ffff:192.168.0.1" r)r(rr9r7s r3raw_hostz URL.raw_hosts!(""''..w77r5c.|jjS)a The URL port as an integer. Note that the URL class performs port normalization as per the WHATWG spec. Default ports for "http", "https", "ws", "wss", and "ftp" schemes are always treated as `None`. For example: assert httpx.URL("http://www.example.com") == httpx.URL("http://www.example.com:80") assert httpx.URL("http://www.example.com:80").port is None )r(rr7s r3rzURL.ports""'''r5cL|jjjdS)z Either `` or `:` as bytes. Always normalized to lowercase, and IDNA encoded. This property may be used for generating the value of a request "Host" header. r)r(rr9r7s r3rz URL.netlocs!""))0099r5cL|jjxsd}t|S)z The URL path as a string. Excluding the query string, and URL decoded. For example: url = httpx.URL("https://example.com/pa%20th") assert url.path == "/pa th" /)r(rrr*rs r3rzURL.paths$""''.3t}r5cX|jjxsd}|jdS)a The URL query string, as raw bytes, excluding the leading b"?". This is necessarily a bytewise interface, because we cannot perform URL decoding of this representation until we've parsed the keys and values into a QueryParams instance. For example: url = httpx.URL("https://example.com/?filter=some%20search%20terms") assert url.query == b"filter=some%20search%20terms" r)r(rr9)r*rs r3rz URL.querys)##))/R||G$$r5c@t|jjS)zz The URL query parameters, neatly parsed and packaged into an immutable multidict representation. )r r(rr7s r3rz URL.paramss 4..4455r5c|jjxsd}|jj|d|jjzz }|jdS)a The complete URL path and query string as raw bytes. Used as the target when constructing HTTP requests. For example: GET /users?search=some%20text HTTP/1.1 Host: www.example.org Connection: close rL?r)r(rrr9rMs r3rz URL.raw_pathsV""''.3    $ $ 0 C$--333 3D{{7##r5cHt|jjxsdS)zk The URL fragments, as used in HTML anchors. As a string, without the leading '#'. rO)rr(rr7s r3rz URL.fragment+s t**339r::r5cpt|jjxr|jjS)z Return `True` for absolute URLs such as 'http://example.com/path', and `False` for relative URLs such as '/path'. )boolr(rrr7s r3is_absolute_urlzURL.is_absolute_url3s,D''..K43F3F3K3KLLr5c|j S)z Return `False` for absolute URLs such as 'http://example.com/path', and `True` for relative URLs such as '/path'. )rVr7s r3is_relative_urlzURL.is_relative_url?s ''''r5c t|fi|S)a Copy this URL, returning a new URL with some components altered. Accepts the same set of parameters as the components that are made available via properties on the `URL` class. For example: url = httpx.URL("https://www.example.com").copy_with( username="jo@gmail.com", password="a secret" ) assert url == "https://jo%40email.com:a%20secret@www.example.com" )r )r*r,s r3r)z URL.copy_withGs4"6""r5NcZ|j|jj||SN)r)r)rsetr*r.r/s r3copy_set_paramzURL.copy_set_paramV"~~T[[__S%%@~AAr5cZ|j|jj||Sr[)r)raddr]s r3copy_add_paramzURL.copy_add_paramYr_r5cX|j|jj|Sr[)r)rremover*r.s r3copy_remove_paramzURL.copy_remove_param\s"~~T[[%7%7%<~==r5cX|j|jj|Sr[)r)rmerger*rs r3copy_merge_paramszURL.copy_merge_params_s"~~T[[%6%6v%>~??r5c hddlm}t|t|tt|S)z Return an absolute URL, using this URL as the base. Eg. url = httpx.URL("https://www.example.com/test") url = url.join("/new/path") assert url == "https://www.example.com/new/path" r)urljoin) urllib.parserlr r)r*r+rls r3joinzURL.joinbs% )73t9c#c(m455r5c*tt|SNhashrr7s r3__hash__z URL.__hash__pCIr5crt|ttfxr t|tt|k(Srp)r#r rr*others r3__eq__z URL.__eq__ss)%#s,MTc#e*o1MMr5c,t|jSrp)rr(r7s r3__str__z URL.__str__vs4&&''r5ch|j\}}}}}}}d|vr|jddd}dj|r|dndd|vrd|dn||d|ndg}dj|r|jdnd|rd|nd||d |nd|d |ndg} |jj d | d S) Nr=rz :[secure]rO@[]z//rR#())r(splitrnr __class__r$) r*rrrrrrr authorityr+s r3__repr__z URL.__repr__ys>B>Q>Q;$dE8 (?"..-a01;HGG"*8*A"d{!D6 ".!D6 B  gg%+4;;-q!$-"YK 2$0!E7 b"*"6!H:B   ..))*!C7!44r5cddl}ddl}|jd|jdgd}||j|j |j |jS)NrzURL.raw is deprecated.RawURL)r:rHrr) collectionswarningswarn namedtupler:rHrr)r*rrrs r3rawzURL.rawsV ./'' D ]]]]   r5)rO)r+ URL | strr, typing.AnyreturnNonerr)rr)rz int | None)rr rrU)r,rrr rp)r.rr/rrr )r.rrr )rrrr )r+rrr rrrwrrrU)rztuple[bytes, bytes, int, bytes])!r$ __module__ __qualname____doc__r4propertyrr:rrrrrHrrrrrrrrVrXr)r^rbrfrjrnrsrxrzrrrr5r3r r s;z/b**::<<3333488* ( (::  %% 66$$ ;; M M(( #BB>@ 6N(54    r5ceZdZdZddZddZddZddZddZdddZ d d Z dd!d Z dd!d Z d"d Z dd#d Zd$dZd%dZd&dZd'dZd(dZd'dZd)dZd*dZd*dZdd+dZd,dZy)-r z0 URL query parameters, as a multi-dict. c jt|dksJd|r |rJd|r|dn|}|t|ttfr6t|tr|j dn|}t |d|_yt|tr=|j jDcic]\}}|t|c}}|_yi}t|ttfr/|D])}|j|dgj|d+nE|jDcic]*\}}|t|ttfr t|n|g,}}}|jDcic](\}}t||Dcgc] }t|c}*c}}}|_ycc}}wcc}}wcc}wcc}}}w) NrCzToo many arguments.z'Cannot mix named and unnamed arguments.rrT)keep_blank_valuesr)lenr#rrr&r_dictr r!listtuple setdefaultappendr )r*argsr,r/kv dict_valueitems r3r4zQueryParams.__init__s4y1}333}VO&OO$QV =JusEl;-7u-EELL)5E!%4@DJ { +161B1B1DEA!T!W*EDJ=?J%$/ "GD))$q'26==d1gFG!& 1*Qu ">tAwQCG ',,.AqA!D$/5DDDJ/FEs$%F/F#%F.;F) F.)F.c6|jjS)z Return all the keys in the query params. Usage: q = httpx.QueryParams("a=123&a=456&b=789") assert list(q.keys()) == ["a", "b"] )rkeysr7s r3rzQueryParams.keysszz  r5c|jjDcic] \}}||d c}}jScc}}w)a Return all the values in the query params. If a key occurs more than once only the first item for that key is returned. Usage: q = httpx.QueryParams("a=123&a=456&b=789") assert list(q.values()) == ["123", "789"] r)rr!valuesr*rrs r3rzQueryParams.valuess:%)JJ$4$4$67DAq1Q47>>@@7Ac|jjDcic] \}}||d c}}jScc}}w)a Return all items in the query params. If a key occurs more than once only the first item for that key is returned. Usage: q = httpx.QueryParams("a=123&a=456&b=789") assert list(q.items()) == [("a", "123"), ("b", "789")] r)rr!rs r3r!zQueryParams.itemss:%)JJ$4$4$67DAq1Q47==??7rcg}|jjD]&\}}|j|Dcgc]}||fc}(|Scc}w)z Return all items in the query params. Allow duplicate keys to occur. Usage: q = httpx.QueryParams("a=123&a=456&b=789") assert list(q.multi_items()) == [("a", "123"), ("a", "456"), ("b", "789")] )rr!extend)r* multi_itemsrris r3rzQueryParams.multi_itemssQ.0 JJ$$& 4DAq   21A2 3 4 3s A NcX||jvr|jt|dS|S)z Get a value from the query param for a given key. If the key occurs more than once, then only the first value is returned. Usage: q = httpx.QueryParams("a=123&a=456&b=789") assert q.get("a") == "123" r)rr)r*r.defaults r3getzQueryParams.gets- $** ::c#h'* *r5c^t|jjt|gS)z Get all values from the query param for a given key. Usage: q = httpx.QueryParams("a=123&a=456&b=789") assert q.get_list("a") == ["123", "456"] )rrrrres r3get_listzQueryParams.get_lists"DJJNN3s8R011r5ct}t|j|_t|g|jt |<|S)z Return a new QueryParams instance, setting the value of a key. Usage: q = httpx.QueryParams("a=123") q = q.set("a", "456") assert q == httpx.QueryParams("a=456") )r dictrr rr*r.r/qs r3r\zQueryParams.sets: Mtzz"3E:;Cr5ct}t|j|_|j|t |gz|jt |<|S)z Return a new QueryParams instance, setting or appending the value of a key. Usage: q = httpx.QueryParams("a=123") q = q.add("a", "456") assert q == httpx.QueryParams("a=123&a=456") )r rrrr rrs r3razQueryParams.add(sH Mtzz"JJsO/Ee/L.MMCr5ct}t|j|_|jjt |d|S)z Return a new QueryParams instance, removing the value of a key. Usage: q = httpx.QueryParams("a=123") q = q.remove("a") assert q == httpx.QueryParams("") N)r rrr'r)r*r.rs r3rdzQueryParams.remove7s6 Mtzz"  CHd#r5cZt|}i|j|j|_|S)a\ Return a new QueryParams instance, updated with. Usage: q = httpx.QueryParams("a=123") q = q.merge({"b": "456"}) assert q == httpx.QueryParams("a=123&b=456") q = httpx.QueryParams("a=123") q = q.merge({"a": "456", "b": "789"}) assert q == httpx.QueryParams("a=456&b=789") )r r)r*rrs r3rhzQueryParams.mergeFs,  +TZZ+177+r5c&|j|dS)Nrrres r3 __getitem__zQueryParams.__getitem__Xszz#q!!r5c||jvSrprres r3 __contains__zQueryParams.__contains__[sdjj  r5c4t|jSrp)iterrr7s r3__iter__zQueryParams.__iter__^sDIIK  r5c,t|jSrp)rrr7s r3__len__zQueryParams.__len__as4::r5c,t|jSrp)rUrr7s r3__bool__zQueryParams.__bool__dsDJJr5c*tt|Srprqr7s r3rszQueryParams.__hash__grtr5ct||jsyt|jt|jk(S)NF)r#rsortedrrvs r3rxzQueryParams.__eq__js:%0d&&()VE4E4E4G-HHHr5c4t|jSrp)rrr7s r3rzzQueryParams.__str__os))+,,r5cT|jj}t|}|d|dS)Nrr)rr$r)r* class_name query_strings r3rzQueryParams.__repr__rs.^^,, 4y Q|.a00r5ctd)NzYQueryParams are immutable since 0.18.0. Use `q = q.merge(...)` to create an updated copy. RuntimeErrorris r3updatezQueryParams.updatews @  r5ctd)Nz^QueryParams are immutable since 0.18.0. Use `q = q.set(key, value)` to create an updated copy.rr]s r3 __setitem__zQueryParams.__setitem__}s E  r5)rQueryParamTypes | Noner,rrr)rztyping.KeysView[str])rztyping.ValuesView[str])rztyping.ItemsView[str, str])rzlist[tuple[str, str]]rp)r.rrrrr)r.rrz list[str])r.rr/rrr )r.rrr )rrrr )r.rrr)r.rrrU)rztyping.Iterator[typing.Any]rrrr)rrrr)r.rr/rrr)r$rrrr4rrr!rrrr\rardrhrrrrrrsrxrzrrrrr5r3r r sy$L ! A @   2   $"!! I -1   r5) __future__rtypingrmrrrrF_typesr _urlparser _utilsr __all__r Mappingrr rr5r3rsO" 55 #* - R R j ] &..c*] r5