Ë
    >²Xj4  ã                   óæ  — d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z
mZmZ ddlmZ 	 ddlmZmZ dZd	Z ej2                  d
ej4                  «      Z ej2                  d«      ZdZ ej<                  d«      Zd%d„Z	d„ Zd„ Zd„ Z d„ Z! e"e«       e"d«      z  Z#d„ Z$d„ Z%d„ Z&d„ Z'defd„Z(d„ Z)d„ Z*defd„Z+d„ Z,d&d„Z-d„ Z.d'd „Z/ G d!„ d"e0«      Z1 G d#„ d$«      Z2y# e$ r ddlmZmZ Y Œ¹w xY w)(z|
oauthlib.common
~~~~~~~~~~~~~~

This module provides data structures and utilities common
to all implementations of OAuth.
é    N)ÚquoteÚunquoteÚ	urlencodeé   )Ú	get_debug)ÚSystemRandomÚrandbits)r   ÚgetrandbitsÚ>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789z_ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}z&([^&;]*(?:password|token)[^=]*=)[^&;]+z&%[^0-9A-Fa-f]|%[0-9A-Fa-f][^0-9A-Fa-f]zAABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-Úoauthlibc                 ó¦   — t        | t        «      r| j                  d«      n| } t        | |«      } t        | t        «      r| j                  d«      } | S ©Núutf-8)Ú
isinstanceÚstrÚencodeÚ_quoteÚbytesÚdecode)ÚsÚsafes     úU/var/www/html/content_generation/venv/lib/python3.12/site-packages/oauthlib/common.pyr   r   +   sE   € Ü'¨¬3Ô/ˆ�‰�Ô°Q€AÜˆq�$‹€Aô �!”UÔØ�H‰H�WÓˆØ€Hó    c                 ó^   — t        | «      } t        | t        «      r| j                  d«      } | S r   )Ú_unquoter   r   r   )r   s    r   r   r   5   s*   € Ü�‹€Aô �!”UÔØ�H‰H�WÓˆØ€Hr   c                 ót   — t        | «      }t        |«      }t        |t        «      r|S |j	                  d«      S r   )Úencode_params_utf8Ú
_urlencoder   r   r   )ÚparamsÚutf8_paramsÚ
urlencodeds      r   r   r   ?   s7   € Ü$ VÓ,€KÜ˜KÓ(€JÜ�*œcÔ"ØÐà× Ñ  Ó)Ð)r   c                 óÈ   — g }| D ]Z  \  }}|j                  t        |t        «      r|j                  d«      n|t        |t        «      r|j                  d«      n|f«       Œ\ |S )ziEnsures that all parameters in a list of 2-element tuples are encoded to
    bytestrings using UTF-8
    r   )Úappendr   r   r   )r   ÚencodedÚkÚvs       r   r   r   H   s]   € ð €GÛ‰ˆˆ1Ø�‰Ü!+¨A¬sÔ!3ˆA�H‰H�WÔ¸Ü!+¨A¬sÔ!3ˆA�H‰H�WÔ¸ð<õ 	=ð ð €Nr   c                 óÈ   — g }| D ]Z  \  }}|j                  t        |t        «      r|j                  d«      n|t        |t        «      r|j                  d«      n|f«       Œ\ |S )zfEnsures that all parameters in a list of 2-element tuples are decoded to
    unicode using UTF-8.
    r   )r#   r   r   r   )r   Údecodedr%   r&   s       r   Údecode_params_utf8r)   T   s]   € ð €GÛ‰ˆˆ1Ø�‰Ü!+¨A¬uÔ!5ˆA�H‰H�WÔ¸1Ü!+¨A¬uÔ!5ˆA�H‰H�WÔ¸1ð>õ 	?ð ð €Nr   z=&;:%+~,*@!()/?'$c                 óò   — | r4t        | «      t        k  s"d}t        |t        | «      t        z
  | fz  «      ‚t        j	                  | «      rt        d«      ‚t        j                  | d¬«      }t        |«      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.
    z£Error 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)Úsetr!   Ú
