
    '[f                         d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z
 ddlmZmZ dZ ee           ed	          z  Z ej        d
          Zd Zd Zd ZddZddZd Zd Zd Zd ZdS )zc
    authlib.util.urls
    ~~~~~~~~~~~~~~~~~

    Wrapper functions for URL encoding and decoding.
    Nquote)unquote)	urlencode   )
to_unicodeto_byteszAABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-z=&;:%+~,*@!()/?z&%[^0-9A-Fa-f]|%[0-9A-Fa-f][^0-9A-Fa-f]c                     g }| D ]6\  }}|                     t          |          t          |          f           7t          t          |                    S N)appendr	   r   
_urlencode)paramsencodedkvs       G/var/www/piapp/venv/lib/python3.11/site-packages/authlib/common/urls.py
url_encoder      sV    G 3 31Xa[[12222j))***    c                    | rCt          |           t          k    s+d}t          |t          |           t          z
  | fz            t                              |           rt          d          t          j        | d          }g }|D ]6\  }}|                    t          |          t          |          f           7|S )a  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      CSZZ:--*
 #e**z"95!AABBB !!%(( B@AAA& >>>F G 7 71
1z!}}56666Nr   c                     t          |t                    r|                                }t          j        | d          }|                    |           t          |          S )z)Extend a query with a list of two-tuples.Tr   )
isinstancedictitemsr   r   extendr   )r   r   qss      r   add_params_to_qsr)   S   sT    &$  		ET	:	:	:BIIfb>>r   Fc                     t          j         |           \  }}}}}}|rt          ||          }nt          ||          }t          j        ||||||f          S )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   ]   se    &.&7&<&<#CdC 0sF++ //S$UC@AAAr      /c                 V    t          t          t          |           |                    S r   )r   _quoter	   )ssafes     r   r   r   g   s     fXa[[$//000r   c                 :    t          t          |                     S r   )r   _unquoter7   s    r   r   r   k   s    hqkk"""r   c                 "    t          | d          S )Ns   ~@#$&()*!+=:;,.?/'r   r;   s    r   	quote_urlr=   o   s    *+++r   c                    t          | t          t          f          r)	 t          |           } n# t          t
          f$ r Y dS w xY wt          | t                    rOg }|                                 D ]6\  }}|                    t          |          t          |          f           7|S | sdS 	 t          |           S # t
          $ r Y dS w xY w)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_paramsrC   s   s     #e}%% 	s))CC:& 	 	 	44	 #t IIKK 	: 	:DAqMM:a==*Q--89999 t#   tts!   . AA/B> >
CCc                 F    t          j         |           }|j        o|j        S r   )r   schemehostname)urlparseds     r   is_valid_urlrI      s!    s##F=,V_,r   )F)r4   )__doc__reurllib.parser   r6   r   r:   r   r   parser   encodingr   r	   always_safer   r   compiler   r   r"   r)   r3   r=   rC   rI    r   r   <module>rR      sX    
			 ( ( ( ( ( ( , , , , , , 0 0 0 0 0 0       * * * * * * * * 
 S$5 6 66
 bj!JKK + + +0 0 0f  B B B B1 1 1 1# # #, , ,  :- - - - -r   