
    ?g"                     z    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j                  e      Z G d d      Zd Zy)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                       e Zd Zd Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zd Z	d	 Z
d
 Zd Zd Zy)BaseEndpointc                 .    d| _         d| _        d | _        y )NTF)
_available_catch_errors_valid_request_methodsselfs    [/var/www/openai/venv/lib/python3.12/site-packages/oauthlib/oauth2/rfc6749/endpoints/base.py__init__zBaseEndpoint.__init__   s    "&*#    c                     | j                   S N)r   r   s    r   valid_request_methodsz"BaseEndpoint.valid_request_methods   s    ***r   c                 Z    ||D cg c]  }|j                          }}|| _        y c c}w r   )upperr   )r   r   xs      r   r   z"BaseEndpoint.valid_request_methods   s3     ,8M$N8M1QWWY8M!$N&;# %Os   (c                     | j                   S r   r   r   s    r   	availablezBaseEndpoint.available%   s    r   c                     || _         y r   r   )r   r   s     r   r   zBaseEndpoint.available)   s	    #r   c                     | j                   S r   r   r   s    r   catch_errorszBaseEndpoint.catch_errors-   s    !!!r   c                     || _         y r   r!   )r   r"   s     r   r"   zBaseEndpoint.catch_errors1   s
    )r   c                 6    |j                   st        |d      y)zRaise error on missing token.zMissing token parameter.requestdescriptionN)tokenr   r   r&   s     r   _raise_on_missing_tokenz$BaseEndpoint._raise_on_missing_token5   s"    }}%g2LN N r   c                 F   | j                   j                  |      r>| j                   j                  |      s"t        j	                  d|       t        |      y| j                   j                  |j                  |      s"t        j	                  d|       t        |      y)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)   s     r   _raise_on_invalid_clientz%BaseEndpoint._raise_on_invalid_client:   s    !!@@I))==gF		=wG(99 G ''>>w?P?PRYZII97C$W55 [r   c                     |j                   r>|j                   | j                  v r%|j                   | j                  vrt        |      yyy)zRaise on unsupported tokens.r,   N)token_type_hintvalid_token_typessupported_token_typesr
   r)   s     r   _raise_on_unsupported_tokenz(BaseEndpoint._raise_on_unsupported_tokenD   sN    ####t'='==##4+E+EE+G<< F > $r   c                     | j                   t        d      |j                  j                         | j                   vr(t	        |d|j                  j                         z        y )Nz0Configure "valid_request_methods" property firstzUnsupported request method %sr%   )r   
ValueErrorhttp_methodr   r   r)   s     r   _raise_on_bad_methodz!BaseEndpoint._raise_on_bad_methodK   sf    %%-OPP$$&d.H.HH%g3RU\UhUhUnUnUp3ps s Ir   c                 ~    |j                   j                         dk(  r |j                  xs d}|rt        |d      yy)z/Raise if invalid POST request received
        POST z$URL query parameters are not allowedr%   N)r<   r   	uri_queryr   )r   r&   query_paramss      r   _raise_on_bad_post_requestz'BaseEndpoint._raise_on_bad_post_requestR   sL     $$&&0",,2L)'7]` `  1r   N)__name__
__module____qualname__r   propertyr   setterr   r"   r*   r4   r9   r=   rC    r   r   r   r      s    +
 + + !!< "<   $ $ " " * *N
6=s`r   r   c                 B     t        j                          fd       }|S )Nc                 ~   | j                   s1t               }t        j                  d|z         i |j                  dfS | j
                  r	  | |g|i |S  | |g|i |S # t        $ r  t        $ r  t        $ r;}t               }t        j                  d|z         i |j                  dfcY d }~S d }~ww xY w)Nz*Endpoint unavailable, ignoring request %s.i  z.Exception caught while processing request, %s.i  )r   r	   r0   infojsonr"   r   r   	Exceptionr   warning)endpointuriargskwargseerrorfs         r   wrapperz0catch_errors_and_unavailability.<locals>.wrapper\   s    !!+-AHHACGHqvvs?"  
+38888 Xs4T4V44  #  +#DqHJ5::s**	+s   A& &B<0B71B<7B<)	functoolswraps)rV   rW   s   ` r   catch_errors_and_unavailabilityrZ   [   s%    __Q5 5( Nr   )__doc__rX   loggingerrorsr   r   r   r   r   r	   r
   	getLoggerrD   r0   r   rZ   rI   r   r   <module>r_      sI       
 g!F` F`Pr   