o
    2c(                     @   s  d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZ d dlmZ d dlmZ d d	lmZ d
ZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZ G dd  d eZ!G d!d" d"e Z"G d#d$ d$eZ#G d%d& d&eZ$G d'd( d(eZ%G d)d* d*e%Z&G d+d, d,e%Z'G d-d. d.eZ(G d/d0 d0eZ)dS )1    )unicode_literalsN)copy)Markupescape)widgets)	text_typeizip)DummyTranslations)StopValidation)unset_value)BooleanFieldDecimalField	DateFieldDateTimeField	FieldList
FloatField	FormFieldIntegerField
RadioFieldSelectFieldSelectMultipleFieldStringField	TimeFieldc                       s   e Zd ZdZe Ze ZdZe ZdZ	dZ
e ZdZ fddZdde ddddddddddfddZd	d
 Zdd Zdd Zdd Zedd Zdd Zdd Ze fddZdd Zdd Zdd Zefdd Zd!d" Zd#d$ Zd%d& Z   Z!S )'Fieldz
    Field base class
    NTc                    s6   d|v rd|v rt t| | S t| g|R i |S )N_form_name)superr   __new__UnboundField)clsargskwargs	__class__ I/var/www/html/gps/gps/lib/python3.10/site-packages/wtforms/fields/core.pyr   '   s   zField.__new__ c                 C   s  |dur|| _ |dur|| _n|	dur|	j| _ntd|| _|| _|| _|| _t | _||
 | _	|
| _
t| j| _| | |pC| j| _|pI| j	| _t| j|durT|n
| |
dd | _|durh|| _t| j| jgD ]}t|dd}|D ]	}t| j|d q{qqdS )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 filters which are run on input data by `process`.
        :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 _form:
            The form holding this field. It is passed by the form itself during
            construction. You should never pass this value yourself.
        :param _name:
            The name of this field, passed by the enclosing form during its
            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` and `_name` 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_flagsr$   T)_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setattr)selfr>   r8   r0   r.   r9   r-   r?   r/   r   r   _prefixr*   _metavr2   fr$   r$   r%   __init__-   s6   /


,zField.__init__c                 C      |  S z}
        Returns a HTML representation of the field. For more powerful rendering,
        see the `__call__` method.
        r$   rD   r$   r$   r%   __unicode__}      zField.__unicode__c                 C   rJ   rK   r$   rL   r$   r$   r%   __str__   rN   zField.__str__c                 C   rJ   )z
        Returns a HTML representation of the field. For more powerful rendering,
        see the :meth:`__call__` method.
        r$   rL   r$   r$   r%   __html__   rN   zField.__html__c                 K   s   | 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)rD   r!   r$   r$   r%   __call__   s   zField.__call__c                 C   sH   |d ur |D ]}t |std|t|rtd|qd S d S )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   r8   	validatorr$   r$   r%   r7      s   
zField.check_validatorsc                 C   s   | j |S )z
        Get a translation for the given message.

        This proxies for the internal translations object.

        :param string: A unicode string to be translated.
        :return: A unicode string which is the translated output.
        )r*   r;   )rD   stringr$   r$   r%   r;      s   	zField.gettextc                 C   s   | 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)rD   singularpluralnr$   r$   r%   rY      s   zField.ngettextc              
   C   s  t | j| _d}| | z| | W n? ty9 } z|jr-|jd r-| j|jd  d}W Y d}~nd}~w tyS } z| j|jd  W Y d}~nd}~ww |sct	
| j|}| ||}z| || W n ty } z| j|jd  W Y d}~nd}~ww t| jdkS )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errorsr7   pre_validater
   r    append
ValueErrorr@   rA   r8   _run_validation_chainpost_validatelen)rD   formextra_validatorsstop_validationerA   r$   r$   r%   validate   s0   
zField.validatec                 C   s   |D ]H}z|||  W q t y0 } z|jr$|jd r$| j|jd  W Y d}~ dS d}~w tyJ } z| j|jd  W Y d}~qd}~ww dS )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_   ra   rb   )rD   rf   r8   rW   ri   r$   r$   r%   rc      s   zField._run_validation_chainc                 C      dS )z
        Override if you need field-level validation. Runs before any other
        validators.

        :param form: The form the field belongs to.
        Nr$   )rD   rf   r$   r$   r%   r`      s   zField.pre_validatec                 C   rk   )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.
        Nr$   )rD   rf   validation_stoppedr$   r$   r%   rd   	  s   	zField.post_validatec              
   C   sH  g | _ |tu rz|  }W n ty   | j}Y nw || _z| | W n ty? } z| j |jd  W Y d}~nd}~ww |durx| j	|v rQ|
