
    +h1                         d dl Z d dlmZ d dlmZ d dlmZ dZ e       Z G d d      Z	 G d d	e
      Z G d
 de	e      Zy)    N)OrderedDict)DefaultMeta)unset_value)BaseFormFormc                   p    e Zd ZdZdefdZd Zd Zd Zd Z	d Z
d	 ZddZddZed        Zed        Zy
)r   zy
    Base Form Class.  Provides core behaviour like field construction,
    validation, and data and error proxying.
     c                 .   |r|d   dvr|dz  }|| _         || _        t               | _        t	        |d      r|j                         }| j                   j                  |       }g }|j                  r@|j                  |       | _	        |j                  | j                  j                  |              t        j                  ||      D ]E  \  }}|j                  xs |}t        |||      }	|j!                  | ||	      }
|
| j                  |<   G g | _        y)af  
        :param fields:
            A dict or sequence of 2-tuples of partially-constructed fields.
        :param prefix:
            If provided, all fields will have their name prefixed with the
            value.
        :param meta:
            A meta instance which is used for configuration and customization
            of WTForms behaviors.
        z-_;:/.-items)nameprefixtranslationsN)meta_prefixr   _fieldshasattrr   get_translationscsrf
build_csrf_csrfextend
setup_form	itertoolschainr   dict
bind_fieldform_errors)selffieldsr   r   r   extra_fieldsr   unbound_field
field_nameoptionsfields              ?/var/www/html/venv/lib/python3.12/site-packages/wtforms/form.py__init__zBaseForm.__init__   s     fRj0cMF	"}67#\\^Fyy11$799.DJ

 5 5d ;<#,??6<#H 	'D-&++3tJ
6UGOOD-AE!&DLL		'     c                 H    t        | j                  j                               S )z&Iterate form fields in creation order.)iterr   values)r    s    r'   __iter__zBaseForm.__iter__5   s    DLL'')**r)   c                     || j                   v S )z;Returns `True` if the named field is a member of this form.r   r    r   s     r'   __contains__zBaseForm.__contains__9   s    t||##r)   c                      | j                   |   S )z(Dict-style access to this form's fields.r/   r0   s     r'   __getitem__zBaseForm.__getitem__=   s    ||D!!r)   c                 Z    |j                  | || j                        | j                  |<   y)zBind a field to this form.)formr   r   N)bindr   r   r    r   values      r'   __setitem__zBaseForm.__setitem__A   s#    "ZZTT\\ZRTr)   c                     | j                   |= y)zRemove a field from this form.Nr/   r0   s     r'   __delitem__zBaseForm.__delitem__E   s    LLr)   c                 l    | j                   j                         D ]  \  }}|j                  ||        y)z
        Populates the attributes of the passed `obj` with data from the form's
        fields.

        :note: This is a destructive operation; Any attribute with the same name
               as a field will be overridden. Use with caution.
        N)r   r   populate_obj)r    objr   r&   s       r'   r=   zBaseForm.populate_objI   s4      <<--/ 	*KD%sD)	*r)   Nc                    | j                   j                  | |      }|t        |fi |}||j                         ni }| j                  j                         D ]y  \  }}|j                  |g       }	t        | d|z  d      }
|
|	j                  |
       |t        ||      rt        ||      }n||v r||   }nt        }|j                  |||	       { y)a  Process default and input data with each field.

        :param formdata: Input data coming from the client, usually
            ``request.form`` or equivalent. Should provide a "multi
            dict" interface to get a list of values for a given key,
            such as what Werkzeug, Django, and WebOb provide.
        :param obj: Take existing data from attributes on this object
            matching form field attributes. Only used if ``formdata`` is
            not passed.
        :param data: Take existing data from keys in this dict matching
            form field attributes. ``obj`` takes precedence if it also
            has a matching attribute. Only used if ``formdata`` is not
            passed.
        :param extra_filters: A dict mapping field attribute names to
            lists of extra filter functions to run. Extra filters run
            after filters passed when creating the field. If the form
            has ``filter_<fieldname>``, it is the last extra filter.
        :param kwargs: Merged with ``data`` to allow passing existing
            data as parameters. Overwrites any duplicate keys in
            ``data``. Only used if ``formdata`` is not passed.
        Nz	filter_%s)extra_filters)r   wrap_formdatar   copyr   r   getgetattrappendr   r   process)r    formdatar>   datar@   kwargsfiltersr   r&   field_extra_filtersinline_filters              r'   rF   zBaseForm.processT   s    , 99**4:$)&)F*7*C-$$&<<--/ 	MKD%")++dB"7#D+*<dCM(#**=973#5sD)d|"MM(D8KML	Mr)   c                     d}| j                   j                         D ]0  \  }}|
