
    +h:                         d dl Z d dlZd dl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  G d	 d
      Z G d d      Z G d d      Z G d d      Zy)    N)escape)Markup)widgets)DummyTranslations)unset_value)StopValidation)ValidationErrorc                        e Zd ZdZ e       Z e       ZdZ e       ZdZ	dZ
 e       ZdZ fdZ	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd Zd Zd Zed	        Zd
 Zd ZddZd Zd Zd ZedfdZd Zd Zd Z xZ S )Fieldz
    Field base class
    NTc                 H    d|v rt         |   |       S t        | g|i |S )N_form)super__new__UnboundField)clsargskwargs	__class__s      F/var/www/html/venv/lib/python3.12/site-packages/wtforms/fields/core.pyr   zField.__new__   s/    f7?3''5d5f55    c           	         ||| _         ||| _        n|
|
j                  | _        nt        d      || _        || _        || _        || _        t               | _        ||	z   | _	        |	| _
        t        |       j                  | _        | j                  |       |xs | j                  | _        |xs | j                  | _        t!        | j                  ||n.| j#                  |	j%                  dd      j'                                     | _        ||| _        t-        j.                  | j                  | j*                  g      D ]z  }t1        |di       }t3        |t4              r,t7        j8                  dt:        d       |D ci c]  }|d	 }}|j=                         D ]  \  }}t?        | j                  ||        | yc c}w )
a  
        Construct a new field.

        :param label:
            The label of the field.
        :param validators:
            A sequence of validators to call when `validate` is called.
        :param filters:
            A sequence of callable which are run by :meth:`~Field.process`
            to filter or transform the input data. For example
            ``StringForm(filters=[str.strip, str.upper])``.
            Note that filters are applied after processing the default and
            incoming data, but before validation.
        :param description:
            A description for the field, typically used for help text.
        :param id:
            An id to use for the field. A reasonable default is set by the form,
            and you shouldn't need to set this manually.
        :param default:
            The default value to assign to the field, if no form or object
            input is provided. May be a callable.
        :param widget:
            If provided, overrides the widget used to render the field.
        :param dict render_kw:
            If provided, a dictionary which provides default keywords that
            will be given to the widget at render time.
        :param name:
            The HTML name of this field. The default value is the Python
            attribute name.
        :param _form:
            The form holding this field. It is passed by the form itself during
            construction. You should never pass this value yourself.
        :param _prefix:
            The prefix to prepend to the form name of this field, passed by
            the enclosing form during construction.
        :param _translations:
            A translations object providing message translations. Usually
            passed by the enclosing form during construction. See
            :doc:`I18n docs <i18n>` for information on message translations.
        :param _meta:
            If provided, this is the 'meta' instance from the form. You usually
            don't pass this yourself.

        If `_form` isn't provided, an :class:`UnboundField` will be
        returned instead. Call its :func:`bind` method with a form instance and
        a name to construct the field.
        Nz"Must provide one of _form or _meta_ field_flagszxFlags should be stored in dicts and not in tuples. The next version of WTForms will abandon support for flags in tuples.   )
stacklevelT) _translationsmeta	TypeErrordefaultdescription	render_kwfiltersFlagsflagsname
short_nametype__name__check_validators
validatorsidLabelgettextreplacetitlelabelwidget	itertoolschaingetattr
isinstancetuplewarningswarnDeprecationWarningitemssetattr)selfr1   r+   r#   r!   r,   r    r2   r"   r&   r   _prefixr   _metavr%   	flag_nameks                     r   __init__zField.__init__#   s   ~ $!.DDI

DI@AA&"W
dN	J''	j)$7/		GG  dll34::<=	

  DK4;;-@ 	*AA}b1E %'+ '  ;@@YD@@ *1