ValueErrorÚINVALID_HEX_PATTERNÚsearchÚurlparseÚ	parse_qslr)   )ÚqueryÚerrorr   s      r   Ú	urldecoder5   c   sv   € ñ ”S˜“Z¤:Ò-ð*ˆô
 ˜¤# e£*¬zÑ"9¸5Ð!AÑAÓBÐBô ×!Ñ! %Ô(ÜÐ@ÓAÐAô ×Ñ ¸Ô>€Fô ˜fÓ%Ð%r   c                 óT  — t        | t        t        f«      r	 t        | «      }|S t        | d«      rD	 t        | «       t        t        | t        «      r| j                  «       n| «      }t        |«      }|S d}|S # t        $ r d}Y |S w xY w# t        $ r d}Y |S t        $ r d}Y |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Ú__iter__)r   r   r   r5   r.   ÚhasattrÚdictÚlistÚitemsr)   Ú	TypeError)Úrawr   s     r   Úextract_paramsr>   „   sÈ   € ô �#œœs�|Ô$ð	Ü˜s“^ˆFð  €Mô 
��jÔ	!ð	0Ü�ŒIô ¬°C¼Ô)>˜#Ÿ)™)œ+ÀCÓHˆFÜ'¨Ó/ˆFð €Mð ˆà€Møô ò 	Ø‰Fð €Mð	ûô
 ò 	Ø‰Fð €Mô ò 	Ø‰Fð €Mð	ús(   ˜A9 ²B Á9BÂBÂB'Â
B'Â&B'c                  óR   — t        t        t        d«      «      t        «       z   «      S )aâ  Generate pseudorandom nonce that is unlikely to repeat.

    Per `section 3.3`_ of the OAuth 1 RFC 5849 spec.
    Per `section 3.2.1`_ of the MAC Access Authentication spec.

    A random 64-bit number is appended to the epoch timestamp for both
    randomness and to decrease the likelihood of collisions.

    .. _`section 3.2.1`: https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-3.2.1
    .. _`section 3.3`: https://tools.ietf.org/html/rfc5849#section-3.3
    é@   )r   r	   Úgenerate_timestamp© r   r   Úgenerate_noncerC   ¡   s!   € ô Œs”8˜B“<Ó Ô#5Ó#7Ñ7Ó8Ð8r   c                  óN   — t        t        t        j                  «       «      «      S )aD  Get seconds since epoch (UTC).

    Per `section 3.3`_ of the OAuth 1 RFC 5849 spec.
    Per `section 3.2.1`_ of the MAC Access Authentication spec.

    .. _`section 3.2.1`: https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-3.2.1
    .. _`section 3.3`: https://tools.ietf.org/html/rfc5849#section-3.3
    )r   ÚintÚtimerB   r   r   rA   rA   °   s   € ô Œs”4—9‘9“;ÓÓ Ð r   é   c                 ób   ‡‡— t        «       Šdj                  ˆˆfd„t        | «      D «       «      S )aX  Generates a non-guessable OAuth token

    OAuth (1 and 2) does not specify the format of tokens except that they
    should be strings of random characters. Tokens should not be guessable
    and entropy when generating the random characters is important. Which is
    why SystemRandom is used instead of the default random.choice method.
    Ú c              3   ó@   •K  — | ]  }‰j                  ‰«      –— Œ y ­w©N)Úchoice)Ú.0ÚxÚcharsÚrands     €€r   Ú	<genexpr>z!generate_token.<locals>.<genexpr>Å   s   øè ø€ Ð=©}¨!�4—;‘;˜u×%©}ùs   ƒ)r   ÚjoinÚrange)ÚlengthrO   rP   s    `@r   Úgenerate_tokenrU   ¼   s%   ù€ ô ‹>€DØ�7‰7Ô=¬u°V¬}Ó=Ó=Ð=r   c                 ó  — dd l }t        j                  j                  «       }|j                  |t        j                  |j
                  ¬«      z   dœ}|j                  |j                  «       |j                  || d«      }t        |d«      }|S )Nr   )Úseconds)ÚscopeÚexpÚRS256úUTF-8)
ÚjwtÚdatetimeÚutcnowrX   Ú	timedeltaÚ
expires_inÚupdateÚclaimsr   Ú
to_unicode)Úprivate_pemÚrequestr\   Únowrb   Útokens         r   Úgenerate_signed_tokenrh   È   sw   € Ûä
×
Ñ
×
"Ñ
"Ó
$€Cð —‘Ø”X×'Ñ'°×0BÑ0BÔCÑCñ€Fð
 ‡M�M�'—.‘.Ô!à�J‰J�v˜{¨GÓ4€EÜ�u˜gÓ&€Eà€Lr   c                 ó4   — dd l }|j                  || dg¬«      S )Nr   rZ   )Ú
algorithms)r\   r   )Ú
public_pemrg   r\   s      r   Úverify_signed_tokenrl   Ú   s   € Ûà�:‰:�e˜Z°W°Iˆ:Ó>Ð>r   c                 ó   — t        | |«      S )z…Generates an OAuth client_id

    OAuth 2 specify the format of client_id in
    https://tools.ietf.org/html/rfc6749#appendix-A.
    )rU   )rT   rO   s     r   Úgenerate_client_idrn   à   s   € ô ˜& %Ó(Ð(r   c                 ó¨   — t        |t        «      r|j                  «       }t        j                  | d¬«      }|j                  |«       t        |«      S )z)Extend a query with a list of two-tuples.Tr+   )r   r9   r;   r1   r2   Úextendr   )r3   r   Úqueryparamss      r   Úadd_params_to_qsrr   é   sB   € ä�&œ$ÔØ—‘“ˆÜ×$Ñ$ U¸dÔC€KØ×Ñ�vÔÜ�[Ó!Ð!r   c                 ó¦   — t        j                   | «      \  }}}}}}|rt        ||«      }nt        ||«      }t        j                  ||||||f«      S )z5Add a list of two-tuples to the uri query components.)r1   rr   Ú
urlunparse)	Úurir   ÚfragmentÚschÚnetÚpathÚparr3   Úfras	            r   Úadd_params_to_urir|   ò   sX   € ä&.×&7Ñ&7¸Ó&<Ñ#€Cˆˆd�C˜ ÙÜ˜s FÓ+‰ä  ¨Ó/ˆÜ×Ñ  S¨$°°U¸CÐ@ÓAÐAr   c                 óœ   — t        | «      t        |«      k7  ryd}t        | |«      D ]  \  }}|t        |«      t        |«      z  z  }Œ! |dk(  S )a   Near-constant time string comparison.

    Used in order to avoid timing attacks on sensitive information such
    as secret keys during request verification (`rootLabs`_).

    .. _`rootLabs`: http://rdist.root.org/2010/01/07/timing-independent-array-comparison/

    Fr   )ÚlenÚzipÚord)ÚaÚbÚresultrN   Úys        r   Úsafe_string_equalsr…   ü   sP   € ô ˆ1ƒv”�Q“ÒØà€FÜ�A�q–	‰ˆˆ1Ø”#�a“&œ3˜q›6‘/Ñ!‰ð à�Q‰;Ðr   c           	      óx  ‡— t        | t        «      r| S t        | t        «      rt        | ‰¬«      S t        | d«      rR	 t	        | «       t        | d«      r| j                  «       } | D ��ci c]  \  }}t        |‰«      t        |‰«      “Œ c}}S | S c c}}w # t        $ r Y | S t        $ r ˆfd„| D «       cY S w xY w)z:Convert a number of different types of objects to unicode.)Úencodingr7   r;   c              3   ó6   •K  — | ]  }t        |‰«      –— Œ y ­wrK   ©rc   )rM   Úir‡   s     €r   rQ   zto_unicode.<locals>.<genexpr>  s   øè ø€ Ð:±T°”J˜q (×+±Tùs   ƒ)	r   r   r   r8   r9   r;   rc   r<   r.   )Údatar‡   r%   r&   s    `  r   rc   rc     sÀ   ø€ ä�$œÔØˆä�$œÔÜ�4 (Ô+Ð+äˆt�ZÔ ð	WÜ�ŒJô �t˜WÔ%Ø—z‘z“|�ÙQUÔVÑQUÉÈÈA”J˜q (Ó+¬Z¸¸8Ó-DÑDÐQUÒVÐVà€Kùó Wøô ò 	Øð €Kô ò 	;ã:±TÓ:Ò:ð	;ús   ¾B Á*!BÂ	B9Â#B9Â8B9c                   óX   ‡ — e Zd ZdZi Zd„ Zd„ Zˆ fd„Zˆ fd„Zd	d„Z	ˆ fd„Z
ˆ fd„Zˆ xZS )
ÚCaseInsensitiveDictz3Basic case insensitive dict with strings only keys.c                 ót   — |D �ci c]  }|j                  «       |“Œ c}| _        |D ]
  }||   | |<   Œ y c c}w rK   ©ÚlowerÚproxy)Úselfr‹   r%   s      r   Ú__init__zCaseInsensitiveDict.__init__-  s>   € Ù,0Ó1©D q�a—g‘g“i ‘l¨DÑ1ˆŒ