||v r||   }n
t               }|j                  | |      r/d}2 |S )aL  
        Validates the form by calling `validate` on each field.

        :param extra_validators:
            If provided, is a dict mapping field names to a sequence of
            callables which will be passed as extra validators to the field's
            `validate` method.

        Returns `True` if no errors occur.
        TF)r   r   tuplevalidate)r    extra_validatorssuccessr   r&   extras         r'   rO   zBaseForm.validate   sb     <<--/ 	 KD%+8H0H(.>>$.	  r)   c                 ~    | j                   j                         D ci c]  \  }}||j                   c}}S c c}}w N)r   r   rH   )r    r   fs      r'   rH   zBaseForm.data   s/    ,0LL,>,>,@AqaffAAAs   9c                     | j                   j                         D ci c]  \  }}|j                  s||j                  ! }}}| j                  r| j                  |d <   |S c c}}w rT   )r   r   errorsr   )r    r   rU   rW   s       r'   rW   zBaseForm.errors   sW    040B0B0DQWT1$.QQ++F4L Rs
   A"A")NNNNrT   )__name__
__module____qualname____doc___default_metar(   r-   r1   r3   r9   r;   r=   rF   rO   propertyrH   rW    r)   r'   r   r      si    
 ')} !F+$"S	*+MZ* B B  r)   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)FormMetaa  
    The metaclass for `Form` and any subclasses of `Form`.

    `FormMeta`'s responsibility is to create the `_unbound_fields` list, which
    is a list of `UnboundField` instances sorted by their order of
    instantiation.  The list is created at the first instantiation of the form.
    If any fields are added/removed from the form, the list is cleared to be
    re-generated on the next instantiation.

    Any properties which begin with an underscore or are not `UnboundField`
    instances are ignored by the metaclass.
    c                 P    t         j                  | |||       d | _        d | _        y rT   )typer(   _unbound_fields_wtforms_meta)clsr   basesattrss       r'   r(   zFormMeta.__init__   s$    c4." r)   c                    | j                   jg }t        |       D ]@  }|j                  d      rt        | |      }t	        |d      s.|j                  ||f       B |j                  d        || _         | j                  Xg }| j                  D ],  }d|j                  v s|j                  |j                         . t        dt        |      i       | _        t        j                  | g|i |S )z
        Construct a new `Form` instance.

        Creates the `_unbound_fields` list and the internal `_wtforms_meta`
        subclass of the class Meta in order to allow a proper inheritance
        hierarchy.
        _
_formfieldc                 *    | d   j                   | d   fS )N   r   )creation_counter)xs    r'   <lambda>z#FormMeta.__call__.<locals>.<lambda>   s    qt'<'<ad&C r)   )keyMeta)rc   dir
startswithrD   r   rE   sortrd   __mro____dict__rq   rb   rN   __call__)re   argsrI   r!   r   r#   rf   	mro_classs           r'   rw   zFormMeta.__call__   s     &FC =s+$+C$6M}l;t]&;<	= KKCKD"(C $E [[ 1	Y///LL01 !%VU5\2 >C}}S242622r)   c                     |dk(  rd| _         n$|j                  d      st        |d      rd| _        t        j                  | ||       y)zV
        Add an attribute to the class, clearing `_unbound_fields` if needed.
        rq   Nri   rj   )rd   rs   r   rc   rb   __setattr__)re   r   r8   s      r'   r{   zFormMeta.__setattr__   sB     6> $C%'%*F"&CdE*r)   c                 `    |j                  d      sd| _        t        j                  | |       y)zc
        Remove an attribute from the class, clearing `_unbound_fields` if
        needed.
        ri   N)rs   rc   rb   __delattr__)re   r   s     r'   r}   zFormMeta.__delattr__   s(    
 s#"&Cd#r)   N)rX   rY   rZ   r[   r(   rw   r{   r}   r^   r)   r'   r`   r`      s    !