Aq)*	* As   
Gc                      |        S )z}
        Returns a HTML representation of the field. For more powerful rendering,
        see the `__call__` method.
         r=   s    r   __str__zField.__str__       
 vr   c                      |        S )z
        Returns a HTML representation of the field. For more powerful rendering,
        see the :meth:`__call__` method.
        rE   rF   s    r   __html__zField.__html__   rH   r   c                 :    | j                   j                  | |      S )aa  
        Render this field as HTML, using keyword args as additional attributes.

        This delegates rendering to
        :meth:`meta.render_field <wtforms.meta.DefaultMeta.render_field>`
        whose default behavior is to call the field's widget, passing any
        keyword arguments from this call along to the widget.

        In all of the WTForms HTML widgets, keyword arguments are turned to
        HTML attributes, though in theory a widget is free to do anything it
        wants with the supplied keyword arguments, and widgets don't have to
        even do anything related to HTML.
        )r   render_field)r=   r   s     r   __call__zField.__call__   s     yy%%dF33r   c                     |\|D ]V  }t        |      st        dj                  |            t        j                  |      s>t        dj                  |             y y )Nz6{} is not a valid validator because it is not callablezK{} is not a valid validator because it is a class, it should be an instance)callabler   formatinspectisclass)r   r+   	validators      r   r*   zField.check_validators   sj    !' 		*###)6)#4 
 ??9-#3396)3D  "r   c                 8    | j                   j                  |      S )z
        Get a translation for the given message.

        This proxies for the internal translations object.

        :param string: A string to be translated.
        :return: A string which is the translated output.
        )r   r.   )r=   strings     r   r.   zField.gettext   s     !!))&11r   c                 <    | j                   j                  |||      S )a  
        Get a translation for a message which can be pluralized.

        :param str singular: The singular form of the message.
        :param str plural: The plural form of the message.
        :param int n: The number of elements this message is referring to
        )r   ngettext)r=   singularpluralns       r   rW   zField.ngettext   s     !!**8VQ??r   c                    t        | j                        | _        d}| j                  |       	 | j	                  |       |s2t        j                  | j                  |      }| j                  ||      }	 | j                  ||       t        | j                        dk(  S # t
        $ rO}|j                  r7|j                  d   r(| j                  j                  |j                  d          d}Y d}~d}~wt        $ r2}| j                  j                  |j                  d          Y d}~d}~ww xY w# t        $ r2}| j                  j                  |j                  d          Y d}~d}~ww xY w)a  
        Validates the field and returns True or False. `self.errors` will
        contain any errors raised during validation. This is usually only
        called by `Form.validate`.

        Subfields shouldn't override this, but rather override either
        `pre_validate`, `post_validate` or both, depending on needs.

        :param form: The form the field belongs to.
        :param extra_validators: A sequence of extra validators to run.
        Fr   TN)listprocess_errorserrorsr*   pre_validater   r   appendr	   r3   r4   r+   _run_validation_chainpost_validatelen)r=   formextra_validatorsstop_validationer4   s         r   validatezField.validate   s,    4../ 	./	*d# OODOO5EFE"88uEO	*t_5 4;;1$$%  	#vv!&&)""166!9-"O 	*KKqvvay))	*  	*KKqvvay))	*s<   B 5D3 	D0(AC22D0>(D++D03	E.<(E))E.c                 L   |D ]  }	  |||         y# t         $ rN}|j                  r7|j                  d   r(| j                  j                  |j                  d          Y d}~ yd}~wt        $ r2}| j                  j                  |j                  d          Y d}~d}~ww xY w)a%  
        Run a validation chain, stopping if any validator raises StopValidation.

        :param form: The Form instance this field belongs to.
        :param validators: a sequence or iterable of validator callables.
        :return: True if validation was stopped, False otherwise.
        r   NTF)r   r   r^   r`   r	   )r=   rd   r+   rS   rg   s        r   ra   zField._run_validation_chain   s     $ 	.I.$%	.  " 66affQiKK&&qvvay1" .""166!9--.s!   		B#AA%%B#1(BB#c                      y)z
        Override if you need field-level validation. Runs before any other
        validators.

        :param form: The form the field belongs to.
        NrE   )r=   rd   s     r   r_   zField.pre_validate  s     	r   c                      y)a*  
        Override if you need to run any field-level validation tasks after
        normal validation. This shouldn't be needed in most cases.

        :param form: The form the field belongs to.
        :param validation_stopped:
            `True` if any validator raised StopValidation.
        NrE   )r=   rd   validation_stoppeds      r   rb   zField.post_validate  s     	r   c                 J   g | _         |t        u r	 | j                         }|| _        	 | j                  |       |R| j                  |v r!|j                  | j                        | _        ng | _        	 | j                  | j                         	 t        j                  | j                  |xs g       D ]  } || j                         | _         y# t        $ r | j                  }Y w xY w# t        $ r2}| j                   j                  |j                  d          Y d}~d}~ww xY w# t        $ r2}| j                   j                  |j                  d          Y d}~d}~ww xY w# t        $ r2}| j                   j                  |j                  d          Y d}~yd}~ww xY w)a
  
        Process incoming data, calling process_data, process_formdata as needed,
        and run filters.

        If `data` is not provided, process_data will be called on the field's
        default.

        Field subclasses usually won't override this, instead overriding the
        process_formdata and process_data methods. Only override this for
        special advanced processing, such as when a field encapsulates many
        inputs.

        :param extra_filters: A sequence of extra filters to run.
        r   N)r]   r   r    r   object_dataprocess_data
ValueErrorr`   r   r&   getlistraw_dataprocess_formdatar3   r4   r#   data)r=   formdatart   extra_filtersrg   filters         r   processzField.process(  sk    !;$||~  	2d# yyH$ ( 0 0 ; "6%%dmm4	2#//$,,8KL ."499-	.-  $||$  	2&&qvvay11	2  6##**166!9556  	2&&qvvay11	2sY   C C+ 3D) A E' C('C(+	D&4(D!!D&)	E$2(EE$'	F"0(FF"c                     || _         y)a  
        Process the Python data applied to this field and store the result.

        This will be called during form construction by the form's `kwargs` or
        `obj` argument.

        :param value: The python object containing the value to process.
        Nrt   )r=   values     r   ro   zField.process_dataV  s     	r   c                     |r|d   | _         yy)z
        Process data received over the wire from a form.

        This will be called during form construction with data supplied
        through the `formdata` argument.

        :param valuelist: A list of strings to process.
        r   Nrz   )r=   	valuelists     r   rs   zField.process_formdataa  s     !!DI r   c                 2    t        ||| j                         y)z
        Populates `obj.<name>` with the field's data.

        :note: This is a destructive operation. If `obj.<name>` already exists,
               it will be overridden. Use with caution.
        N)r<   rt   )r=   objr&   s      r   populate_objzField.populate_objm  s     	T499%r   )NNrE    NNNNNNr   NN)rE   )!r)   
