o
    Df                     @   sJ   d Z ddlmZmZmZ ddlmZ dddZdd	 Zd
d Z	dd Z
dS )z
    authlib.spec.rfc5849.parameters
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    This module contains methods related to `section 3.5`_ of the OAuth 1.0a spec.

    .. _`section 3.5`: https://tools.ietf.org/html/rfc5849#section-3.5
    )urlparse
url_encodeextract_params   )escapeNc                 C   sB   |pi }d dd | D }|rd| d| }d| |d< |S )a  **Prepare the Authorization header.**
    Per `section 3.5.1`_ of the spec.

    Protocol parameters can be transmitted using the HTTP "Authorization"
    header field as defined by `RFC2617`_ with the auth-scheme name set to
    "OAuth" (case insensitive).

    For example::

        Authorization: OAuth realm="Photos",
            oauth_consumer_key="dpf43f3p2l4k3l03",
            oauth_signature_method="HMAC-SHA1",
            oauth_timestamp="137131200",
            oauth_nonce="wIjqoS",
            oauth_callback="http%3A%2F%2Fprinter.example.com%2Fready",
            oauth_signature="74KNZJeDHnMBp0EMJ9ZHt%2FXKycU%3D",
            oauth_version="1.0"

    .. _`section 3.5.1`: https://tools.ietf.org/html/rfc5849#section-3.5.1
    .. _`RFC2617`: https://tools.ietf.org/html/rfc2617
    z, c                 S   s2   g | ]\}}| d rt| dt| dqS )oauth_z="")
startswithr   ).0kv r   Z/home/ubuntu/webapp/venv/lib/python3.10/site-packages/authlib/oauth1/rfc5849/parameters.py
<listcomp>&   s    z#prepare_headers.<locals>.<listcomp>zrealm="z", zOAuth Authorization)join)oauth_paramsheadersrealmheader_parametersr   r   r   prepare_headers   s   
	r   c                 C   s&   t |}||  |jdd d |S )a>  Append OAuth params to an existing set of parameters.

    Both params and oauth_params is must be lists of 2-tuples.

    Per `section 3.5.2`_ and `3.5.3`_ of the spec.

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

    c                 S   s   | d  dS )Nr   r   )r	   )ir   r   r   <lambda>I   s    z _append_params.<locals>.<lambda>)key)listextendsort)r   paramsmergedr   r   r   _append_params8   s   
r   c                 C   s   t t| |S )zPrepare the Form-Encoded Body.

    Per `section 3.5.2`_ of the spec.

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

    )r   r   )r   bodyr   r   r   prepare_form_encoded_bodyM   s   	r!   c                 C   sB   t  |\}}}}}}tt| t|pg }t ||||||fS )zPrepare the Request URI Query.

    Per `section 3.5.3`_ of the spec.

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

    )r   r   r   r   
urlunparse)r   urischnetpathparqueryfrar   r   r   prepare_request_uri_queryY   s
   	r*   )NN)__doc__authlib.common.urlsr   r   r   utilr   r   r   r!   r*   r   r   r   r   <module>   s    
+