ÛˆAØ˜1‘gˆD�ŠGñ ùò 2s   …5c                 ó:   — |j                  «       | j                  v S rK   r�   )r’   r%   s     r   Ú__contains__z CaseInsensitiveDict.__contains__2  s   € Ø�w‰w‹y˜DŸJ™JÐ&Ð&r   c                 ó”   •— | j                   |j                  «          }t        ‰| �  |«       | j                   |j                  «       = y rK   )r‘   r�   ÚsuperÚ__delitem__©r’   r%   ÚkeyÚ	__class__s      €r   r˜   zCaseInsensitiveDict.__delitem__5  s6   ø€ Ø�j‰j˜Ÿ™›Ñ#ˆÜ‰Ñ˜CÔ Ø�J‰J�q—w‘w“yÑ!r   c                 ó\   •— | j                   |j                  «          }t        ‰| �  |«      S rK   )r‘   r�   r—   Ú__getitem__r™   s      €r   r�   zCaseInsensitiveDict.__getitem__:  s'   ø€ Ø�j‰j˜Ÿ™›Ñ#ˆÜ‰wÑ" 3Ó'Ð'r   c                 ó   — || v r| |   S |S rK   rB   )r’   r%   Údefaults      r   ÚgetzCaseInsensitiveDict.get>  s   € Ø˜t™)ˆt�A‰wÐ0¨Ð0r   c                 ó`   •— t         ‰| �  ||«       || j                  |j                  «       <   y rK   )r—   Ú__setitem__r‘   r�   )r’   r%   r&   r›   s      €r   r¢   zCaseInsensitiveDict.__setitem__A  s&   ø€ Ü‰Ñ˜A˜qÔ!Ø !ˆ�
‰
�1—7‘7“9Òr   c                 ó~   •— t        ‰| �  |i |¤Ž t        |i |¤ŽD ]  }|| j                  |j	                  «       <   Œ! y rK   )r—   ra   r9   r‘   r�   )r’   ÚargsÚkwargsr%   r›   s       €r   ra   zCaseInsensitiveDict.updateE  s<   ø€ Ü‰‰˜Ð' Ò'Ü�tÐ&˜vÔ&ˆAØ$%ˆD�J‰J�q—w‘w“yÒ!ñ 'r   rK   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r‘   r“   r•   r˜   r�   r    r¢   ra   Ú__classcell__)r›   s   @r   r�   r�   '  s3   ø„ á=à€Eòò
'ô"ô
(ó1ô"÷&ð &r   r�   c                   óX   — e Zd ZdZ	 	 d	d„Zd„ Zd„ Zed„ «       Zed„ «       Z	ed„ «       Z
y)
ÚRequesta:  A malleable representation of a signable HTTP request.

    Body argument may contain any data, but parameters will only be decoded if
    they are one of:

    * urlencoded query string
    * dict
    * list of 2-tuples

    Anything else will be treated as raw body data to be passed through
    unmolested.
    Nc                 óH  ‡— ˆfd„} ||«      | _          ||«      | _        t         ||xs i «      «      | _         ||«      | _        t        | j                  «      | _        g | _        i | _        i dd “dd “dd “dd “dd “dd “dd “d	d “d
