
    k7i                         S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r
  SSKJr  SSKJr  S	r\" \5      \" S
5      -  r\R"                  " S5      rS rS rS rSS jrSS jrS rS rS rSS\4S jjrg)zWauthlib.util.urls.
~~~~~~~~~~~~~~~~~

Wrapper functions for URL encoding and decoding.
    Nquote)unquote)	urlencode   )to_bytes)
to_unicodezAABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-z=&;:%+~,*@!()/?z&%[^0-9A-Fa-f]|%[0-9A-Fa-f][^0-9A-Fa-f]c                     / nU  H*  u  p#UR                  [        U5      [        U5      45        M,     [        [        U5      5      $ N)appendr   r	   
_urlencode)paramsencodedkvs       M/home/james-whalen/.local/lib/python3.13/site-packages/authlib/common/urls.py
url_encoder      s<    GXa[12 j)**    c                 V   U (       a5  [        U 5      [        ::  d"  Sn[        U[        U 5      [        -
  U 4-  5      e[        R	                  U 5      (       a  [        S5      e[
        R                  " U SS9n/ nU H*  u  pEUR                  [        U5      [        U5      45        M,     U$ )aj  Decode a query string in x-www-form-urlencoded format into a sequence
of two-element tuples.

Unlike urlparse.parse_qsl(..., strict_parsing=True) urldecode will enforce
correct formatting of the query string by validation. If validation fails
a ValueError will be raised. urllib.parse_qsl will only raise errors if
any of name-value pairs omits the equals sign.
zError trying to decode a non urlencoded string. Found invalid characters: %s in the string: '%s'. Please ensure the request/response body is x-www-form-urlencoded.z%Invalid hex encoding in query string.Tkeep_blank_values)	set
urlencoded
ValueErrorINVALID_HEX_PATTERNsearchurlparse	parse_qslr   r	   )queryerrorr   decodedr   r   s         r   
url_decoder"      s     SZ:-% 	 #e*z"95!AABB !!%((@AA& >F G
1z!}56 Nr   c                     [        U[        5      (       a  UR                  5       n[        R                  " U SS9nUR                  U5        [        U5      $ )z)Extend a query with a list of two-tuples.Tr   )
isinstancedictitemsr   r   extendr   )r   r   qss      r   add_params_to_qsr)   Q   sB    &$			ET	:BIIfb>r   c                     [         R                   " U 5      u  p4pVpxU(       a  [        X5      nO[        Xq5      n[         R                  " X4XVXx45      $ )z5Add a list of two-tuples to the uri query components.)r   r)   
urlunparse)	urir   fragmentschnetpathparr   fras	            r   add_params_to_urir3   [   sH    &.&7&7&<#Cds+ /$U@AAr   c                 >    [        [        [        U 5      U5      5      $ r   )r	   _quoter   )ssafes     r   r   r   e   s    fXa[$/00r   c                 *    [        [        U 5      5      $ r   )r	   _unquoter6   s    r   r   r   i   s    hqk""r   c                     [        U S5      $ )Ns   ~@#$&()*!+=:;,.?/'r   r:   s    r   	quote_urlr<   m   s    )**r   c                 r   [        U [        [        45      (       a   [        U 5      n [        U [        5      (       aB  / nU R                  5        H*  u  p#UR                  [        U5      [        U5      45        M,     U$ U (       d  g [        U 5      $ ! [        [
        4 a     gf = f! [
         a     gf = f)a  Extract parameters and return them as a list of 2-tuples.

Will successfully extract parameters from urlencoded query strings,
dicts, or lists of 2-tuples. Empty strings/dicts/lists will return an
empty list of parameters. Any other input will result in a return
value of None.
N)
r$   listtupler%   	TypeErrorr   r&   r   r	   r"   )rawr   r   r   s       r   extract_paramsrB   q   s     #e}%%	s)C #tIIKDAMM:a=*Q-89  # :& 		  s#   B 
B) B&%B&)
B65B6urlc                     [         R                   " U 5      nUR                  =(       a-    UR                  =(       a    U=(       d    UR                  (       + $ r   )r   schemehostnamer-   )rC   fragments_allowedparseds      r   is_valid_urlrI      s9    s#FX&//X/@/WDWr   )F)   /)T)__doc__reurllib.parseparser   r   r5   r   r9   r   r   encodingr   r	   always_safer   r   compiler   r   r"   r)   r3   r<   rB   strrI    r   r   <module>rT      s    
  ( , 0   Q$5 66
jj!JK +2jB1#+:c r   