
    !<i                         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 ddl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defdZdS )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                     g }| D ]6\  }}|                     t          |          t          |          f           7t          t          |                    S N)appendr   r	   
_urlencode)paramsencodedkvs       /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.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)   Q   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   e   s     fXa[[$//000r   c                 :    t          t          |                     S r   )r	   _unquoter7   s    r   r   r   i   s    hqkk"""r   c                 "    t          | d          S )Ns   ~@#$&()*!+=:;,.?/'r   r;   s    r   	quote_urlr=   m   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   q   s     #e}%% 	s))CC:& 	 	 	44	 #t IIKK 	: 	:DAqMM:a==*Q--89999 t#   tts!   . AA/B> >
CCTurlc                 Z    t          j         |           }|j        o|j        o	|p|j         S r   )r   schemehostnamer-   )rD   fragments_allowedparseds      r   is_valid_urlrJ      s3    s##FX&/X/@/WDWr   )F)r4   )T)__doc__reurllib.parseparser   r   r6   r   r:   r   r   encodingr   r	   always_safer   r   compiler   r   r"   r)   r3   r=   rC   strrJ    r   r   <module>rT      sn    
			       ( ( ( ( ( ( , , , , , , 0 0 0 0 0 0                  QS$5 6 66
 bj!JKK + + +2 2 2j  B B B B1 1 1 1# # #+ + +  : c      r   