o
    h                     @   s   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 zddlmZ W n eyU   dZY nw h dZe ZG dd deZdd ZdS )    )current_app)request)session)Markup)CombinedMultiDict)ImmutableMultiDict)cached_property)Form)DefaultMeta)HiddenInput   )_FlaskFormCSRF)translationsN>   DELETEPATCHPUTPOSTc                       sN   e Zd ZdZG dd deZef fdd	Zdd Zdd	d
Z	dd Z
  ZS )	FlaskFormzFlask-specific subclass of WTForms :class:`~wtforms.form.Form`.

    If ``formdata`` is not specified, this will use :attr:`flask.request.form`
    and :attr:`flask.request.files`.  Explicitly pass ``formdata=None`` to
    prevent this.
    c                       s\   e Zd ZeZeZedd Zedd Z	edd Z
edd Zd	d
 Z fddZ  ZS )zFlaskForm.Metac                 C      t jddS )NZWTF_CSRF_ENABLEDTr   configgetself r   A/var/www/html/venv/lib/python3.10/site-packages/flask_wtf/form.pycsrf$      zFlaskForm.Meta.csrfc                 C   s   t jdt jS )NZWTF_CSRF_SECRET_KEY)r   r   r   Z
secret_keyr   r   r   r   csrf_secret(   s   zFlaskForm.Meta.csrf_secretc                 C   r   )NZWTF_CSRF_FIELD_NAMEZ
csrf_tokenr   r   r   r   r   csrf_field_name,   r   zFlaskForm.Meta.csrf_field_namec                 C   r   )NZWTF_CSRF_TIME_LIMITi  r   r   r   r   r   csrf_time_limit0   r   zFlaskForm.Meta.csrf_time_limitc                 C   sJ   |t u r#t r!tjrttjtjfS tjrtjS tjr!tt S d S |S N)	_Auto_is_submittedr   filesr   formZis_jsonr   Zget_json)r   r%   formdatar   r   r   wrap_formdata4   s   zFlaskForm.Meta.wrap_formdatac                    s   t jddst |S tS )NZWTF_I18N_ENABLEDT)r   r   r   superget_translationsr   )r   r%   	__class__r   r   r)   B   s   zFlaskForm.Meta.get_translations)__name__
__module____qualname__r   Z
csrf_classr   Zcsrf_contextr   r   r   r   r    r'   r)   __classcell__r   r   r*   r   Meta    s    



r0   c                    s   t  jdd|i| d S )Nr&   r   )r(   __init__)r   r&   kwargsr*   r   r   r1   H   s   zFlaskForm.__init__c                 C   s   t  S )zConsider the form submitted if there is an active request and
        the method is ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
        )r#   r   r   r   r   is_submittedK   s   zFlaskForm.is_submittedNc                 C   s   |   o	| j|dS )zCall :meth:`validate` only if the form is submitted.
        This is a shortcut for ``form.is_submitted() and form.validate()``.
        )extra_validators)r3   validate)r   r4   r   r   r   validate_on_submitR   s   zFlaskForm.validate_on_submitc                    s,    fdd}t ddd ||p D S )a?  Render the form's hidden fields in one call.

        A field is considered hidden if it uses the
        :class:`~wtforms.widgets.HiddenInput` widget.

        If ``fields`` are given, only render the given fields that
        are hidden.  If a string is passed, render the field with that
        name if it exists.

        .. versionchanged:: 0.13

           No longer wraps inputs in hidden div.
           This is valid HTML 5.

        .. versionchanged:: 0.13

           Skip passed fields that aren't hidden.
           Skip passed names that don't exist.
        c                 3   sB    | D ]}t |trt |d }|d u st |jtsq|V  qd S r!   )
isinstancestrgetattrZwidgetr   )fieldsfr   r   r   hidden_fieldsm   s   
z+FlaskForm.hidden_tag.<locals>.hidden_fields
c                 s   s    | ]}t |V  qd S r!   )r8   ).0r;   r   r   r   	<genexpr>w   s    z'FlaskForm.hidden_tag.<locals>.<genexpr>)r   join)r   r:   r<   r   r   r   
hidden_tagX   s    
zFlaskForm.hidden_tagr!   )r,   r-   r.   __doc__r
   r0   r"   r1   r3   r6   rA   r/   r   r   r*   r   r      s    (
r   c                   C   s   t totjtv S )zConsider the form submitted if there is an active request and
    the method is ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
    )boolr   methodSUBMIT_METHODSr   r   r   r   r#   z   s   r#   )Zflaskr   r   r   Z
markupsafer   Zwerkzeug.datastructuresr   r   Zwerkzeug.utilsr   Zwtformsr	   Zwtforms.metar
   Zwtforms.widgetsr   r   r   Zi18nr   ImportErrorrE   objectr"   r   r#   r   r   r   r   <module>   s(    b