ó
O'^c           @@ 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 n Xd d l m	 Z	 d d l
 m Z m Z e	 j d d d   Z d   Z d	   Z d
   Z d S(   už   
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
i    (   t   absolute_importt   unicode_literals(   t   urlparset
   urlunparsei   (   t   utils(   t   extract_paramst	   urlencodec         C@ s·   | p	 i  } g  } xQ |  D]I \ } } t  j |  } t  j |  } d j | |  } | j |  q Wd j |  }	 | r d | |	 }	 n  d |	 }
 i  } | j |  |
 | d <| S(   u  **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
    u	   {0}="{1}"u   , u   realm="%s", u   OAuth %su   Authorization(   R   t   escapet   formatt   appendt   joint   update(   t   oauth_paramst   headerst   realmt%   authorization_header_parameters_partst   oauth_parameter_namet   valuet   escaped_namet   escaped_valuet   partt   authorization_header_parameterst   authorization_headert   full_headers(    (    sD   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/parameters.pyt   prepare_headers   s"    	


c         C@ s0   t  |  } | j |   | j d d    | S(   u<  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

    t   keyc         S@ s   |  d j  d  S(   Ni    u   oauth_(   t
   startswith(   t   i(    (    sD   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/parameters.pyt   <lambda>m   t    (   t   listt   extendt   sort(   R   t   paramst   merged(    (    sD   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/parameters.pyt   _append_params\   s    c         C@ s   t  |  |  S(   u   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   t   body(    (    sD   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/parameters.pyt   prepare_form_encoded_bodyq   s    	c         C@ s[   t  |  \ } } } } } } t t |  t |  p6 g    } t | | | | | | f  S(   u   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   t   urit   scht   nett   patht   part   queryt   fra(    (    sD   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/parameters.pyt   prepare_request_uri_query}   s    	N(   t   __doc__t
   __future__R    R   R   R   t   ImportErrort   urllib.parseR   R   t   oauthlib.commonR   R   t   filter_paramst   NoneR   R#   R%   R-   (    (    (    sD   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/parameters.pyt   <module>	   s   E		