
?`«UU  ã               @   sÊ   d  Z  d d l m Z m Z y d d l m Z m Z Wn( e k
 r` d d l m Z m Z Yn Xd d l m	 Z	 d d l
 m Z m Z e	 j d d d d	 „ ƒ Z d
 d „  Z d d „  Z d d „  Z d S)z¼
oauthlib.parameters
~~~~~~~~~~~~~~~~~~~

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

.. _`section 3.5`: http://tools.ietf.org/html/rfc5849#section-3.5
é    )Úabsolute_importÚunicode_literals)ÚurlparseÚ
urlunparseé   )Úutils)Úextract_paramsÚ	urlencodeNc             C   s´   | p	 i  } g  } xQ |  D]I \ } } t  j | ƒ } t  j | ƒ } d j | | ƒ } | j | ƒ q Wd j | ƒ }	 | r‰ d | |	 }	 d |	 }
 i  } | j | ƒ |
 | 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="Example",
            oauth_consumer_key="0685bd9184jfhq22",
            oauth_token="ad180jjd733klru7",
            oauth_signature_method="HMAC-SHA1",
            oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D",
            oauth_timestamp="137131200",
            oauth_nonce="4572616e48616d6d65724c61686176",
            oauth_version="1.0"


    .. _`section 3.5.1`: http://tools.ietf.org/html/rfc5849#section-3.5.1
    .. _`RFC2617`: http://tools.ietf.org/html/rfc2617
    z	{0}="{1}"z, zrealm="%s", zOAuth %sZAuthorization)r   ÚescapeÚformatÚappendÚjoinÚupdate)Úoauth_paramsZheadersZrealmZ%authorization_header_parameters_partsZoauth_parameter_nameÚvalueZescaped_nameZescaped_valueÚpartZauthorization_header_parametersZauthorization_headerZfull_headers© r   úD/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/parameters.pyÚprepare_headers   s"    	

r   c             C   s3   t  | ƒ } | j |  ƒ | 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`: http://tools.ietf.org/html/rfc5849#section-3.5.2
    .. _`3.5.3`: http://tools.ietf.org/html/rfc5849#section-3.5.3

    Úkeyc             S   s   |  d j  d ƒ S)Nr   Zoauth_)Ú
startswith)Úir   r   r   Ú<lambda>m   s    z _append_params.<locals>.<lambda>)ÚlistÚextendÚsort)r   ZparamsZmergedr   r   r   Ú_append_params\   s    r   c             C   s   t  |  | ƒ S)z–Prepare the Form-Encoded Body.

    Per `section 3.5.2`_ of the spec.

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

    )r   )r   Zbodyr   r   r   Úprepare_form_encoded_bodyq   s    	r   c             C   s[   t  | ƒ \ } } } } } } t t |  t | ƒ p6 g  ƒ ƒ } t | | | | | | f ƒ S)z–Prepare the Request URI Query.

    Per `section 3.5.3`_ of the spec.

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

    )r   r	   r   r   r   )r   ZuriZschZnetÚpathZparZqueryZfrar   r   r   Úprepare_request_uri_query}   s    	r   )Ú__doc__Z
__future__r   r   r   r   ÚImportErrorZurllib.parseÚ r   Zoauthlib.commonr   r	   Zfilter_paramsr   r   r   r   r   r   r   r   Ú<module>	   s   E