
    IiE              
          S r SSKrSSKrSSKrSSKrSSKJr  SrSrSr	\R                  " S5      r\R                  " S	R                  S
SSSSS95      r\R                  " SR                  SSSS95      r\R                  " S
5      \R                  " S5      \R                  " S5      \R                  " S5      \R                  " S5      \R                  " S5      \R                  " S5      \R                  " S5      S.r\R                  " S5      r\R                  " S5      r " S S\R$                  5      rS1S\S\R*                  \   S\4S jjrS\S\4S jrS \R*                  \R0                  \\4      S!\S\R*                  \   4S" jrS#\S$\S%\SS4S& jrS#\S\4S' jrS(\S\4S) jrS2S*\S+\S\4S, jjrS2S*\S+\S\4S- jjr S2S*\S+\S\4S. jjr!S/\RD                  \RF                  \\4      S\4S0 jr$g)3a  
An implementation of `urlparse` that provides URL validation and normalization
as described by RFC3986.

We rely on this implementation rather than the one in Python's stdlib, because:

* It provides more complete URL validation.
* It properly differentiates between an empty querystring and an absent querystring,
  to distinguish URLs with a trailing '?'.
* It handles scheme, hostname, port, and path normalization.
* It supports IDNA hostnames, normalizing them to their encoded form.
* The API supports passing individual components, as well as the complete URL string.

Previously we relied on the excellent `rfc3986` package to handle URL parsing and
validation, but this module provides a simpler alternative, with less indirection
required.
    N   )
InvalidURLi   zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~z!$&'()*+,;=z%[A-Fa-f0-9]{2}z(?:(?P<scheme>{scheme}):)?(?://(?P<authority>{authority}))?(?P<path>{path})(?:\?(?P<query>{query}))?(?:#(?P<fragment>{fragment}))?z([a-zA-Z][a-zA-Z0-9+.-]*)?z[^/?#]*z[^?#]*z[^#]*z.*scheme	authoritypathqueryfragmentzA(?:(?P<userinfo>{userinfo})@)?(?P<host>{host}):?(?P<port>{port})?z(\[.*\]|[^:@]*))userinfohostportz[^@]*z(\[.*\]|[^:]*))r   r   r   r	   r
   r   r   r   z ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$z^\[.*\]$c                      \ rS rSr% \\S'   \\S'   \\S'   \R                  \   \S'   \\S'   \R                  \   \S'   \R                  \   \S'   \	S	\4S
 j5       r
\	S	\4S j5       rS\R                  \   S	S 4S jrS	\4S jrSrg)ParseResult^   r   r   r   r   r   r	   r
   returnc                     SR                  U R                  (       a  U R                   S3OSSU R                  ;   a  SU R                   S3OU R                  U R                  b  SU R                   3/5      $ S/5      $ )N @:[])joinr   r   r   selfs    5/venv/lib/python3.13/site-packages/httpx/_urlparse.pyr   ParseResult.authorityg   sz    ww'+}}4==/#"$'499$4!DII;a $))#'99#8!DII;
 	
 ?A
 	
    c                     SR                  SU R                  ;   a  SU R                   S3OU R                  U R                  b  SU R                   3/5      $ S/5      $ )Nr   r   r   r   )r   r   r   r   s    r   netlocParseResult.netlocq   sd    ww$'499$4!DII;a $))#'99#8!DII;
 	
 ?A
 	
