xjZTddlmZddlZddlZddlmZmZmZddlZejdk\rddl m Z nddl m Z ddl mZddlmZdd lmZdd lmZd d gZGd d ZGdd ej.eefZy)) annotationsN)parse_qsunquote urlencode) ) deprecated)HTTPXDeprecationWarning)QueryParamTypes)urlparse)primitive_value_to_strURL QueryParamsceZdZdZd!d"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#dZee de!d0d Z"y)1ru1 url = httpx2.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 = httpx2.URL("http://中国.icom.museum") assert url.host == "中国.icom.museum" url = httpx2.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 = httpx2.URL("http://中国.icom.museum") assert url.raw_host == b"xn--fiqs8s.icom.museum" url = httpx2.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 httpx2.URL("http://example.com") == httpx2.URL("http://example.com:80") assert httpx2.URL("http://example.com").port is None assert httpx2.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 asciirrz7Invalid type for url. Expected str or httpx2.URL, got z: )strbytesintobjectitems TypeError isinstance__name__typedecodepoprr _uri_referencer copy_with) selfurlkwargsallowedkeyvaluemessageexpectedseenrs `/mnt/ssd/data/Dropbox/adrian/sandbox/mcp-query/venv/lib/python3.12/site-packages/httpx2/_urls.py__init__z URL.__init__Tst !!  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 UVZ[^V_U``bcfbijk kc.|jjS)zb The URL scheme, such as "http", "https". Always normalised to lowercase. )r,rr.s r7rz URL.schemes "")))r9cL|jjjdS)z The raw bytes representation of the URL scheme, such as b"http", b"https". Always normalised to lowercase. r)r,rencoder;s r7 raw_schemezURL.raw_schemes! ""))0099r9cL|jjjdS)zj The URL userinfo as a raw bytestring. For example: b"jo%40email.com:a%20secret". r)r,rr=r;s r7rz URL.userinfos! ""++227;;r9ch|jj}t|jddS)zn The URL username as a string, with URL decoding applied. For example: "jo@email.com" :rr,rr partitionr.rs r7rz URL.username0 &&//x))#.q122r9ch|jj}t|jddS)zj The URL password as a string, with URL decoding applied. For example: "a secret" rArBrDs r7rz URL.passwordrEr9ch|jj}d|vrtj|d}|S)u) The URL host as a string. Always normalized to lowercase, with IDNA hosts decoded into unicode. Examples: url = httpx2.URL("http://www.EXAMPLE.org") assert url.host == "www.example.org" url = httpx2.URL("http://中国.icom.museum") assert url.host == "中国.icom.museum" url = httpx2.URL("http://xn--fiqs8s.icom.museum") assert url.host == "中国.icom.museum" url = httpx2.URL("https://[::ffff:192.168.0.1]") assert url.host == "::ffff:192.168.0.1" zxn--T)display)r,ridnar*)r.rs r7rzURL.hosts1('',, T>;;tT2D r9cL|jjjdS)uE The raw bytes representation of the URL host. Always normalized to lowercase, and IDNA encoded. Examples: url = httpx2.URL("http://www.EXAMPLE.org") assert url.raw_host == b"www.example.org" url = httpx2.URL("http://中国.icom.museum") assert url.raw_host == b"xn--fiqs8s.icom.museum" url = httpx2.URL("http://xn--fiqs8s.icom.museum") assert url.raw_host == b"xn--fiqs8s.icom.museum" url = httpx2.URL("https://[::ffff:192.168.0.1]") assert url.raw_host == b"::ffff:192.168.0.1" r)r,rr=r;s r7raw_hostz URL.raw_hosts!(""''..w77r9c.|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 httpx2.URL("http://www.example.com") == httpx2.URL("http://www.example.com:80") assert httpx2.URL("http://www.example.com:80").port is None )r,rr;s r7rzURL.ports""'''r9cL|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,rr=r;s r7rz URL.netlocs!""))0099r9cL|jjxsd}t|S)z The URL path as a string. Excluding the query string, and URL decoded. For example: url = httpx2.URL("https://example.com/pa%20th") assert url.path == "/pa th" /)r,rrr.rs r7rzURL.paths$""''.3t}r9cX|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 = httpx2.URL("https://example.com/?filter=some%20search%20terms") assert url.query == b"filter=some%20search%20terms" r)r,rr=)r.rs r7rz URL.querys)##))/R||G$$r9c@t|jjS)zz The URL query parameters, neatly parsed and packaged into an immutable multidict representation. )rr,rr;s r7rz URL.paramss 4..4455r9c|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 rP?r)r,rrr=rQs r7rz URL.raw_pathsV""''.3    $ $ 0 C$--333 3D{{7##r9cHt|jjxsdS)zk The URL fragments, as used in HTML anchors. As a string, without the leading '#'. rS)rr,rr;s r7rz URL.fragment/s t**339r::r9cpt|jjxr|jjS)z Return `True` for absolute URLs such as 'http://example.com/path', and `False` for relative URLs such as '/path'. )boolr,rrr;s r7is_absolute_urlzURL.is_absolute_url7s,D''..K43F3F3K3KLLr9c|j S)z Return `False` for absolute URLs such as 'http://example.com/path', and `True` for relative URLs such as '/path'. )rZr;s r7is_relative_urlzURL.is_relative_urlCs ''''r9c 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 = httpx2.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.r0s r7r-z URL.copy_withKs4"6""r9NcZ|j|jj||SN)r)r-rsetr.r2r3s r7copy_set_paramzURL.copy_set_paramZ"~~T[[__S%%@~AAr9cZ|j|jj||Sr_)r-raddras r7copy_add_paramzURL.copy_add_param]rcr9cX|j|jj|Sr_)r-rremover.r2s r7copy_remove_paramzURL.copy_remove_param`s"~~T[[%7%7%<~==r9cX|j|jj|Sr_)r-rmerger.rs r7copy_merge_paramszURL.copy_merge_paramscs"~~T[[%6%6v%>~??r9c hddlm}t|t|tt|S)z Return an absolute URL, using this URL as the base. Eg. url = httpx2.URL("https://www.example.com/test") url = url.join("/new/path") assert url == "https://www.example.com/new/path" r)urljoin) urllib.parserprr!)r.r/rps r7joinzURL.joinfs% )73t9c#c(m455r9c*tt|SNhashr!r;s r7__hash__z URL.__hash__tCIr9crt|ttfxr t|tt|k(Srt)r'rr!r.others r7__eq__z URL.__eq__ws)%#s,MTc#e*o1MMr9c,t|jSrt)r!r,r;s r7__str__z URL.__str__zs4&&''r9ch|j\}}}}}}}d|vr|jddd}dj|r|dndd|vrd|dn||d|ndg}dj|r|jdnd|rd|nd||d |nd|d |ndg} |jj d | d S) NrArz :[secure]rS@[]z//rV#())r,splitrrr __class__r() r.rrrrrrr authorityr/s r7__repr__z URL.__repr__}s>B>Q>Q;$dE8 (?"..-a01;HGG"*8*A"d{!D6 ".!D6 B  gg%+4;;-q!$-"YK 2$0!E7 b"*"6!H:B   ..))*!C7!44r9zURL.raw is deprecated.)categorycddl}|jdgd}||j|j|j|j S)NrRawURL)r>rLrr) collections namedtupler>rLrr)r.rrs r7rawzURL.rawsC ''2`a]]]]   r9)rS)r/ URL | strr0 typing.AnyreturnNonerr!)rr")rz int | None)rrrrY)r0rrrrt)r2r!r3rrr)r2r!rr)rr rr)r/rrrrr#r{rrrY)rztuple[bytes, bytes, int, bytes])#r( __module__ __qualname____doc__r8propertyrr>rrrrrLrrrrrrrrZr\r-rbrfrjrnrrrwr|r~rr r rr r9r7rrs;z,l\**::<<3333488* ( (::  %% 66$$ ;; M M(( #BB>@ 6N(54(3JK  L  r9ceZdZdZddZddZddZddZddZdddZ 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)-rz0 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) NrGzToo many arguments.z'Cannot mix named and unnamed arguments.rrT)keep_blank_valuesr )lenr'r!r"r*r_dictrr%listtuple setdefaultappendr)r.argsr0r3kv dict_valueitems r7r8zQueryParams.__init__s4y1}333}VO&OO$QV =JusEl;-7u-EELL)5E!%4@DJ { +161B1B1DEA!T!W*EDJ=?J%$/ "GD))$q'26==d1gFG_d^i^i^klVZVWYZaJq4-,HaqcQl l \f[k[k[mnnSWSTVW#a&A"ND#9$#?"NNnDJ)Fm #Ons$%F/F#%F.;F) F.)F.c6|jjS)z Return all the keys in the query params. Usage: q = httpx2.QueryParams("a=123&a=456&b=789") assert list(q.keys()) == ["a", "b"] )rkeysr;s r7rzQueryParams.keysszz  r9c|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 = httpx2.QueryParams("a=123&a=456&b=789") assert list(q.values()) == ["123", "789"] r)rr%valuesr.rrs r7rzQueryParams.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 = httpx2.QueryParams("a=123&a=456&b=789") assert list(q.items()) == [("a", "123"), ("b", "789")] r)rr%rs r7r%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 = httpx2.QueryParams("a=123&a=456&b=789") assert list(q.multi_items()) == [("a", "123"), ("a", "456"), ("b", "789")] )rr%extend)r. multi_itemsrris r7rzQueryParams.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 = httpx2.QueryParams("a=123&a=456&b=789") assert q.get("a") == "123" r)rr!)r.r2defaults r7getzQueryParams.gets- $** ::c#h'* *r9c^t|jjt|gS)z Get all values from the query param for a given key. Usage: q = httpx2.QueryParams("a=123&a=456&b=789") assert q.get_list("a") == ["123", "456"] )rrrr!ris r7get_listzQueryParams.get_list s"DJJNN3s8R011r9ct}t|j|_t|g|jt |<|S)z Return a new QueryParams instance, setting the value of a key. Usage: q = httpx2.QueryParams("a=123") q = q.set("a", "456") assert q == httpx2.QueryParams("a=456") )rdictrrr!r.r2r3qs r7r`zQueryParams.sets: Mtzz"3E:;Cr9ct}t|j|_|j|t |gz|jt |<|S)z Return a new QueryParams instance, setting or appending the value of a key. Usage: q = httpx2.QueryParams("a=123") q = q.add("a", "456") assert q == httpx2.QueryParams("a=123&a=456") )rrrrrr!rs r7rezQueryParams.add#sH Mtzz"JJsO/Ee/L.MMCr9ct}t|j|_|jjt |d|S)z Return a new QueryParams instance, removing the value of a key. Usage: q = httpx2.QueryParams("a=123") q = q.remove("a") assert q == httpx2.QueryParams("") N)rrrr+r!)r.r2rs r7rhzQueryParams.remove2s6 Mtzz"  CHd#r9cZt|}i|j|j|_|S)a` Return a new QueryParams instance, updated with. Usage: q = httpx2.QueryParams("a=123") q = q.merge({"b": "456"}) assert q == httpx2.QueryParams("a=123&b=456") q = httpx2.QueryParams("a=123") q = q.merge({"a": "456", "b": "789"}) assert q == httpx2.QueryParams("a=456&b=789") )rr)r.rrs r7rlzQueryParams.mergeAs,  +TZZ+177+r9c&|j|dS)Nrrris r7 __getitem__zQueryParams.__getitem__Sszz#q!!r9c||jvSrtrris r7 __contains__zQueryParams.__contains__Vsdjj  r9c4t|jSrt)iterrr;s r7__iter__zQueryParams.__iter__YsDIIK  r9c,t|jSrt)rrr;s r7__len__zQueryParams.__len__\s4::r9c,t|jSrt)rYrr;s r7__bool__zQueryParams.__bool___sDJJr9c*tt|Srtrur;s r7rwzQueryParams.__hash__brxr9ct||jsyt|jt|jk(S)NF)r'rsortedrrzs r7r|zQueryParams.__eq__es:%0d&&()VE4E4E4G-HHHr9c4t|jSrt)rrr;s r7r~zQueryParams.__str__js))+,,r9cT|jj}t|}|d|dS)Nrr)rr(r!)r. class_name query_strings r7rzQueryParams.__repr__ms.^^,, 4y Q|.a00r9ctd)NzYQueryParams are immutable since 0.18.0. Use `q = q.merge(...)` to create an updated copy. RuntimeErrorrms r7updatezQueryParams.updatersvwwr9ctd)Nz^QueryParams are immutable since 0.18.0. Use `q = q.set(key, value)` to create an updated copy.rras r7 __setitem__zQueryParams.__setitem__us l  r9)rQueryParamTypes | Noner0rrr)rztyping.KeysView[str])rztyping.ValuesView[str])rztyping.ItemsView[str, str])rzlist[tuple[str, str]]rt)r2rrrrr)r2r!rz list[str])r2r!r3rrr)r2r!rr)rrrr)r2rrr!)r2rrrY)rztyping.Iterator[typing.Any]rrrr)rrrr)r2r!r3r!rr)r(rrrr8rrr%rrrr`rerhrlrrrrrrwr|r~rrrr r9r7rrs{o@ ! A @   2   $"!! I -1 x r9) __future__rsystypingrqrrrrJ version_infowarningsr typing_extensions _exceptionsr _typesr _urlparser _utilsr__all__rMappingr!rr r9r7rsi" 55 w#,0#* - L L ^ S &..c*S r9