d “dd “dd “dd “dd “dd “dd “dd “dd “d d d d d d d d d d d d d dœ¥| _	        | j                  j                  t        t        | j                  «      «      «       | j                  j                  t        | j                  xs g «      «       y )Nc                 ó$   •— ‰rt        | ‰«      S | S rK   r‰   )rN   r‡   s    €r   r   z Request.__init__.<locals>.encode]  s   ø€ Ù.6”:˜a Ó*Ð=¸AÐ=r   Úaccess_tokenÚclientÚ	client_idÚclient_secretÚcodeÚcode_challengeÚcode_challenge_methodÚcode_verifierÚextra_credentialsÚ
grant_typeÚredirect_uriÚrefresh_tokenÚrequest_tokenÚresponse_typerX   ÚscopesÚstate)rg   ÚuserÚtoken_type_hintÚresponse_modeÚnonceÚdisplayÚpromptrb   Úmax_ageÚ
ui_localesÚid_token_hintÚ
login_hintÚ
acr_values)ru   Úhttp_methodr�   ÚheadersÚbodyr>   Údecoded_bodyÚoauth_paramsÚvalidator_logÚ_paramsra   r9   r5   Ú	uri_query)r’   ru   rÊ   rÌ   rË   r‡   r   s        ` r   r“   zRequest.__init__Z  sª  ø€ ô	>ñ ˜#“;ˆŒÙ! +Ó.ˆÔÜ*©6°'²-¸RÓ+@ÓAˆŒÙ˜4“LˆŒ	Ü*¨4¯9©9Ó5ˆÔØˆÔØˆÔð!
Ø˜Dð!
à�dð!
ð ˜ð!
ð ˜Tð	!
ð
 �Dð!
ð ˜dð!
ð $ Tð!
ð ˜Tð!
ð   ð!
ð ˜$ð!
ð ˜Dð!
ð ˜Tð!
ð ˜Tð!
ð ˜Tð!
ð �Tð!
ð  �dð!!
ð" �Tð#!
ð$ ØØ#ð "ØØØØØØØ!ØØòA!
ˆŒðD 	�‰×ÑœD¤¨4¯>©>Ó!:Ó;Ô<Ø�‰×ÑœD ×!2Ñ!2Ò!8°bÓ9Õ:r   c                 óR   — || j                   v r| j                   |   S t        |«      ‚rK   )rÐ   ÚAttributeError)r’   Únames     r   Ú__getattr__zRequest.__getattr__�  s(   € Ø�4—<‘<ÑØ—<‘< Ñ%Ð%ä  Ó&Ð&r   c                 ó  — t        «       sy| j                  }| j                  j                  «       }|rt        j                  dt        |«      «      }d|v rd|d<   dj                  | j                  | j                  ||«      S )Nz<oauthlib.Request SANITIZED>z<SANITIZED>ÚAuthorizationz<SANITIZED>zF<oauthlib.Request url="{}", http_method="{}", headers="{}", body="{}">)
r   rÌ   rË   ÚcopyÚSANITIZE_PATTERNÚsubr   Úformatru   rÊ   )r’   rÌ   rË   s      r   Ú__repr__zRequest.__repr__“  sv   € ÜŒ{Ø1Ø�y‰yˆØ—,‘,×#Ñ#Ó%ˆÙÜ#×'Ñ'¨¼¸T»ÓCˆDØ˜gÑ%Ø'4ˆG�OÑ$ØW×^Ñ^Ø�H‰H�d×&Ñ&¨°ó7ð 	7r   c                 óT   — t        j                   | j                  «      j                  S rK   )r1   ru   r3   ©r’   s    r   rÑ   zRequest.uri_queryŸ  s   € ä× Ñ  §¡Ó*×0Ñ0Ð0r   c                 ób   — | j                   sg S t        j                  | j                   dd¬«      S )NT)r,   Ústrict_parsing)rÑ   r1   r2   rÞ   s    r   Úuri_query_paramszRequest.uri_query_params£  s,   € à�~Š~ØˆIÜ×!Ñ! $§.¡.ÀDØ15ô7ð 	7r   c                 ó  — t        j                  t        «      }d„ | j                  xs g | j                  z   D «       }|D ]  }||xx   dz  cc<   Œ |j                  «       D ��cg c]  \  }}|dkD  sŒ|‘Œ c}}S c c}}w )Nc              3   ó&   K  — | ]	  }|d    –— Œ y­w)r   NrB   )rM   Úps     r   rQ   z+Request.duplicate_params.<locals>.<genexpr>­  s   è ø€ ð PÙN˜ð �a•DÙNùs   ‚r   )ÚcollectionsÚdefaultdictrE   rÍ   rá   r;   )r’   Ú	seen_keysÚall_keysr%   Úcs        r   Úduplicate_paramszRequest.duplicate_paramsª  s|   € ä×+Ñ+¬CÓ0ˆ	ñPØ"×/Ñ/Ò5°2¸×9NÑ9NÒNóPˆãˆAØ�a‹L˜AÑŒLð à'Ÿo™oÔ/Ô9Ñ/‘d�a˜°1°q³5’Ð/Ò9Ð9ùÓ9s   Á%A;Á3A;)ÚGETNNr   )r¦   r§   r¨   r©   r“   rÕ   rÜ   ÚpropertyrÑ   rá   rê   rB   r   r   r¬   r¬   K  s]   „ ñð CGØ!ó1;òf'ò
7ð ñ1ó ð1ð ñ7ó ð7ð ñ:ó ñ:r   r¬   )ó   /)F)r[   )3r©   rå   r]   ÚloggingÚrerF   Úurllib.parseÚparser1   r   r   r   r   r   r   rI   r   Úsecretsr   r	   ÚImportErrorÚrandomr
   ÚUNICODE_ASCII_CHARACTER_SETÚCLIENT_ID_CHARACTER_SETÚcompileÚ
IGNORECASErÙ   r/   Úalways_safeÚ	getLoggerÚlogr   r)   r-   r!   r5   r>   rC   rA   rU   rh   rl   rn   rr   r|   r…   rc   r9   r�   r¬   rB   r   r   Ú<module>rü      s<  ðñó Û Û Û 	Û Ý ÷ñ õ ð=ß.ð ,Ð ðNÐ ð �2—:‘:ÐGÈÏÉÓWÐ Ø �b—j‘jÐ!JÓKÐ ð€ð €g×Ñ˜
Ó#€óòò*ò	ò	ñ �Ó¡Ð$8Ó 9Ñ9€
ò&òBò:9ò	!ð Ð$?ó 	>òò$?ð !Ð(?ó )ò"óBòó$ô2!&˜$ô !&÷Hf:ò f:øðk	 ò =ß<Ñ<ð=ús   ®C  Ã C0Ã/C0