ó
O'^c           @@ sq   d  Z  d d l m Z m Z d d l Z d d l m Z d d l m Z e j	 e
  Z d e f d	     YZ d S(
   uş   
oauthlib.oauth1.rfc5849.endpoints.resource
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This module is an implementation of the resource protection provider logic of
OAuth 1.0 RFC 5849.
i    (   t   absolute_importt   unicode_literalsNi   (   t   BaseEndpointi   (   t   errorst   ResourceEndpointc           B@ s#   e  Z d  Z d d d d d  Z RS(   u!  An endpoint responsible for protecting resources.

    Typical use is to instantiate with a request validator and invoke the
    ``validate_protected_resource_request`` in a decorator around a view
    function. If the request is valid, invoke and return the response of the
    view. If invalid create and return an error response directly from the
    decorator.

    See :doc:`/oauth1/validator` for details on which validator methods to implement
    for this endpoint.

    An example decorator::

        from functools import wraps
        from your_validator import your_validator
        from oauthlib.oauth1 import ResourceEndpoint
        endpoint = ResourceEndpoint(your_validator)

        def require_oauth(realms=None):
            def decorator(f):
                @wraps(f)
                def wrapper(request, *args, **kwargs):
                    v, r = provider.validate_protected_resource_request(
                            request.url,
                            http_method=request.method,
                            body=request.data,
                            headers=request.headers,
                            realms=realms or [])
                    if v:
                        return f(*args, **kwargs)
                    else:
                        return abort(403)
    u   GETc         C@ s-  y |  j  | | | |  } Wn t j k
 r9 t d f SXy |  j |  |  j |  Wn t j k
 ru t | f SX| j s t | f S|  j j	 | j  s¨ t | f S|  j j
 | j | j | j | d | j sß t | f S|  j j | j |  } | s|  j j | _ n  |  j j | j | j |  } | sE|  j j | _ n  |  j j | j | j | d | j d | }	 |  j |  }
 | | j d <| | j d <|	 | j d <|
 | j d <t | | |	 |
 f  } | s#t j d  t j d	 |  t j d
 |  t j d |	  t j d |
  n  | | f S(   u  Create a request token response, with a new request token if valid.

        :param uri: The full URI of the token request.
        :param http_method: A valid HTTP verb, i.e. GET, POST, PUT, HEAD, etc.
        :param body: The request body as a string.
        :param headers: The request headers as a dict.
        :param realms: A list of realms the resource is protected under.
                       This will be supplied to the ``validate_realms``
                       method of the request validator.
        :returns: A tuple of 2 elements.
                  1. True if valid, False otherwise.
                  2. An oauthlib.common.Request object.
        t   access_tokent   urit   realmsu   clientu   resource_owneru   realmu	   signatureu&   [Failure] request verification failed.u   Valid client: %su   Valid token: %su   Valid realm: %su   Valid signature: %sN(   t   _create_requestR   t   OAuth1Errort   Falset   Nonet   _check_transport_securityt   _check_mandatory_parameterst   resource_owner_keyt   request_validatort   check_access_tokent   validate_timestamp_and_noncet
   client_keyt	   timestampt   noncet   validate_client_keyt   dummy_clientt   validate_access_tokent   dummy_access_tokent   validate_realmsR   t   _check_signaturet   validator_logt   allt   logt   info(   t   selfR   t   http_methodt   bodyt   headersR   t   requestt   valid_clientt   valid_resource_ownert   valid_realmt   valid_signaturet   v(    (    sL   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/endpoints/resource.pyt#   validate_protected_resource_request7   sV    	
	
	
					N(   t   __name__t
   __module__t   __doc__R   R)   (    (    (    sL   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/endpoints/resource.pyR      s   "(   R,   t
   __future__R    R   t   loggingt   baseR   t    R   t	   getLoggerR*   R   R   (    (    (    sL   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/endpoints/resource.pyt   <module>   s   