
    +h                     J    d dl mZ d dlmZ dZ G d de      Z G d d      Zy)	    )HiddenField)ValidationError)CSRFTokenFieldCSRFc                   B     e Zd ZdZdZ fdZd Zd Zd Z fdZ	 xZ
S )r   aA  
    A subclass of HiddenField designed for sending the CSRF token that is used
    for most CSRF protection schemes.

    Notably different from a normal field, this field always renders the
    current token regardless of the submitted value, and also will not be
    populated over to object data via populate_obj
    Nc                 P    |j                  d      | _        t        |   |i | y )N	csrf_impl)popr	   super__init__)selfargskw	__class__s      D/var/www/html/venv/lib/python3.12/site-packages/wtforms/csrf/core.pyr   zCSRFTokenField.__init__   s%    ,$%"%    c                     | j                   S )z
        We want to always return the current token on render, regardless of
        whether a good or bad token was passed.
        )current_token)r   s    r   _valuezCSRFTokenField._value   s    
 !!!r   c                      y)z<
        Don't populate objects with the CSRF token
        N )r   r   s     r   populate_objzCSRFTokenField.populate_obj   s     	r   c                 <    | j                   j                  ||        y)z8
        Handle validation of this token field.
        N)r	   validate_csrf_token)r   forms     r   pre_validatezCSRFTokenField.pre_validate$   s     	**46r   c                 d    t        |   |i | | j                  j                  |       | _        y )N)r   processr	   generate_csrf_tokenr   )r   r   kwargsr   s      r   r   zCSRFTokenField.process*   s+    ((!^^??Er   )__name__
__module____qualname____doc__r   r   r   r   r   r   __classcell__)r   s   @r   r   r      s/     M&"7F Fr   r   c                   "    e Zd ZeZd Zd Zd Zy)r   c                 b    |j                   }|j                  }| j                  d|       }||fgS )a  
        Receive the form we're attached to and set up fields.

        The default implementation creates a single field of
        type :attr:`field_class` with name taken from the
        ``csrf_field_name`` of the class meta.

        :param form:
            The form instance we're attaching to.
        :return:
            A sequence of `(field_name, unbound_field)` 2-tuples which
            are unbound fields to be added to the form.
        z
CSRF Token)labelr	   )metacsrf_field_namefield_class)r   r   r)   
field_nameunbound_fields        r   
setup_formzCSRF.setup_form2   s;     yy))
((|t(L]+,,r   c                     t               )a  
        Implementations must override this to provide a method with which one
        can get a CSRF token for this form.

        A CSRF token is usually a string that is generated deterministically
        based on some sort of user data, though it can be anything which you
        can validate on a subsequent request.

        :param csrf_token_field:
            The field which is being used for CSRF.
        :return:
            A generated CSRF string.
        )NotImplementedError)r   csrf_token_fields     r   r   zCSRF.generate_csrf_tokenE   s     "##r   c                 j    |j                   |j                  k7  rt        |j                  d            y)a>  
        Override this method to provide custom CSRF validation logic.

        The default CSRF validation logic simply checks if the recently
        generated token equals the one we received as formdata.

        :param form: The form which has this CSRF token.
        :param field: The CSRF token field.
        zInvalid CSRF Token.N)r   datar   gettext)r   r   fields      r   r   zCSRF.validate_csrf_tokenU   s0     %**,!%--0E"FGG -r   N)r!   r"   r#   r   r+   r.   r   r   r   r   r   r   r   /   s     K-&$ Hr   r   N)wtforms.fieldsr   wtforms.validatorsr   __all__r   r   r   r   r   <module>r9      s+    & .
$%F[ %FP1H 1Hr   