__module____qualname____doc__r7   r^   r]   rr   r+   r2   
_formfieldr   r   do_not_call_in_templatesr   rC   rG   rJ   rM   classmethodr*   r.   rW   rh   ra   r_   rb   r   rx   ro   rs   r   __classcell__r   s   @r   r   r      s     WFWNHJFJ%'M#6 o*b4   	2@'%R(	 &1 ,2\	
%&r   r   c                   .    e Zd ZdZdZdddZddZd Zy)	r   Tr   N)r&   c                    t         xj                  dz  c_        || _        || _        || _        || _        t         j                  | _        |j                  d      }|r| j                  j                  |       y y )N   r+   )r   creation_counterfield_classr   r&   r   getr*   )r=   r   r&   r   r   r+   s         r   rC   zUnboundField.__init__{  sh    %%*%&		 , = =ZZ-
--j9 r   c                 p    t        | j                  f||||d|} | j                  | j                  i |S )N)r&   r   r>   r   )dictr   r   r   )r=   rd   r&   prefixtranslationsr   kws          r   bindzUnboundField.bind  sL    KK
&
 
  t1b11r   c                 x    dj                  | j                  j                  | j                  | j                        S )Nz<UnboundField({}, {!r}, {!r})>)rP   r   r)   r   r   rF   s    r   __repr__zUnboundField.__repr__  s0    /66%%tyy$++
 	
r   )r   N)r)   r   r   r   r   rC   r   r   rE   r   r   r   r   w  s    J04 	:	2
r   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )r$   zq
    Holds a set of flags as attributes.

    Accessing a non-existing attribute returns None for its value.
    c                 F    |j                  d      rt        | 	  |      S y )Nr   )
startswithr   __getattr__)r=   r&   r   s     r   r   zFlags.__getattr__  s"    ??37&t,,r   c                     t        | |      S N)r5   )r=   r&   s     r   __contains__zFlags.__contains__  s    tT""r   c                 T      fdt               D        }ddj                  |      z  S )Nc              3   b   K   | ]&  }|j                  d       s| dt        |        ( yw)r   =N)r   r5   ).0r&   r=   s     r   	<genexpr>z!Flags.__repr__.<locals>.<genexpr>  s8      
??3' fAgdD)*+
s   ,/z<wtforms.fields.Flags: {%s}>, )dirjoin)r=   r%   s   ` r   r   zFlags.__repr__  s,    
D	

 .		%0@@@r   )r)   r   r   r   r   r   r   r   r   s   @r   r$   r$     s    
#Ar   r$   c                   0    e Zd ZdZd Zd Zd ZddZd Zy)	r-   z
    An HTML form label.
    c                      || _         || _        y r   field_idtext)r=   r   r   s      r   rC   zLabel.__init__  s     	r   c                      |        S r   rE   rF   s    r   rG   zLabel.__str__  	    vr   c                      |        S r   rE   rF   s    r   rJ   zLabel.__html__  r   r   Nc                     d|v r|j                  d      |d<   n|j                  d| j                         t        j                  di |}t        |xs | j                        }t        d| d| d      S )Nfor_forz<label >z</label>rE   )pop
setdefaultr   r   html_paramsr   r   r   )r=   r   r   
attributess       r   rM   zLabel.__call__  sp    V"JJv.F5MeT]]3((262
d'dii(
|1TF(;<<r   c                 <    d| j                   d| j                  dS )NzLabel(r   )r   rF   s    r   r   zLabel.__repr__  s     (499-q99r   r   )	r)   r   r   r   rC   rG   rJ   rM   r   rE   r   r   r-   r-     s     =:r   r-   )rQ   r3   r8   
markupsafer   r   wtformsr   wtforms.i18nr   wtforms.utilsr   wtforms.validatorsr   r	   r   r   r$   r-   rE   r   r   <module>r      sQ          * % - .e& e&P
 
@A A0: :r   