o
    y¨ÊhÒ
  ã                   @   s”   d Z ddlmZmZ ddlmZmZmZ zddlZW n e	y)   ddl
mZ Y nw dZdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )zn
oauthlib.utils
~~~~~~~~~~~~~~

This module contains utility methods used by various parts of the OAuth
spec.
é    )Úabsolute_importÚunicode_literals)ÚquoteÚunicode_typeÚunquoteNÚ>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789c                    s   ‡ fdd„}ˆ j |_ |S )z§Decorator which filters params to remove non-oauth_* parameters

    Assumes the decorated method takes a params dict or list of tuples as its
    first argument.
    c                    s   t | ƒ} ˆ | g|¢R i |¤ŽS )N)Úfilter_oauth_params)ÚparamsÚargsÚkwargs©Útarget© úO/var/www/html/env/lib/python3.10/site-packages/oauthlib/oauth1/rfc5849/utils.pyÚwrapper   s   zfilter_params.<locals>.wrapper)Ú__doc__)r   r   r   r   r   Úfilter_params   s   r   c                 C   s6   dd„ }t | tƒrtt|t|  ¡ ƒƒƒS tt|| ƒƒS )zARemoves all non oauth parameters from a dict or a list of params.c                 S   s   | d   d¡S )Nr   Úoauth_)Ú
startswith)Úkvr   r   r   Ú<lambda>(   s    z%filter_oauth_params.<locals>.<lambda>)Ú
isinstanceÚdictÚlistÚfilterÚitems)r	   Úis_oauthr   r   r   r   &   s   
r   c                 C   s.   t | tƒstdd| t| ƒf  ƒ‚t| dd�S )zªEscape a unicode string in an OAuth-compatible fashion.

    Per `section 3.6`_ of the spec.

    .. _`section 3.6`: https://tools.ietf.org/html/rfc5849#section-3.6

    z$Only unicode objects are escapable. zGot %r of type %s.ó   ~)Úsafe)r   r   Ú
ValueErrorÚtyper   ©Úur   r   r   Úescape/   s
   
ÿr#   c                 C   s   t | tƒs	tdƒ‚t| ƒS )Nz%Only unicode objects are unescapable.)r   r   r   r   r!   r   r   r   Úunescape?   s   
r$   c                 C   ó
   t  | ¡S )z1A unicode-safe version of urllib2.parse_keqv_list)Úurllib2Úparse_keqv_list)Úlr   r   r   r'   E   ó   
r'   c                 C   r%   )z1A unicode-safe version of urllib2.parse_http_list)r&   Úparse_http_listr!   r   r   r   r*   K   r)   r*   c              	   C   sn   d  ¡ }| dt|ƒ…   ¡  |¡r3t| t|ƒd… ƒ}z	tt|ƒ ¡ ƒW S  ttfy2   Y tdƒ‚w tdƒ‚)z;Parse an OAuth authorization header into a list of 2-tupleszOAuth NzMalformed authorization header)	ÚlowerÚlenr   r*   r   r'   r   Ú
IndexErrorr   )Úauthorization_headerÚauth_schemer   r   r   r   Úparse_authorization_headerQ   s   þr0   )r   Ú
__future__r   r   Úoauthlib.commonr   r   r   r&   ÚImportErrorÚurllib.requestÚrequestÚUNICODE_ASCII_CHARACTER_SETr   r   r#   r$   r'   r*   r0   r   r   r   r   Ú<module>   s    ÿ	