
    ~h                     R    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddZd	 Zd
 Z	d Z
y)zauthlib.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
    )extract_params)
url_encode)urlparse   )escapeNc                     |xs i }dj                  | D cg c]0  \  }}|j                  d      rt        |       dt        |       d2 c}}      }|r	d| d|z   }d| |d<   |S c c}}w )	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, oauth_z=""zrealm="z", zOAuth Authorization)join
startswithr   )oauth_paramsheadersrealmkvheader_parameterss         ]/opt/mcp/mcp-sentiment/venv/lib/python3.12/site-packages/authlib/oauth1/rfc5849/parameters.pyprepare_headersr      s    , mG 		 %	
1||H% aykF1I;a(	
 %eWC03DD "((9':;GON#	
s   5A)
c                 d    t        |      }|j                  |        |j                  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                 *    | d   j                  d      S )Nr   r	   )r   )is    r   <lambda>z _append_params.<locals>.<lambda>O   s    adooh7     )key)listextendsort)r   paramsmergeds      r   _append_paramsr!   >   s/     &\F
MM,
 KK7K8Mr   c                 ,    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   bodys     r   prepare_form_encoded_bodyr$   S   s     n\4899r   c                     t        j                   |      \  }}}}}}t        t        | t        |      xs g             }t        j                  ||||||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fras           r   prepare_request_uri_queryr.   _   sZ     '/&7&7&<#CdC~lN54I4ORPQES$UC@AAr   )NN)__doc__authlib.common.urlsr   r   r   utilr   r   r!   r$   r.    r   r   <module>r3      s.    / * ( +\*	:Br   