
    ihG                     V    S SK r S SKJr  SSKJr  SSKJr  SSKJr  Sr " S	 S
\5      r	g)    N)unset_value   )widgets   )Field)UnboundField)	FieldListc                      ^  \ rS rSrSr\R                  " 5       r      SU 4S jjr\	S4S jr
S rSS jrS rS\	S4S	 jr\	4S
 jrS rS rS rS r\S 5       rSrU =r$ )r	      a  
Encapsulate an ordered list of multiple instances of the same field type,
keeping data as a list.

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

: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.
:param separator:
    A string which will be suffixed to this field's name to create the
    prefix to enclosed list entries. The default is fine for most uses.
Nc                 J  > [         T	U ]  " X#4SU0UD6  U R                  (       a  [        S5      e[	        U[
        5      (       d   S5       eXl        X@l        XPl        SU l	        UR                  SS5      U l        X`l        UR                  R                  SS5      U l        g )	NdefaultRFieldList does not accept any filters. Instead, define them on the enclosed field.z(Field must be unbound, not a field class_prefix 	separator-)super__init__filters	TypeError
isinstancer   unbound_fieldmin_entriesmax_entries
last_indexgetr   
_separatorkwargs_field_separator)
selfr   label
validatorsr   r   r   r   r   	__class__s
            V/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/wtforms/fields/list.pyr   FieldList.__init__$   s     	FGFvF<</  <
 
 	65	6 
 +&&zz)R0# - 4 4 8 8c J    c                    U(       a  [        S5      e/ U l        U[        L d  U(       d   U R                  5       nX l        U(       a  [        [        U R                  U R                  U5      5      5      nU R                  (       a  US U R                   n[        U5      nU H  n [        U5      nU R                  XUS9  M!     OU H  nU R                  X5        M     [        U R                  5      U R                  :  a7  U R                  U5        [        U R                  5      U R                  :  a  M6  g g ! [          a    U R                  n GNf = f! [         a	    [        n Nf = f)Nr   )index)r   entriesr   r   object_datasortedset_extract_indicesnamer   iternextStopIteration
_add_entrylenr   )r!   formdatadataextra_filtersindicesidatar)   obj_datas           r%   processFieldList.process@   s9   / 
 ;d$||~  S!6!6tyy(!KLMG!"4D$4$45JE +#E{H %@ ! !3 ! $,,$"2"22OOH% $,,$"2"22+  $||$ % +*H+s#   D< 'E<EEE,+E,c              #      #    [        U5      S-   nU H`  nUR                  U5      (       d  M  XCS R                  U R                  S5      S   nUR	                  5       (       d  MS  [        U5      v   Mb     g7f)z
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 necessarily in order.
r   Nr   )r4   
startswithsplitr    isdigitint)r!   prefixr5   offsetks        r%   r.   FieldList._extract_indicesc   sb      VqA||F##gJ$$T%:%:A>qA99;;a&L	 s   (A84A8&A8c                    / U l         U R                   H9  nUR                  U5        U R                   R                  UR                   5        M;     [	        S U R                    5       5      (       d  / U l         [
        R                  " U R                  U5      nU R                  X5        [        U R                   5      S:H  $ )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              3   $   #    U  H  ov   M     g 7fN ).0xs     r%   	<genexpr>%FieldList.validate.<locals>.<genexpr>   s     *k1ks   r   )
errorsr*   validateappendany	itertoolschainr#   _run_validation_chainr4   )r!   formextra_validatorssubfieldrS   s        r%   rO   FieldList.validater   s      Hd#KKx/ % *dkk***DK1AB""4/4;;1$$r'   c                    [        XS 5      n [        U5      n[        R                  " U[        R
                  " S 5      5      n[        S[        40 5      n/ n[        U R                  U5       H?  u  pU" 5       n
Xl
        UR                  U
S5        UR                  U
R                  5        MA     [        XU5        g ! [         a    [        / 5      n Nf = f)N_faker6   )getattrr0   r   rR   rS   repeattypeobjectzipr*   r6   populate_objrP   setattr)r!   objr/   valuesivalues
candidatesrZ   outputfieldr6   fake_objs              r%   r`   FieldList.populate_obj   s    D)	6lG __Wi.>.>t.DE
Wvi,t||Z8KEwH Mx0MM(--(	 9 	6"  	2hG	s   B> >CCc           	         U R                   (       a*  [        U R                  5      U R                   :  d   S5       eUc  U R                  S-   nX0l        U R                   U R
                   U 3nU R                   U R
                   U 3nU R                  R                  S UU R                  UU R                  U R                  S9nUR                  X5        U R                  R                  U5        U$ )Nz?You cannot have more than max_entries entries in this FieldListr   )rU   r/   rB   id_metatranslations)r   r4   r*   r   
short_namer   rk   r   bindr   meta_translationsr;   rP   )r!   r5   r6   r)   r/   rk   rg   s          r%   r3   FieldList._add_entry   s      C$58H8H$H	ML	MH=OOa'E//"4??"3E7;y)%1""''<<))++ ( 
 	h%E"r'   c                      U R                  US9$ )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.
)r6   )r3   )r!   r6   s     r%   append_entryFieldList.append_entry   s     D))r'   c                 d    U R                   R                  5       nU =R                  S-  sl        U$ )z4Removes the last entry from the list and returns it.r   )r*   popr   )r!   entrys     r%   	pop_entryFieldList.pop_entry   s'      "1r'   c                 ,    [        U R                  5      $ rH   )r0   r*   r!   s    r%   __iter__FieldList.__iter__   s    DLL!!r'   c                 ,    [        U R                  5      $ rH   )r4   r*   r|   s    r%   __len__FieldList.__len__   s    4<<  r'   c                      U R                   U   $ rH   )r*   )r!   r)   s     r%   __getitem__FieldList.__getitem__   s    ||E""r'   c                 X    U R                    Vs/ s H  oR                  PM     sn$ s  snf rH   )r*   r6   )r!   fs     r%   r6   FieldList.data   s      $-1---s   ')
r    r   r   r*   rN   r   r   r   r+   r   )NNr   Nr   rI   )rI   )__name__
__module____qualname____firstlineno____doc__r   
ListWidgetwidgetr   r   r;   r.   rO   r`   r3   rt   ry   r}   r   r   propertyr6   __static_attributes____classcell__)r$   s   @r%   r	   r	      s    * !F
 K8 &1 !&F!%.#$ #'[ * !, *"!# . .r'   r	   )
rR   wtforms.utilsr   r   r   corer   r   __all__r	   rI   r'   r%   <module>r      s'     %   
~. ~.r'   