| j	| _ng | _z| | j W n tyw } z| j |jd  W Y d}~nd}~ww z| jD ]}|| j| _q|W dS  ty } z| j |jd  W Y d}~dS d}~w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.
        r   N)r^   r   r-   r,   object_dataprocess_datarb   ra   r    r3   getlistraw_dataprocess_formdatar0   data)rD   formdatarr   ri   filterr$   r$   r%   process  s@   


 zField.processc                 C   s
   || _ dS )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rr   rD   valuer$   r$   r%   rn   @  s   
	zField.process_datac                 C   s   |r	|d | _ dS dS )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   Nrv   rD   	valuelistr$   r$   r%   rq   K  s   	zField.process_formdatac                 C   s   t ||| j dS )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)rC   rr   )rD   objr3   r$   r$   r%   populate_objW  s   zField.populate_obj)"r6   
__module____qualname____doc__tupler_   r^   rp   r8   r?   
_formfieldr	   r*   do_not_call_in_templatesr   rI   rM   rO   rP   rR   classmethodr7   r;   rY   rj   rc   r`   rd   r   ru   rn   rq   r|   __classcell__r$   r$   r"   r%   r      s@    
P

)	,r   c                   @   s.   e Zd ZdZdZdd ZdddZd	d
 ZdS )r   Tr   c                 O   sJ   t  jd7  _|| _|| _|| _t j| _|d}|r#| j| d S d S )N   r8   )r   creation_counterfield_classr    r!   getr7   )rD   r   r    r!   r8   r$   r$   r%   rI   e  s   
zUnboundField.__init__r&   Nc                 K   s.   t | jf||||d|}| j| ji |S )N)r   rE   r   r*   )dictr!   r   r    )rD   rf   r3   prefixtranslationsr!   kwr$   r$   r%   bindo  s   zUnboundField.bindc                 C   s   d| j j| j| jf S )Nz<UnboundField(%s, %r, %r)>)r   r6   r    r!   rL   r$   r$   r%   __repr__z  s   zUnboundField.__repr__)r&   N)r6   r}   r~   r   r   rI   r   r   r$   r$   r$   r%   r   a  s    

r   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )r1   zz
    Holds a set of boolean flags as attributes.

    Accessing a non-existing attribute returns False for its value.
    c                    s   | drtt| |S dS )Nr'   F)
startswithr   r1   __getattr__rD   r3   r"   r$   r%   r     s   
zFlags.__getattr__c                 C   s
   t | |S N)rB   r   r$   r$   r%   __contains__     
zFlags.__contains__c                 C   s    dd t | D }dd| S )Nc                 s   s    | ]
}| d s|V  qdS )r'   N)r   ).0r3   r$   r$   r%   	<genexpr>  s    z!Flags.__repr__.<locals>.<genexpr>z<wtforms.fields.Flags: {%s}>z, )dirjoin)rD   r2   r$   r$   r%   r     s   zFlags.__repr__)r6   r}   r~   r   r   r   r   r   r$   r$   r"   r%   r1   ~  s
    r1   c                   @   sB   e Zd ZdZdd Zdd Zdd Zdd	 ZdddZdd Z	d
S )r:   z
    An HTML form label.
    c                 C   s   || _ || _d S r   field_idtext)rD   r   r   r$   r$   r%   rI     s   
zLabel.__init__c                 C   rJ   r   r$   rL   r$   r$   r%   rO        zLabel.__str__c                 C   rJ   r   r$   rL   r$   r$   r%   rM     r   zLabel.__unicode__c                 C   rJ   r   r$   rL   r$   r$   r%   rP     r   zLabel.__html__Nc                 K   sT   d|v r| d|d< n|d| j tjdi |}t|p | j}td||f S )Nfor_forz<label %s>%s</label>r$   )pop
setdefaultr   r   html_paramsr   r   r   )rD   r   r!   
attributesr$   r$   r%   rR     s   zLabel.__call__c                 C   s   d| j | jf S )NzLabel(%r, %r)r   rL   r$   r$   r%   r        zLabel.__repr__r   )
r6   r}   r~   r   rI   rO   rM   rP   rR   r   r$   r$   r$   r%   r:     s    

r:   c                       sH   e Zd Ze Z	 d
 fdd	Zdd Zdd ZG dd	 d	e	Z
  ZS )SelectFieldBaseNc                    0   t t| j||fi | |d ur|| _d S d S r   )r   r   rI   option_widget)rD   r>   r8   r   r!   r"   r$   r%   rI     s   
zSelectFieldBase.__init__c                 C   s   t  )z
        Provides data for choice widget rendering. Must return a sequence or
        iterable of (value, label, selected) tuples.
        )NotImplementedErrorrL   r$   r$   r%   iter_choices  rN   zSelectFieldBase.iter_choicesc                 c   sp    t | j| jd | jd}t|  D ]#\}\}}}| jd|d| j|f d|}|d | ||_	|V  qd S )N)r?   r   r   rF   %s-%d)r>   r9   r$   )
r   r   r3   r+   	enumerater   _Optionr9   ru   checked)rD   optsirx   r>   r   optr$   r$   r%   __iter__  s    zSelectFieldBase.__iter__c                   @   s   e Zd ZdZdd ZdS )zSelectFieldBase._OptionFc                 C   
   t | jS r   )r   rr   rL   r$   r$   r%   _value  r   zSelectFieldBase._Option._valueN)r6   r}   r~   r   r   r$   r$   r$   r%   r     s    r   NNN)r6   r}   r~   r   Optionr   rI   r   r   r   r   r   r$   r$   r"   r%   r     s    r   c                       sP   e Zd Ze Zddeddf fdd	Zdd Zdd Z	d	d
 Z
dd Z  ZS )r   NTc                    s@   t t| j||fi | || _|d urt|nd | _|| _d S r   )r   r   rI   coercer]   choicesvalidate_choice)rD   r>   r8   r   r   r   r!   r"   r$   r%   rI     s   
zSelectField.__init__c                 c   sb    | j sg }nt| j d ttfr| j }nt| j | j }|D ]\}}||| || jkfV  qd S )Nr   )r   
isinstancer]   r   zipr   rr   )rD   r   rx   r>   r$   r$   r%   r     s   zSelectField.iter_choicesc              	   C   s@   z|d u rt  | || _W d S  t tfy   d | _Y d S w r   )rb   r   rr   r,   rw   r$   r$   r%   rn     s   zSelectField.process_datac                 C   s<   |rz|  |d | _W d S  ty   t| dw d S )Nr   z Invalid Choice: could not coerce)r   rr   rb   r;   ry   r$   r$   r%   rq     s   zSelectField.process_formdatac                 C   s6   | j r|  D ]
\}}}|r d S qt| dd S )NzNot a valid choice)r   r   rb   r;   )rD   rf   r'   matchr$   r$   r%   r`     s   zSelectField.pre_validate)r6   r}   r~   r   Selectr?   r   rI   r   rn   rq   r`   r   r$   r$   r"   r%   r     s    r   c                   @   s<   e Zd ZdZejddZdd Zdd Zdd	 Z	d
d Z
dS )r   z
    No different from a normal select field, except this one can take (and
    validate) multiple choices.  You'll need to specify the HTML `size`
    attribute to the select field when rendering.
    T)multiplec                 c   s<    | j D ]\}}| jd uo| || jv }|||fV  qd S r   )r   rr   r   )rD   rx   r>   selectedr$   r$   r%   r     s
   z SelectMultipleField.iter_choicesc              	      s>   zt  fdd|D  _W d S  ttfy   d  _Y d S w )Nc                 3       | ]}  |V  qd S r   r   )r   rG   rL   r$   r%   r         z3SelectMultipleField.process_data.<locals>.<genexpr>)r]   rr   rb   r,   rw   r$   rL   r%   rn     s
   z SelectMultipleField.process_datac                    s<   zt  fdd|D  _W d S  ty   t dw )Nc                 3   r   r   r   r   xrL   r$   r%   r     r   z7SelectMultipleField.process_formdata.<locals>.<genexpr>z?Invalid choice(s): one or more data inputs could not be coerced)r]   rr   rb   r;   ry   r$   rL   r%   rq     s
   z$SelectMultipleField.process_formdatac                 C   sN   | j r#tdd | jD }| j D ]}||vr"t| dt|d qd S d S )Nc                 s   s    | ]}|d  V  qdS )r   Nr$   )r   cr$   r$   r%   r     s    z3SelectMultipleField.pre_validate.<locals>.<genexpr>z0'%(value)s' is not a valid choice for this field)rx   )rr   r]   r   rb   r;   r   )rD   rf   valuesdr$   r$   r%   r`     s   
