
    ih                     J    S SK Jr  S SKJr  Sr " S S\5      r " S S5      rg)	    )HiddenField)ValidationError)CSRFTokenFieldCSRFc                   N   ^  \ rS rSrSrSrU 4S jrS rS rS r	U 4S jr
S	rU =r$ )
r      a)  
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                 R   > UR                  S5      U l        [        TU ]  " U0 UD6  g )N	csrf_impl)popr
   super__init__)selfargskw	__class__s      T/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/wtforms/csrf/core.pyr   CSRFTokenField.__init__   s%    ,$%"%    c                     U R                   $ )zm
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   _valueCSRFTokenField._value   s    
 !!!r   c                     g)z,
Don't populate objects with the CSRF token
N )r   r   s     r   populate_objCSRFTokenField.populate_obj   s     	r   c                 :    U R                   R                  X5        g)z(
Handle validation of this token field.
N)r
   validate_csrf_token)r   forms     r   pre_validateCSRFTokenField.pre_validate$   s     	**46r   c                 f   > [         TU ]  " U0 UD6  U R                  R                  U 5      U l        g )N)r   processr
   generate_csrf_tokenr   )r   r   kwargsr   s      r   r#   CSRFTokenField.process*   s+    ((!^^??Er   )r
   r   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r    r#   __static_attributes____classcell__)r   s   @r   r   r      s/     M&"7F Fr   r   c                   *    \ rS rSr\rS rS rS rSr	g)r   /   c                 Z    UR                   nUR                  nU R                  SU S9nX44/$ )av  
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   r2   
field_nameunbound_fields        r   
setup_formCSRF.setup_form2   s9     yy))
((|t(L+,,r   c                     [        5       e)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$   CSRF.generate_csrf_tokenE   s     "##r   c                 l    UR                   UR                  :w  a  [        UR                  S5      5      eg)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   CSRF.validate_csrf_tokenU   s0     %**,!%--0E"FGG -r   r   N)
r'   r(   r)   r*   r   r4   r7   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>rE      s+    & .
$%F[ %FP1H 1Hr   