
    wdfU                     Z    d dl mZ d dlmZ dZ G d de          Z G d de          ZdS )	    )ValidationError)HiddenField)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                 |    |                     d          | _         t          t          |           j        |i | d S )N	csrf_impl)popr	   superr   __init__)selfargskw	__class__s      V/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/wtforms/csrf/core.pyr   zCSRFTokenField.__init__   s>    ,,,nd##,d9b99999    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                     dS )z<
        Don't populate objects with the CSRF token
        N )r   r   s     r   populate_objzCSRFTokenField.populate_obj   s	     	r   c                 <    | j                             ||            dS )z8
        Handle validation of this token field.
        N)r	   validate_csrf_token)r   forms     r   pre_validatezCSRFTokenField.pre_validate#   s"     	**466666r   c                      t          t          |           j        |  | j                            |           | _        d S )N)r   r   processr	   generate_csrf_tokenr   )r   r   r   s     r   r   zCSRFTokenField.process)   s;    +nd##+T22!^??EEr   )__name__
__module____qualname____doc__r   r   r   r   r   r   __classcell__)r   s   @r   r   r      s          M: : : : :" " "  7 7 7F F F F F F F F Fr   r   c                   $    e Zd ZeZd Zd Zd ZdS )r   c                 V    |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_form1   sC     y)
(( ) 
 
 ]+,,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_tokenG   s     "###r   c                 j    |j         |j        k    r"t          |                    d                    dS )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 TokenN)r   datar   gettext)r   r   fields      r   r   zCSRF.validate_csrf_tokenW   s7     %*,,!%--0D"E"EFFF -,r   N)r    r!   r"   r   r*   r-   r   r   r   r   r   r   r   .   sK         K- - -,$ $ $ G G G G Gr   r   N)wtforms.validatorsr   wtforms.fieldsr   __all__r   objectr   r   r   r   <module>r9      s    . . . . . . & & & & & &
$$F $F $F $F $F[ $F $F $FN4G 4G 4G 4G 4G6 4G 4G 4G 4G 4Gr   