z SelectMultipleField.pre_validateN)r6   r}   r~   r   r   r   r?   r   rn   rq   r`   r$   r$   r$   r%   r     s    r   c                   @   s$   e Zd ZdZejddZe ZdS )r   z
    Like a SelectField, except displays a list of radio buttons.

    Iterating the field will produce subfields (each containing a label as
    well) in order to allow custom rendering of the individual radio fields.
    F)prefix_labelN)	r6   r}   r~   r   r   
ListWidgetr?   
RadioInputr   r$   r$   r$   r%   r   %  s    r   c                   @   s(   e Zd ZdZe Zdd Zdd ZdS )r   zx
    This field is the base for most of the more complicated fields, and
    represents an ``<input type="text">``.
    c                 C   s*   |r	|d | _ d S | j d u rd| _ d S d S Nr   r&   rv   ry   r$   r$   r%   rq   7  s
   

zStringField.process_formdatac                 C   s   | j d ur
t| j S dS )Nr&   )rr   r   rL   r$   r$   r%   r   =  s   zStringField._valueN)	r6   r}   r~   r   r   	TextInputr?   rq   r   r$   r$   r$   r%   r   0  s
    r   c                       s:   e Zd ZdZd fdd	Zdd Zdd	 Zd
d Z  ZS )LocaleAwareNumberFieldz
    Base class for implementing locale-aware number parsing.

    Locale-aware numbers require the 'babel' package to be present.
    NFc                    sL   t t| j||fi | || _|r$|| _|d jjd | _|   d S d S )Nr   r   )	r   r   rI   
use_localenumber_formatr+   localeslocale_init_babel)rD   r>   r8   r   r   r!   r"   r$   r%   rI   G  s   zLocaleAwareNumberField.__init__c                 C   s0   zddl m} || _W d S  ty   tdw )Nr   )numbersz7Using locale-aware decimals requires the babel library.)babelr   babel_numbersImportError)rD   r   r$   r$   r%   r   O  s   z"LocaleAwareNumberField._init_babelc                 C   s   | j || jS r   )r   parse_decimalr   rw   r$   r$   r%   _parse_decimalV  r   z%LocaleAwareNumberField._parse_decimalc                 C   s   | j || j| jS r   )r   format_decimalr   r   rw   r$   r$   r%   _format_decimalY  s   z&LocaleAwareNumberField._format_decimal)NNFN)	r6   r}   r~   r   rI   r   r   r   r   r$   r$   r"   r%   r   A  s    r   c                       sB   e Zd ZdZe Zd fdd	Zdd Zdd Z	d	d
 Z
  ZS )r   z
    A text field, except all input is coerced to an integer.  Erroneous input
    is ignored and will not be accepted as a value.
    Nc                       t t| j||fi | d S r   )r   r   rI   rD   r>   r8   r!   r"   r$   r%   rI   d     zIntegerField.__init__c                 C   (   | j r| j d S | jd urt| jS dS r   rp   rr   r   rL   r$   r$   r%   r   g  
   


zIntegerField._valuec              	   C   sR   |d ur$|t ur$zt|| _W d S  ttfy#   d | _t| dw d | _d S )NNot a valid integer value)r   intrr   rb   r,   r;   rw   r$   r$   r%   rn   o  s   
zIntegerField.process_datac                 C   @   |rz
t |d | _W d S  ty   d | _t| dw d S )Nr   r   )r   rr   rb   r;   ry   r$   r$   r%   rq   y     zIntegerField.process_formdataNN)r6   r}   r~   r   r   r   r?   rI   r   rn   rq   r   r$   r$   r"   r%   r   ]  s    
r   c                       sB   e Zd ZdZe Zddedf fdd	Zdd Z	dd Z
  ZS )	r   a  
    A text field which displays and coerces data of the `decimal.Decimal` type.

    :param places:
        How many decimal places to quantize the value to for display on form.
        If None, does not quantize value.
    :param rounding:
        How to round the value during quantize, for example
        `decimal.ROUND_UP`. If unset, uses the rounding value from the
        current thread's context.
    :param use_locale:
        If True, use locale-based number formatting. Locale-based number
        formatting requires the 'babel' package.
    :param number_format:
        Optional number format for locale. If omitted, use the default decimal
        format for the locale.
    Nc                    sT   t t| j||fi | | jr|tus|d urtd|tu r"d}|| _|| _d S )NzEWhen using locale-aware numbers, 'places' and 'rounding' are ignored.   )r   r   rI   r   r   r,   placesrounding)rD   r>   r8   r   r   r!   r"   r$   r%   rI     s   
zDecimalField.__init__c                 C   s   | j r| j d S | jd urV| jrt| | jS | jd urQt| jdrGtd| j }| j	d u r:| j
|}t|S | jj
|| j	d}t|S d| j }|| j S t| jS dS )Nr   quantizez.1)r   z%%0.%dfr&   )rp   rr   r   r   r   r   hasattrdecimalDecimalr   r   )rD   exp	quantizedrT   r$   r$   r%   r     s"   






zDecimalField._valuec              	   C   sd   |r0z| j r| |d | _W d S t|d | _W d S  tjtfy/   d | _t| dw d S )Nr   zNot a valid decimal value)r   r   rr   r   r   InvalidOperationrb   r;   ry   r$   r$   r%   rq     s   zDecimalField.process_formdata)r6   r}   r~   r   r   r   r?   r   rI   r   rq   r   r$   r$   r"   r%   r     s    
r   c                       s:   e Zd ZdZe Zd	 fdd	Zdd Zdd Z	  Z
S )
r   z
    A text field, except all input is coerced to an float.  Erroneous input
    is ignored and will not be accepted as a value.
    Nc                    r   r   )r   r   rI   r   r"   r$   r%   rI     r   zFloatField.__init__c                 C   r   r   r   rL   r$   r$   r%   r     r   zFloatField._valuec                 C   r   )Nr   zNot a valid float value)floatrr   rb   r;   ry   r$   r$   r%   rq     r   zFloatField.process_formdatar   r6   r}   r~   r   r   r   r?   rI   r   rq   r   r$   r$   r"   r%   r     s    r   c                       sF   e Zd ZdZe ZdZd fdd	Zdd Z	dd	 Z
d
d Z  ZS )r   a  
    Represents an ``<input type="checkbox">``. Set the ``checked``-status by using the
    ``default``-option. Any value for ``default``, e.g. ``default="checked"`` puts
    ``checked`` into the html-element and sets the ``data`` to ``True``

    :param false_values:
        If provided, a sequence of strings each of which is an exact match
        string of what is considered a "false" value. Defaults to the tuple
        ``(False, 'false', '',)``
    )Ffalser&   Nc                    r   r   )r   r   rI   false_values)rD   r>   r8   r   r!   r"   r$   r%   rI     s   
zBooleanField.__init__c                 C   s   t || _d S r   )boolrr   rw   r$   r$   r%   rn     s   zBooleanField.process_datac                 C   s&   |r	|d | j v rd| _d S d| _d S )Nr   FT)r   rr   ry   r$   r$   r%   rq     s   

zBooleanField.process_formdatac                 C   s   | j r
t| j d S dS )Nr   y)rp   r   rL   r$   r$   r%   r     s   zBooleanField._valuer   )r6   r}   r~   r   r   CheckboxInputr?   r   rI   rn   rq   r   r   r$   r$   r"   r%   r     s    
r   c                       s:   e Zd ZdZe Zd
 fdd	Zdd Zdd	 Z	  Z
S )r   zL
    A text field which stores a `datetime.datetime` matching a format.
    N%Y-%m-%d %H:%M:%Sc                    s$   t t| j||fi | || _d S r   )r   r   rI   rT   rD   r>   r8   rT   r!   r"   r$   r%   rI     s   
zDateTimeField.__init__c                 C   s*   | j r	d| j S | jr| j| jpdS )Nr(   r&   )rp   r   rr   strftimerT   rL   r$   r$   r%   r     s   zDateTimeField._valuec                 C   sN   |r%d |}ztj|| j| _W d S  ty$   d | _t| dw d S )Nr(   zNot a valid datetime value)r   datetimestrptimerT   rr   rb   r;   rD   rz   date_strr$   r$   r%   rq     s   
zDateTimeField.process_formdata)NNr   r   r$   r$   r"   r%   r     s    r   c                       *   e Zd ZdZd fdd	Zdd Z  ZS )	r   zA
    Same as DateTimeField, except stores a `datetime.date`.
    N%Y-%m-%dc                        t t| j|||fi | d S r   )r   r   rI   r   r"   r$   r%   rI          zDateField.__init__c                 C   R   |r'd |}ztj|| j | _W d S  ty&   d | _t| dw d S )Nr(   zNot a valid date value)r   r   r   rT   daterr   rb   r;   r   r$   r$   r%   rq   #     
zDateField.process_formdata)NNr   r6   r}   r~   r   rI   rq   r   r$   r$   r"   r%   r         r   c                       r   )	r   z8
    Same as DateTimeField, except stores a `time`.
    N%H:%Mc                    r   r   )r   r   rI   r   r"   r$   r%   rI   1  r   zTimeField.__init__c                 C   r   )Nr(   zNot a valid time value)r   r   r   rT   timerr   rb   r;   )rD   rz   time_strr$   r$   r%   rq   4  r  zTimeField.process_formdata)NNr  r  r$   r$   r"   r%   r   -  r  r   c                       s|   e Zd ZdZe Zd fdd	ZefddZ	e
 fdd	Zd
d Zdd Zdd Zdd Zedd Zedd Z  ZS )r   a-  
    Encapsulate a form as a field in another form.

    :param form_class:
        A subclass of Form that will be encapsulated.
    :param separator:
        A string which will be suffixed to this field's name to create the
        prefix to enclosed fields. The default is fine for most uses.
    N-c                    sJ   t t| j||fi | || _|| _d | _| jrtd|r#tdd S )NzGFormField cannot take filters, as the encapsulated data is not mutable.zTFormField does not accept any validators. Instead, define them on the enclosed form.)r   r   rI   
form_class	separator_objr0   r,   )rD   r	  r>   r8   r
  r!   r"   r$   r%   rI   J  s   zFormField.__init__c                 C   s   |t u rz|  }W n ty   | j}Y nw || _|| _| j| j }t|tr6| j	d||d|| _
d S | j	|||d| _
d S )N)rs   r   )rs   r{   r   r$   )r   r-   r,   r  rm   r3   r
  r   r   r	  rf   )rD   rs   rr   r   r$   r$   r%   ru   T  s   

zFormField.processc                 C   s   |rt d| j S )NzWFormField does not accept in-line validators, as it gets errors from the enclosed form.)r,   rf   rj   )rD   rf   rg   r$   r$   r%   rj   d  s   
zFormField.validatec                 C   sH   t ||d }|d u r| jd u rtd| j}t||| | j| d S )NzZpopulate_obj: cannot find a value to populate from the provided obj or input data/defaults)rB   r  r,   rC   rf   r|   )rD   r{   r3   	candidater$   r$   r%   r|   i  s   
zFormField.populate_objc                 C   r   r   )iterrf   rL   r$   r$   r%   r   s  r   zFormField.__iter__c                 C   
   | j | S r   )rf   r   r$   r$   r%   __getitem__v  r   zFormField.__getitem__c                 C   s   t | j|S r   )rB   rf   r   r$   r$   r%   r   y  s   zFormField.__getattr__c                 C      | j jS r   )rf   rr   rL   r$   r$   r%   rr   |     zFormField.datac                 C   r  r   )rf   r_   rL   r$   r$   r%   r_     r  zFormField.errors)NNr  )r6   r}   r~   r   r   TableWidgetr?   rI   r   ru   r   rj   r|   r   r  r   propertyrr   r_   r   r$   r$   r"   r%   r   >  s    	


r   c                       s   e Zd ZdZe Zdddde f fdd	Ze	fddZ
dd	 Ze fd
dZdd Zde	dfddZe	fddZdd Zdd Zdd Zdd Zedd Z  ZS )r   a~  
    Encapsulate an ordered list of multiple instances of the same field type,
    keeping data as a list.

    >>> authors = FieldList(StringField('Name', [validators.required()]))

    :param unbound_field:
        A partially-instantiated field definition, just like that would be
        defined on a form directly.
    :param min_entries:
        if provided, always have at least this many entries on the field,
        creating blank ones if the provided input does not specify a sufficient
        amount.
    :param max_entries:
        accept no more than this many entries as input, even if more exist in
        formdata.
    Nr   c                    sh   t t| j||fd|i| | jrtdt|tsJ d|| _|| _|| _	d| _
|dd| _d S )Nr-   zRFieldList does not accept any filters. Instead, define them on the enclosed field.z(Field must be unbound, not a field classrE   r&   )r   r   rI   r0   r,   r   r   unbound_fieldmin_entriesmax_entries
last_indexr   rE   )rD   r  r>   r8   r  r  r-   r!   r"   r$   r%   rI     s   zFieldList.__init__c              	   C   s   g | _ |tu s	|sz|  }W n ty   | j}Y nw || _|rZtt| | j|}| j	r6|d | j	 }t
|}|D ]}zt|}W n tyO   t}Y nw | j|||d q<n|D ]}| || q\t| j | jk r|| | t| j | jk smd S d S )N)index)entriesr   r-   r,   rm   sortedset_extract_indicesr3   r  r  nextStopIteration
_add_entryre   r  )rD   rs   rr   indicesidatar  obj_datar$   r$   r%   ru     s4   

zFieldList.processc                 c   sP    t |d }|D ]}||r%||d ddd }| r%t|V  q	dS )a&  
        Yield indices of any keys with given prefix.

        formdata must be an object which will produce keys when iterated.  For
        example, if field 'foo' contains keys 'foo-0-bar', 'foo-1-baz', then
        the numbers 0 and 1 will be yielded, but not neccesarily in order.
        r   Nr  r   )re   r   splitisdigitr   )rD   r   rs   offsetkr$   r$   r%   r    s   

zFieldList._extract_indicesc                 C   sl   g | _ | jD ]}|| | j |j  qtdd | j D s"g | _ t| j|}| || t	| j dkS )z
        Validate this FieldList.

        Note that FieldList validation differs from normal field validation in
        that FieldList validates all its enclosed fields first before running any
        of its own validators.
        c                 s   s    | ]}|V  qd S r   r$   r   r$   r$   r%   r     s    z%FieldList.validate.<locals>.<genexpr>r   )
r_   r  rj   ra   anyr@   rA   r8   rc   re   )rD   rf   rg   subfieldrA   r$   r$   r%   rj     s   

zFieldList.validatec                 C   s   t ||d }zt|}W n ty   tg }Y nw t|td }ttdtfi }g }t	| j
|D ]\}}	| }
|	|
_||
d ||
j q4t||| d S )N_fakerr   )rB   r  r,   r@   rA   repeatr5   strobjectr   r  rr   r|   ra   rC   )rD   r{   r3   r   ivalues
candidatesr*  outputfieldrr   fake_objr$   r$   r%   r|     s   zFieldList.populate_objc                 C   s   | j rt| j| j k sJ d|d u r| jd }|| _d| j|f }d| j|f }| jjd || j|| j	| j
d}||| | j| |S )Nz?You cannot have more than max_entries entries in this FieldListr   r   )rf   r3   r   r9   rF   r   )r  re   r  r  r4   r9   r  r   rE   r+   r*   ru   ra   )rD   rs   rr   r  r3   r9   r1  r$   r$   r%   r     s   
zFieldList._add_entryc                 C   s   | j |dS )z
        Create a new entry with optional default data.

        Entries added in this way will *not* receive formdata however, and can
        only receive object data.
        rv   )r   )rD   rr   r$   r$   r%   append_entry  s   zFieldList.append_entryc                 C   s   | j  }|  jd8  _|S )z6 Removes the last entry from the list and returns it. r   )r  r   r  )rD   entryr$   r$   r%   	pop_entry  s   
zFieldList.pop_entryc                 C   r   r   )r  r  rL   r$   r$   r%   r     r   zFieldList.__iter__c                 C   r   r   )re   r  rL   r$   r$   r%   __len__  r   zFieldList.__len__c                 C   r  r   r  )rD   r  r$   r$   r%   r    r   zFieldList.__getitem__c                 C   s   dd | j D S )Nc                 S   s   g | ]}|j qS r$   rv   )r   rH   r$   r$   r%   
<listcomp>"  s    z"FieldList.data.<locals>.<listcomp>r7  rL   r$   r$   r%   rr      s   zFieldList.data)r6   r}   r~   r   r   r   r?   r   rI   r   ru   r  rj   r|   r   r3  r5  r   r6  r  r  rr   r   r$   r$   r"   r%   r     s$    	r   )*
__future__r   r   r   r@   rU   r   
markupsafer   r   wtformsr   wtforms.compatr   r   wtforms.i18nr	   wtforms.validatorsr
   wtforms.utilsr   __all__r-  r   r   r1   r:   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r$   r$   r$   r%   <module>   sD      I%/!%B#G