
    ~h                         d dl Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lm	Z	 dd
lm
Z
 ddlmZ ddlmZ ddlmZ  G d d      Zy)    N   )InvalidNonceError)InvalidRequestError)InvalidSignatureError)MissingRequiredParameterError)UnsupportedSignatureMethodError)SIGNATURE_HMAC_SHA1)SIGNATURE_PLAINTEXT)SIGNATURE_RSA_SHA1)verify_hmac_sha1)verify_plaintext)verify_rsa_sha1c                   N    e Zd ZeeeeeeiZ	egZ
dZed        Zd Zd Zd Zd Zy)
BaseServeri,  c                 "    || j                   |<   y)a  Extend signature method verification.

        :param name: A string to represent signature method.
        :param verify: A function to verify signature.

        The ``verify`` method accept ``OAuth1Request`` as parameter::

            def verify_custom_method(request):
                # verify this request, return True or False
                return True


            Server.register_signature_method("custom-name", verify_custom_method)
        N)SIGNATURE_METHODS)clsnameverifys      ^/opt/mcp/mcp-sentiment/venv/lib/python3.12/site-packages/authlib/oauth1/rfc5849/base_server.pyregister_signature_methodz$BaseServer.register_signature_method   s      '-d#    c                     |j                   j                  d      }|j                   j                  d      }|j                  t        k(  r|s|sy|st	        d      	 t        |      }|dk  rt        d      | j                  r/t        j                         |z
  | j                  kD  rt        d      |st	        d      | j                  ||      r
t               y# t        t        f$ r}t        d      |d}~ww xY w)zzValidate ``oauth_timestamp`` and ``oauth_nonce`` in HTTP request.

        :param request: OAuth1Request instance
        oauth_timestampoauth_nonceNr   zInvalid "oauth_timestamp" value)oauth_paramsgetsignature_methodr
   r   intr   EXPIRY_TIMEtime
ValueError	TypeErrorexists_noncer   )selfrequest	timestampnonceexcs        r   validate_timestamp_and_noncez'BaseServer.validate_timestamp_and_nonce+   s    
 ((,,->?	$$((7##':: U/0ABB		RII1})*KLLDIIK)$;d>N>N$N)*KLL />>UG,#%% - I& 	R%&GHcQ	Rs   AC C=,C88C=c                    |j                   }|st        d      || j                  vr
t               |j                  st        d      | j
                  j                  |      }|s
t                ||      s
t               y)zhValidate ``oauth_signature`` from HTTP request.

        :param request: OAuth1Request instance
        oauth_signature_methodoauth_signatureN)r   r   SUPPORTED_SIGNATURE_METHODSr   	signaturer   r   r   )r%   r&   methodr   s       r   validate_oauth_signaturez#BaseServer.validate_oauth_signatureM   s    
 ))/0HII999133  /0ABB''++F3133g')) r   c                     t               )zGet client instance with the given ``client_id``.

        :param client_id: A string of client_id
        :return: Client instance
        NotImplementedError)r%   	client_ids     r   get_client_by_idzBaseServer.get_client_by_idc   s     "##r   c                     t               )a	  The nonce value MUST be unique across all requests with the same
        timestamp, client credentials, and token combinations.

        :param nonce: A string value of ``oauth_nonce``
        :param request: OAuth1Request instance
        :return: Boolean
        r3   )r%   r(   r&   s      r   r$   zBaseServer.exists_noncek   s     "##r   N)__name__
__module____qualname__r	   r   r   r   r
   r   r   r.   r    classmethodr   r*   r1   r6   r$    r   r   r   r      sR    -O-
 $7"7K- -" &D*,$$r   r   )r!   errorsr   r   r   r   r   r/   r	   r
   r   r   r   r   r   r<   r   r   <module>r>      s5     % ' ) 1 3 * * ) ' ' &c$ c$r   