r   kwargsc                     U(       d  U $ U R                   U R                  U R                  U R                  U R                  S.nUR                  U5        [        S0 UD6$ )Nr   r   )r   r   r   r	   r
   updateurlparse)r   r!   defaultss      r   	copy_withParseResult.copy_withz   sR    K kkIIZZ
 	'h''r   c                 ,   U R                   nSR                  U R                  (       a  U R                   S3OSU(       a  SU 3OSU R                  U R                  b  SU R                   3OSU R
                  b  SU R
                   3/5      $ S/5      $ )Nr   r   //?#)r   r   r   r   r	   r
   )r   r   s     r   __str__ParseResult.__str__   s    NN	ww%)[[4;;-q!b$-"YK 2		$(JJ$:!DJJ< '+}}'@!DMM?#
 	
 GI
 	
r    N)__name__
__module____qualname____firstlineno__str__annotations__typingOptionalintpropertyr   r   r'   r-   __static_attributes__r/   r   r   r   r   ^   s    KM
I
//#

I??3ooc""
3 
 
 
 
 
(&//#"6 (= (

 

r   r   urlr!   r   c           	      b   [        U 5      [        :  a  [        S5      e[        S U  5       5      (       a  [        S5      eSU;   a*  US   n[	        U[
        5      (       a  [        U5      OUUS'   SU;   a4  UR                  S5      =(       d    SnUR                  S5      u  US'   oAS'   S	U;   d  S
U;   a[  [        UR                  S	S5      =(       d    S5      n[        UR                  S
S5      =(       d    S5      nU(       a  U SU 3OUUS'   SU;   a@  UR                  S5      =(       d    SnUR                  S5      u  US'   oS'   U(       d  S US'   SU;   aU  UR                  S5      =(       d    Sn	SU	;   a5  U	R                  S5      (       a  U	R                  S5      (       d	  SU	 S3US'   UR                  5        H~  u  pUc  M
  [        U5      [        :  a  [        SU
 S35      e[        S U 5       5      (       a  [        SU
 S35      e[        U
   R                  U5      (       a  Mq  [        SU
 S35      e   [         R#                  U 5      nUc   eUR%                  5       nUR                  SUS   5      =(       d    SnUR                  SUS   5      =(       d    SnUR                  SUS   5      =(       d    SnUR                  SUS   5      nUR                  SUS   5      n[&        R#                  U5      nUc   eUR%                  5       nUR                  SUS   5      =(       d    SnUR                  SUS   5      =(       d    Sn	UR                  SUS   5      nUR)                  5       n[        U[*        S-   S9n[-        U	5      n[/        X.5      nUS:g  nUS:g  =(       d    US:g  =(       d    US Ln[1        UUUS9  U(       a  [3        U5      n[        U[*        S-   S9nUc  S O[        U[*        S-   S9nUc  S O[        U[*        S-   S9n[5        UUUUUUU5      $ ) NzURL too longc              3   x   #    U  H0  oR                  5       =(       a    UR                  5       (       + v   M2     g 7fNisasciiisprintable.0chars     r   	<genexpr>urlparse.<locals>.<genexpr>   s(     
E<<>4$"2"2"444   8:z,Invalid non-printable ASCII character in URLr   r   r   r   r   usernamepasswordr   raw_pathr+   r   r	   r   r   zURL component 'z
' too longc              3   x   #    U  H0  oR                  5       =(       a    UR                  5       (       + v   M2     g 7fr>   r?   rB   s     r   rE   rF      s(     O<<><$*:*:*<&<<rG   z8Invalid non-printable ASCII character in URL component ''zInvalid URL component 'r   r   r
   safe)
has_schemehas_authorityz:/[]@z:/?[]@z:/?#[]@)lenMAX_URL_LENGTHr   any
isinstancer8   r4   pop	partitionquoteget
startswithendswithitemsCOMPONENT_REGEX	fullmatch	URL_REGEXmatch	groupdictAUTHORITY_REGEXlower
SUB_DELIMSencode_hostnormalize_portvalidate_pathnormalize_pathr   )r;   r!   r   r   _rH   rI   rJ   	seperatorr   keyvalue	url_matchurl_dictr   r   r   r	   r
   authority_matchauthority_dictr   parsed_schemeparsed_userinfoparsed_hostparsed_portrO   rP   parsed_pathparsed_queryparsed_fragments                                  r   r%   r%      s.   
 3x. (( 
E
EEEGHH f~&0s&;&;Tv 6H%+,2,<,<S,A)v&> VzV3J39r:J39r:9Az8*5xz V::j)/R5=5G5G5L2v	'?"F7O zz&!'R$; 4 4s9K9K a[F6N
 lln
5zN* ?3%z!BCC OOOO NseSTU 
 #3'11%88 #:3%q!ABB %" $I   ""$H ZZ(8"45;F

;(=>D"I::fhv./52DJJw 12Ezz*hz&:;H &++I6O&&&$..0N zz*nZ&@AGRH::fnV45;D::fnV45D
  M 
S0@AO"4(K(6t(DK"$J2M!2Mk6M  $:]Kd# T
W(<=K 5Z(5J#K 
  eH:	;Q&R   r   r   c                    U (       d  g[         R                  U 5      (       a   [        R                  " U 5        U $ [        R                  U 5      (       a   [        R                  " U SS 5        U SS $ U R                  5       (       a  [        U R                  5       [        S9$  [        R                  " U R                  5       5      R                  S5      $ ! [        R                   a    [        SU < 35      ef = f! [        R                   a    [        SU < 35      ef = f! [        R                   a    [        SU < 35      ef = f)	Nr   zInvalid IPv4 address: r   zInvalid IPv6 address: rM   asciizInvalid IDNA hostname: )IPv4_STYLE_HOSTNAMEr_   	ipaddressIPv4AddressAddressValueErrorr   IPv6_STYLE_HOSTNAMEIPv6Addressr@   rW   rb   rc   idnaencodedecode	IDNAError)r   s    r   rd   rd     s0   		"	"4	(	(	@!!$' 		"	"4	(	(	@!!$q*- Abz	 TZZ\
33={{4::<(//88; ** 	@5dX>??	@ ** 	@5dX>??	@ >> =24(;<<=s#   C D '2D( $C>$D%($Er   r   c                     U b  U S:X  a  g  [        U 5      nSSSSSS.R                  U5      nX#:X  a  g U$ ! [         a    [        SU < 35      ef = f)Nr   zInvalid port:    P   i  )ftphttphttpswswss)r8   
ValueErrorr   rX   )r   r   port_as_intdefault_ports       r   re   re   J  st     |trz4$i
 rCr#NRRL "  4>$2334s	   6 Ar   rO   rP   c                     U(       a*  U (       a"  U R                  S5      (       d  [        S5      eggU R                  S5      (       a  [        S5      eU R                  S5      (       a  U(       d  [        S5      egg)z
Path validation rules that depend on if the URL contains
a scheme or authority component.

See https://datatracker.ietf.org/doc/html/rfc3986.html#section-3.3
/z7For absolute URLs, path must be empty or begin with '/'r*   zFURLs with no authority component cannot have a path starting with '//'r   zBURLs with no scheme component cannot have a path starting with ':'N)rY   r   )r   rO   rP   s      r   rf   rf   g  sy      ,,VWW -4
 ??4  X 
 ??3
T  )3r   c                     U R                  S5      n/ nU HF  nUS:X  a  M  US:X  a$  U(       a  US/:w  a  UR                  5         M1  M3  M5  UR                  U5        MH     SR                  U5      $ )zx
Drop "." and ".." segments from a URL path.

For example:

    normalize_path("/path/./to/somewhere/..") == "/path/to"
r   .z..r   )splitrU   appendr   )r   
componentsoutput	components       r   rg   rg     sm     CJ!F	$&RD.

 )v MM)$   88Fr   rD   c                     SR                  U R                  S5       Vs/ s H	  nSUS 3PM     sn5      R                  5       $ s  snf )z
Replace a single character with the percent-encoded representation.

Characters outside the ASCII range are represented with their a percent-encoded
representation of their UTF-8 byte sequence.

For example:

    percent_encode(" ") == "%20"
r   zutf-8%02x)r   r   upper)rD   bytes     r   percent_encoder     sA     77t{{7/CD/CtaSzN/CDEKKMMDs   AstringrN   c                 <    [         U-   S-   nU  H
  nX2;  d  M
    g   g)z4
Determine if a given string is already quote-safe.
r   FT)UNRESERVED_CHARACTERSr   rN   NON_ESCAPED_CHARSrD   s       r   is_safer     s.     .4s: (  r   c                     [        XS9(       a  U $ [        U-   nSR                  U  Vs/ s H  o3U;   a  UO
[        U5      PM     sn5      $ s  snf )z)
Use percent-encoding to quote a string.
rM   r   )r   r   r   r   r   s       r   percent_encodedr     sT     v!-477QWXQW**t0D	DQWX Xs   Ac                    / nSn[         R                  " [        U 5       Hg  nUR                  5       UR	                  5       peUR                  S5      nXS:w  a  XU nUR                  [        XS95        UR                  U5        UnMi     U[        U 5      :w  a  XS n	UR                  [        XS95        SR                  U5      $ )a  
Use percent-encoding to quote a string, omitting existing '%xx' escape sequences.

See: https://www.rfc-editor.org/rfc/rfc3986#section-2.1

* `string`: The string to be percent-escaped.
* `safe`: A string containing characters that may be treated as safe, and do not
    need to be escaped. Unreserved characters are always treated as safe.
    See: https://www.rfc-editor.org/rfc/rfc3986#section-2.3
r   rM   Nr   )
refinditerPERCENT_ENCODED_REGEXstartendgroupr   r   rQ   r   )
r   rN   partscurrent_positionr_   start_positionend_positionmatched_textleading_texttrailing_texts
             r   rW   rW     s     E2F;',{{}eiik{{1~-!>BLLLAB 	\"' < 3v;&01_]>?775>r   r[   c                     SR                  U  VVs/ s H  u  p[        USS9S-   [        USS9-   PM     snn5      $ s  snnf )aE  
We can use a much simpler version of the stdlib urlencode here because
we don't need to handle a bunch of different typing cases, such as bytes vs str.

https://github.com/python/cpython/blob/b2f7b2ef0b5421e01efb8c7bee2ef95d3bab77eb/Lib/urllib/parse.py#L926

Note that we use '%20' encoding for spaces. and '%2F  for '/'.
This is slightly different than `requests`, but is the behaviour that browsers use.

See
- https://github.com/encode/httpx/issues/2536
- https://github.com/encode/httpx/issues/2721
- https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode
&r   rM   =)r   r   )r[   kvs      r   	urlencoder     sQ     88 	
 AB'#-0KK	
 	
s   $=
r#   )r   )%__doc__r{   r   r6   r   _exceptionsr   rR   r   rc   compiler   formatr^   ra   r\   rz   r~   
NamedTupler   r4   r7   r%   rd   Unionr8   re   boolrf   rg   r   r   r   rW   ListTupler   r/   r   r   <module>r      s{  "  	   # I  


#45  JJ	*
 f+  	& **Tf 	  	  jj56I&JJx ZZ 

4 

7#JJ)*JJt	 jj!DE jj- 4
&## 4
nD# Dfooc&: D{ DN+=c +=c +=\
//&,,sCx0
1;>__S:  d t 6  ,N N NC s T 
C 
s 
S 
# S 3 BV[[c3h!78 S r   