o
    a"                     @   s\   d Z ddlZddlZddlmZmZmZmZmZm	Z	m
Z
 eeZG dd dZdd ZdS )	z
oauthlib.oauth2.rfc6749
~~~~~~~~~~~~~~~~~~~~~~~

This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
    N   )FatalClientErrorInvalidClientErrorInvalidRequestErrorOAuth2ErrorServerErrorTemporarilyUnavailableErrorUnsupportedTokenTypeErrorc                   @   s   e Zd Zdd Zedd Zejdd Zedd Zejdd Zed	d
 Zejdd
 Zdd Z	dd Z
dd Zdd Zdd ZdS )BaseEndpointc                 C   s   d| _ d| _d | _d S )NTF)
_available_catch_errors_valid_request_methodsself r   H/usr/lib/python3/dist-packages/oauthlib/oauth2/rfc6749/endpoints/base.py__init__   s   
zBaseEndpoint.__init__c                 C      | j S Nr   r   r   r   r   valid_request_methods      z"BaseEndpoint.valid_request_methodsc                 C   s    |d urdd |D }|| _ d S )Nc                 S   s   g | ]}|  qS r   )upper).0xr   r   r   
<listcomp>!   s    z6BaseEndpoint.valid_request_methods.<locals>.<listcomp>r   )r   r   r   r   r   r      s   
c                 C   r   r   r   r   r   r   r   	available%   r   zBaseEndpoint.availablec                 C   
   || _ d S r   r   )r   r   r   r   r   r   )      
c                 C   r   r   r   r   r   r   r   catch_errors-   r   zBaseEndpoint.catch_errorsc                 C   r   r   r    )r   r!   r   r   r   r!   1   r   c                 C   s   |j s	t|dddS )zRaise error on missing token.zMissing token parameter.requestdescriptionN)tokenr   r   r#   r   r   r   _raise_on_missing_token5   s
   z$BaseEndpoint._raise_on_missing_tokenc                 C   s\   | j |r| j |std| t|ddS | j |j|s,td| t|ddS )z&Raise on failed client authentication.z!Client authentication failed, %r.r#   N)request_validatorclient_authentication_requiredauthenticate_clientlogdebugr   authenticate_client_id	client_idr&   r   r   r   _raise_on_invalid_client:   s   

z%BaseEndpoint._raise_on_invalid_clientc                 C   s4   |j r|j | jv r|j | jvrt|ddS dS dS )zRaise on unsupported tokens.r(   N)token_type_hintvalid_token_typessupported_token_typesr	   r&   r   r   r   _raise_on_unsupported_tokenD   s   


z(BaseEndpoint._raise_on_unsupported_tokenc                 C   s<   | j d u r	td|j | j vrt|d|j  dd S )Nz0Configure "valid_request_methods" property firstzUnsupported request method %sr"   )r   
ValueErrorhttp_methodr   r   r&   r   r   r   _raise_on_bad_methodK   s   
z!BaseEndpoint._raise_on_bad_methodc                 C   s0   |j  dkr|jpd}|rt|dddS dS )z/Raise if invalid POST request received
        POST z$URL query parameters are not allowedr"   N)r6   r   	uri_queryr   )r   r#   query_paramsr   r   r   _raise_on_bad_post_requestR   s   
z'BaseEndpoint._raise_on_bad_post_requestN)__name__
__module____qualname__r   propertyr   setterr   r!   r'   r0   r4   r7   r<   r   r   r   r   r
      s&    






r
   c                    s   t   fdd}|S )Nc              
      s   | j st }td|  i |jdfS | jrTz | |g|R i |W S  ty+     ty2     tyS } zt	 }t
d|  i |jdfW  Y d }~S d }~ww  | |g|R i |S )Nz*Endpoint unavailable, ignoring request %s.i  z.Exception caught while processing request, %s.i  )r   r   r,   infojsonr!   r   r   	Exceptionr   warning)endpointuriargskwargseerrorfr   r   wrapper\   s(   z0catch_errors_and_unavailability.<locals>.wrapper)	functoolswraps)rM   rN   r   rL   r   catch_errors_and_unavailability[   s   rQ   )__doc__rO   loggingerrorsr   r   r   r   r   r   r	   	getLoggerr=   r,   r
   rQ   r   r   r   r   <module>   s    $
H