3:+$r)   r`   c                   T     e Zd ZdZeZ	 	 	 	 	 d fd	Zd Zd Z fdZ	d fd	Z
 xZS )	r   z
    Declarative Form base class. Extends BaseForm's core behaviour allowing
    fields to be defined on Form subclasses as class attributes.

    In addition, form and instance input data are taken at construction time
    and passed to `process()`.
    c                 .   | j                         }|!t        |t              r|j                  |       t        
|   | j                  ||       | j                  j                         D ]  \  }}	t        | ||	         | j                  ||fd|i| y)a  
        :param formdata: Input data coming from the client, usually
            ``request.form`` or equivalent. Should provide a "multi
            dict" interface to get a list of values for a given key,
            such as what Werkzeug, Django, and WebOb provide.
        :param obj: Take existing data from attributes on this object
            matching form field attributes. Only used if ``formdata`` is
            not passed.
        :param prefix: If provided, all fields will have their name
            prefixed with the value. This is for distinguishing multiple
            forms on a single page. This only affects the HTML name for
            matching input data, not the Python name for matching
            existing data.
        :param data: Take existing data from keys in this dict matching
            form field attributes. ``obj`` takes precedence if it also
            has a matching attribute. Only used if ``formdata`` is not
            passed.
        :param meta: A dict of attributes to override on this form's
            :attr:`meta` instance.
        :param extra_filters: A dict mapping field attribute names to
            lists of extra filter functions to run. Extra filters run
            after filters passed when creating the field. If the form
            has ``filter_<fieldname>``, it is the last extra filter.
        :param kwargs: Merged with ``data`` to allow passing existing
            data as parameters. Overwrites any duplicate keys in
            ``data``. Only used if ``formdata`` is not passed.
        N)r   r   rH   )rd   
isinstancer   update_valuessuperr(   rc   r   r   setattrrF   )r    rG   r>   r   rH   r   rI   meta_objr   r&   	__class__s             r'   r(   zForm.__init__   s    H %%'
4 6""4(--HVL<<--/ 	'KD% D$&	' 	Xs888r)   c                     t        d      )Nz8Fields may not be added to Form instances, only classes.)	TypeErrorr7   s      r'   r9   zForm.__setitem__   s    RSSr)   c                 8    | j                   |= t        | |d        y rT   )r   r   r0   s     r'   r;   zForm.__delitem__#  s    LLdD!r)   c                     || j                   v r| j                  |       y t        | j                  |d       }|t	        |d      rt        | |d        y t        |   |       y )Nrj   )r   r;   rD   r   r   r   r   r}   )r    r   r#   r   s      r'   r}   zForm.__delattr__'  sY    4<<T" $DNND$?M(W]L-QdD)#D)r)   c                     ||j                         }ni }| j                  D ]@  }t        | j                  d| d      }| |j	                  |g       j                  |       B t        |   |      S )a  Validate the form by calling ``validate`` on each field.
        Returns ``True`` if validation passes.

        If the form defines a ``validate_<fieldname>`` method, it is
        appended as an extra validator for the field's ``validate``.

        :param extra_validators: A dict mapping field names to lists of
            extra validator methods to run. Extra validators run after
            validators passed when creating the field. If the form has
            ``validate_<fieldname>``, it is the last extra validator.
        N	validate_)rB   r   rD   r   
setdefaultrE   r   rO   )r    rP   rR   r   inliner   s        r'   rO   zForm.validate3  s}     '$))+EELL 	:DT^^y-?FF!  r*11&9	:
 w&&r)   )NNr	   NNrT   )rX   rY   rZ   r[   r   rq   r(   r9   r;   r}   rO   __classcell__)r   s   @r'   r   r      s@     D -9^T"
*' 'r)   r   )	metaclass)r   collectionsr   wtforms.metar   wtforms.utilsr   __all__r\   r   rb   r`   r   r^   r)   r'   <module>r      sI     # $ %
S SlA$t A$Hc'8x c'r)   