
    wdfQ                        d dl mZ d dlZd dlZd dlZd dlZ	 d dlZn# e$ r dZY nw xY w	 d dlZn# e$ r dZY nw xY wd dl	m
Z
mZ dZ G d de          Z G d de          Z G d	 d
e          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d d e          Z G d! d"e          Z G d# d$e          Z G d% d&e          Z  G d' d(e          Z!eZ"eZ#eZ$eZ%eZ&eZ'eZ(eZ)eZ*eZ+eZ,eZ-eZ.e Z/dS ))    )unicode_literalsN)string_types	text_type)DataRequireddata_requiredEmailemailEqualToequal_to	IPAddress
ip_addressInputRequiredinput_requiredLengthlengthNumberRangenumber_rangeOptionaloptionalRequiredrequiredRegexpregexpURLurlAnyOfany_ofNoneOfnone_of
MacAddressmac_addressUUIDValidationErrorStopValidationc                       e Zd ZdZddZdS )r#   z>
    Raised when a validator fails to validate its input.
     c                 2    t          j        | |g|R i | d S N)
ValueError__init__selfmessageargskwargss       W/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/wtforms/validators.pyr*   zValidationError.__init__!   s+    D';D;;;F;;;;;    Nr&   __name__
__module____qualname____doc__r*    r1   r0   r#   r#      s2         < < < < < <r1   r#   c                       e Zd ZdZddZdS )r$   z
    Causes the validation chain to stop.

    If StopValidation is raised, no more validators in the validation chain are
    called. If raised with a message, the message will be added to the errors
    list.
    r&   c                 2    t          j        | |g|R i | d S r(   )	Exceptionr*   r+   s       r0   r*   zStopValidation.__init__-   s+    4:4:::6:::::r1   Nr2   r3   r8   r1   r0   r$   r$   %   s2         ; ; ; ; ; ;r1   r$   c                        e Zd ZdZddZd ZdS )r
   a9  
    Compares the values of two fields.

    :param fieldname:
        The name of the other field to compare to.
    :param message:
        Error message to raise in case of a validation error. Can be
        interpolated with `%(other_label)s` and `%(other_name)s` to provide a
        more helpful error.
    Nc                 "    || _         || _        d S r(   )	fieldnamer-   )r,   r>   r-   s      r0   r*   zEqualTo.__init__<   s    "r1   c                 j   	 || j                  }n8# t          $ r+ t          |                    d          | j         z            w xY w|j        |j        k    r[t          |d          r|j        j        p| j         | j         d}| j        }||                    d          }t          ||z            d S )NzInvalid field name '%s'.label)other_label
other_namez&Field must be equal to %(other_name)s.)	r>   KeyErrorr#   gettextdatahasattrr@   textr-   )r,   formfieldotherdr-   s         r0   __call__zEqualTo.__call__@   s    	^(EE 	^ 	^ 	^!%--0J"K"Kdn"\]]]	^:##&ug66K5;;K]t~"n A lG--(PQQ!'A+... $#s	    5Ar(   r4   r5   r6   r7   r*   rL   r8   r1   r0   r
   r
   1   sA        	 	   / / / / /r1   r
   c                        e Zd ZdZddZd ZdS )r   a  
    Validates the length of a string.

    :param min:
        The minimum required length of the string. If not provided, minimum
        length will not be checked.
    :param max:
        The maximum length of the string. If not provided, maximum length
        will not be checked.
    :param message:
        Error message to raise in case of a validation error. Can be
        interpolated using `%(min)d` and `%(max)d` if desired. Useful defaults
        are provided depending on the existence of min and max.
    Nc                     |dk    s|dk    s
J d            |dk    s||k    s
J d            || _         || _        || _        d S )NrO   z1At least one of `min` or `max` must be specified.z `min` cannot be more than `max`.minmaxr-   r,   rR   rS   r-   s       r0   r*   zLength.__init__`   sS    byyC2III'ZIIIbyyC3JJJ(JJJJr1   c                    |j         rt          |j                   pd}|| j        k     s| j        dk    r|| j        k    r| j        }|| j        dk    r|                    dd| j                  }nj| j        dk    r|                    dd| j                  }nB| j        | j        k    r|                    dd| j                  }n|                    d	          }t          |t          | j        | j        |
          z            d S d S )Nr   rO   z.Field must be at least %(min)d character long.z/Field must be at least %(min)d characters long.z.Field cannot be longer than %(max)d character.z/Field cannot be longer than %(max)d characters.z-Field must be exactly %(max)d character long.z.Field must be exactly %(max)d characters long.z:Field must be between %(min)d and %(max)d characters long.)rR   rS   r   )	rE   lenrR   rS   r-   ngettextrD   r#   dict)r,   rH   rI   lr-   s        r0   rL   zLength.__call__g   s   J*3uz??/atx<<48r>>a$(lllG8r>>#nn-]-^`d`hj jGGX^^#nn-]-^`d`hj jGGX))#nn-\-]_c_gi iGG $mm,hiiG!'DTX48TU,V,V,V"VWWW *>llr1   )rO   rO   NrM   r8   r1   r0   r   r   Q   sF            X X X X Xr1   r   c                        e Zd ZdZddZd ZdS )r   a  
    Validates that a number is of a minimum and/or maximum value, inclusive.
    This will work with any comparable number type, such as floats and
    decimals, not just integers.

    :param min:
        The minimum required value of the number. If not provided, minimum
        value will not be checked.
    :param max:
        The maximum value of the number. If not provided, maximum value
        will not be checked.
    :param message:
        Error message to raise in case of a validation error. Can be
        interpolated using `%(min)s` and `%(max)s` if desired. Useful defaults
        are provided depending on the existence of min and max.
    Nc                 0    || _         || _        || _        d S r(   rQ   rT   s       r0   r*   zNumberRange.__init__   s    r1   c                    |j         }|8t          j        |          s$| j        || j        k     s| j        || j        k    r| j        }|O| j        |                    d          }n2| j        |                    d          }n|                    d          }t          |t          | j        | j                  z            d S d S )Nz Number must be at least %(min)s.zNumber must be at most %(max)s.z+Number must be between %(min)s and %(max)s.)rR   rS   )	rE   mathisnanrR   rS   r-   rD   r#   rX   )r,   rH   rI   rE   r-   s        r0   rL   zNumberRange.__call__   s    z<4:d++<0DPTPX%$//lG 8##mm,NOOGGX%#mm,MNNGG#mm,YZZG!'DTX48,L,L,L"LMMM &%//r1   )NNNrM   r8   r1   r0   r   r   {   sF             
N N N N Nr1   r   c                   $    e Zd ZdZdZddZd ZdS )r   a=  
    Allows empty input and stops the validation chain from continuing.

    If input is empty, also removes prior errors (such as processing errors)
    from the field.

    :param strip_whitespace:
        If True (the default) also stop the validation chain on input which
        consists of only whitespace.
    )r   Tc                 .    |r
d | _         d S d | _         d S )Nc                 *    |                                  S r(   )stripss    r0   <lambda>z#Optional.__init__.<locals>.<lambda>   s    !'')) r1   c                     | S r(   r8   rc   s    r0   re   z#Optional.__init__.<locals>.<lambda>   s    ! r1   )string_check)r,   strip_whitespaces     r0   r*   zOptional.__init__   s+     	, 3 3D +Dr1   c                     |j         r@t          |j         d         t                    r:|                     |j         d                   sg |j        d d <   t                      d S d S )Nr   )raw_data
isinstancer   rg   errorsr$   )r,   rH   rI   s      r0   rL   zOptional.__call__   ss    ~ 	#EN1,=|!L!L 	#UYUfUfglguvwgxUyUy 	# ELO """	# 	# 	# 	#r1   N)Tr4   r5   r6   r7   field_flagsr*   rL   r8   r1   r0   r   r      sH        	 	 !K, , , ,# # # # #r1   r   c                   $    e Zd ZdZdZddZd ZdS )r   a  
    Checks the field's data is 'truthy' otherwise stops the validation chain.

    This validator checks that the ``data`` attribute on the field is a 'true'
    value (effectively, it does ``if field.data``.) Furthermore, if the data
    is a string type, a string containing only whitespace characters is
    considered false.

    If the data is empty, also removes prior errors (such as processing errors)
    from the field.

    **NOTE** this validator used to be called `Required` but the way it behaved
    (requiring coerced data, not input data) meant it functioned in a way
    which was not symmetric to the `Optional` validator and furthermore caused
    confusion with certain fields which coerced data to 'falsey' values like
    ``0``, ``Decimal(0)``, ``time(0)`` etc. Unless a very specific reason
    exists, we recommend using the :class:`InputRequired` instead.

    :param message:
        Error message to raise in case of a validation error.
    r   Nc                     || _         d S r(   r-   r,   r-   s     r0   r*   zDataRequired.__init__       r1   c                     |j         r3t          |j         t                    rX|j                                         sA| j        |                    d          }n| j        }g |j        d d <   t          |          d S d S )NThis field is required.)rE   rk   r   rb   r-   rD   rl   r$   r,   rH   rI   r-   s       r0   rL   zDataRequired.__call__   s    z 	*Z
LAA 	*%*JZJZJ\J\ 	*|#--(ABB, ELO )))	* 	* 	* 	*r1   r(   rm   r8   r1   r0   r   r      sH         * !K   * * * * *r1   r   c                   "     e Zd ZdZ fdZ xZS )r   z
    Legacy alias for DataRequired.

    This is needed over simple aliasing for those who require that the
    class-name of required be 'Required.'

    c                      t          t          |           j        |i | t          j        dt
          d           d S )Nz7Required is going away in WTForms 3.0, use DataRequired   )
stacklevel)superr   r*   warningswarnDeprecationWarning)r,   r.   r/   	__class__s      r0   r*   zRequired.__init__   sP    &h&7777E1	
 	
 	
 	
 	
 	
r1   )r4   r5   r6   r7   r*   __classcell__r   s   @r0   r   r      sB         
 
 
 
 
 
 
 
 
r1   r   c                   $    e Zd ZdZdZddZd ZdS )r   z
    Validates that input was provided for this field.

    Note there is a distinction between this and DataRequired in that
    InputRequired looks that form-input data was provided, and DataRequired
    looks at the post-coercion data.
    rp   Nc                     || _         d S r(   rr   rs   s     r0   r*   zInputRequired.__init__   rt   r1   c                     |j         r|j         d         s?| j        |                    d          }n| j        }g |j        d d <   t	          |          d S )Nr   rv   )rj   r-   rD   rl   r$   rw   s       r0   rL   zInputRequired.__call__   sd    ~ 	*U^A%6 	*|#--(ABB, ELO )))	* 	*r1   r(   rm   r8   r1   r0   r   r      sH          !K   * * * * *r1   r   c                   "    e Zd ZdZddZddZdS )r   a  
    Validates the field against a user provided regexp.

    :param regex:
        The regular expression string to use. Can also be a compiled regular
        expression pattern.
    :param flags:
        The regexp flags to use, for example re.IGNORECASE. Ignored if
        `regex` is not a string.
    :param message:
        Error message to raise in case of a validation error.
    r   Nc                 v    t          |t                    rt          j        ||          }|| _        || _        d S r(   )rk   r   recompileregexr-   )r,   r   flagsr-   s       r0   r*   zRegexp.__init__  s7    e\** 	-Jue,,E
r1   c                     | j                             |j        pd          }|s5|$| j        |                    d          }n| j        }t          |          |S )Nr&   zInvalid input.)r   matchrE   r-   rD   r#   )r,   rH   rI   r-   r   s        r0   rL   zRegexp.__call__  sa    
  !1r22 	+<'#mm,<==GG"lG!'***r1   )r   Nr(   rM   r8   r1   r0   r   r   
  sF            
 
 
 
 
 
r1   r   c                   V    e Zd ZdZ ej        dej                  Z	 	 	 	 	 ddZd Z	dS )	r   a  
    Validates an email address. Requires email_validator package to be
    installed. For ex: pip install wtforms[email].

    :param message:
        Error message to raise in case of a validation error.
    :param granular_messsage:
        Use validation failed message from email_validator library
        (Default False).
    :param check_deliverability:
        Perform domain name resolution check (Default False).
    :param allow_smtputf8:
        Fail validation for addresses that would require SMTPUTF8
        (Default True).
    :param allow_empty_local:
        Allow an empty local part (i.e. @example.com), e.g. for validating
        Postfix aliases (Default False).
    z(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*\Z|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"\Z)NFTc                 x    t           t          d          || _        || _        || _        || _        || _        d S )Nz7Install 'email_validator' for email validation support.)email_validatorr;   r-   granular_messagecheck_deliverabilityallow_smtputf8allow_empty_local)r,   r-   r   r   r   r   s         r0   r*   zEmail.__init__C  sF     "UVVV 0$8!,!2r1   c                 V   	 |j         t          j                    t          j        |j         | j        | j        | j                   d S # t          j        $ rO}| j        }|2| j        r|	                    |          }n|	                    d          }t          |          d }~ww xY w)N)r   r   r   zInvalid email address.)rE   r   EmailNotValidErrorvalidate_emailr   r   r   r-   r   rD   r#   )r,   rH   rI   er-   s        r0   rL   zEmail.__call__S  s    	+z!%8:::*
%)%>#2"&"8	      1 	+ 	+ 	+lG( F#mmA..GG#mm,DEEG!'***	+s   AA
 
B(A
B##B()NFFTF)
r4   r5   r6   r7   r   r   
IGNORECASE
user_regexr*   rL   r8   r1   r0   r   r   *  sr         & 	]
 J "3 3 3 3 + + + + +r1   r   c                   L    e Zd ZdZd	dZd Zed             Zed             ZdS )
r   aV  
    Validates an IP address. Requires ipaddress package to be instaled for Python 2 support.

    :param ipv4:
        If True, accept IPv4 addresses as valid (default True)
    :param ipv6:
        If True, accept IPv6 addresses as valid (default False)
    :param message:
        Error message to raise in case of a validation error.
    TFNc                     t           t          d          |s|st          d          || _        || _        || _        d S )Nz)Install 'ipaddress' for Python 2 support.zDIP Address Validator must have at least one of ipv4 or ipv6 enabled.)	ipaddressr;   r)   ipv4ipv6r-   )r,   r   r   r-   s       r0   r*   zIPAddress.__init__r  sP    GHHH 	eD 	ecddd		r1   c                     |j         }d}|r8| j        r|                     |          p| j        o|                     |          }|s-| j        }||                    d          }t          |          d S )NFzInvalid IP address.)rE   r   
check_ipv4r   
check_ipv6r-   rD   r#   )r,   rH   rI   valuevalidr-   s         r0   rL   zIPAddress.__call__{  s    
 	eY94??5#9#9dty?cT__]bMcMcE 	+lG--(=>>!'***		+ 	+r1   c                     	 t          j        |          }n# t          $ r Y dS w xY wt          |t           j                  sdS dS NFT)r   r   r)   rk   IPv4Addressclsr   addresss      r0   r   zIPAddress.check_ipv4  \    	*511GG 	 	 	55	 '9#899 	5t    
%%c                     	 t          j        |          }n# t          $ r Y dS w xY wt          |t           j                  sdS dS r   )r   r   r)   rk   IPv6Addressr   s      r0   r   zIPAddress.check_ipv6  r   r   )TFN)	r4   r5   r6   r7   r*   rL   classmethodr   r   r8   r1   r0   r   r   g  sw        	 	   
+ 
+ 
+ 	 	 [	 	 	 [	 	 	r1   r   c                   .     e Zd ZdZd fd	Z fdZ xZS )r    zu
    Validates a MAC address.

    :param message:
        Error message to raise in case of a validation error.
    Nc                 `    d}t          t          |                               ||           d S )Nz&^(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$rr   )r|   r    r*   )r,   r-   patternr   s      r0   r*   zMacAddress.__init__  s1    ;j$(('(BBBBBr1   c                     | j         }||                    d          }t          t          |                               |||           d S )NzInvalid Mac address.)r-   rD   r|   r    rL   )r,   rH   rI   r-   r   s       r0   rL   zMacAddress.__call__  sI    ,?mm$:;;Gj$((ug>>>>>r1   r(   r4   r5   r6   r7   r*   rL   r   r   s   @r0   r    r      sf         C C C C C C? ? ? ? ? ? ? ? ?r1   r    c                   .     e Zd ZdZd fd	Z fdZ xZS )r   a  
    Simple regexp based url validation. Much like the email validator, you
    probably want to validate the url later by other means if the url must
    resolve.

    :param require_tld:
        If true, then the domain-name portion of the URL must contain a .tld
        suffix.  Set this to false if you want to allow domains like
        `localhost`.
    :param message:
        Error message to raise in case of a validation error.
    TNc                     d}t          t          |                               |t          j        |           t          |d          | _        d S )NzP^[a-z]+://(?P<host>[^\/\?:]+)(?P<port>:[0-9]+)?(?P<path>\/.*?)?(?P<query>\?.*)?$Trequire_tldallow_ip)r|   r   r*   r   r   HostnameValidationvalidate_hostname)r,   r   r-   r   r   s       r0   r*   zURL.__init__  sV    ! 	 	c4!!%@@@!3#"
 "
 "
r1   c                    | j         }||                    d          }t          t          |                               |||          }|                     |                    d                    st          |          d S )NzInvalid URL.host)r-   rD   r|   r   rL   r   groupr#   )r,   rH   rI   r-   r   r   s        r0   rL   zURL.__call__  s{    ,?mmN33Gc4  ))$w??%%ekk&&9&9:: 	+!'***	+ 	+r1   )TNr   r   s   @r0   r   r     s`         
 
 
 
 
 
+ + + + + + + + +r1   r   c                        e Zd ZdZddZd ZdS )r"   zn
    Validates a UUID.

    :param message:
        Error message to raise in case of a validation error.
    Nc                     || _         d S r(   rr   rs   s     r0   r*   zUUID.__init__  rt   r1   c                     | j         }||                    d          }	 t          j        |j                   d S # t
          $ r t          |          w xY w)NzInvalid UUID.)r-   rD   uuidr"   rE   r)   r#   rw   s       r0   rL   zUUID.__call__  se    ,?mmO44G	+Iej!!!!! 	+ 	+ 	+!'***	+s	   ; Ar(   rM   r8   r1   r0   r"   r"     sA            + + + + +r1   r"   c                   6    e Zd ZdZddZd Zed             ZdS )r   ae  
    Compares the incoming data to a sequence of valid inputs.

    :param values:
        A sequence of valid inputs.
    :param message:
        Error message to raise in case of a validation error. `%(values)s`
        contains the list of values.
    :param values_formatter:
        Function used to format the list of values in the error message.
    Nc                 B    || _         || _        || j        }|| _        d S r(   valuesr-   default_values_formattervalues_formatterr,   r   r-   r   s       r0   r*   zAnyOf.__init__  -    ##< 0r1   c                     |j         | j        vrV| j        }||                    d          }t	          |t          |                     | j                            z            d S )Nz*Invalid value, must be one of: %(values)s.r   rE   r   r-   rD   r#   rX   r   rw   s       r0   rL   zAnyOf.__call__  se    :T[((lG--(TUU!'D8M8Mdk8Z8Z,[,[,["[\\\ )(r1   c                 @    d                     d | D                       S )N, c              3   4   K   | ]}t          |          V  d S r(   r   .0xs     r0   	<genexpr>z1AnyOf.default_values_formatter.<locals>.<genexpr>	  s(      66!1666666r1   joinr   s    r0   r   zAnyOf.default_values_formatter  s#    yy66v666666r1   NNr4   r5   r6   r7   r*   rL   staticmethodr   r8   r1   r0   r   r     s_        
 
1 1 1 1] ] ] 7 7 \7 7 7r1   r   c                   6    e Zd ZdZddZd Zed             ZdS )r   ai  
    Compares the incoming data to a sequence of invalid inputs.

    :param values:
        A sequence of invalid inputs.
    :param message:
        Error message to raise in case of a validation error. `%(values)s`
        contains the list of values.
    :param values_formatter:
        Function used to format the list of values in the error message.
    Nc                 B    || _         || _        || j        }|| _        d S r(   r   r   s       r0   r*   zNoneOf.__init__  r   r1   c                     |j         | j        v rV| j        }||                    d          }t	          |t          |                     | j                            z            d S )Nz+Invalid value, can't be any of: %(values)s.r   r   rw   s       r0   rL   zNoneOf.__call__  se    :$$lG--(VWW!'D8M8Mdk8Z8Z,[,[,["[\\\ %$r1   c                 @    d                     d | D                       S )Nr   c              3   4   K   | ]}t          |          V  d S r(   r   r   s     r0   r   z2NoneOf.default_values_formatter.<locals>.<genexpr>)  s(      11!1111111r1   r   )vs    r0   r   zNoneOf.default_values_formatter'  s#    yy11q111111r1   r   r   r8   r1   r0   r   r     s_        
 
1 1 1 1] ] ] 2 2 \2 2 2r1   r   c                   x    e Zd ZdZ ej        dej                  Z ej        dej                  Zd	dZ	d Z
dS )
r   z
    Helper class for checking hostnames for validation.

    This is not a validator in and of itself, and as such is not exported.
    z ^(xn-|[a-z0-9_]+)(-[a-z0-9_]+)*$z*^([a-z]{2,20}|xn--([a-z0-9]+-)*[a-z0-9]+)$TFc                 "    || _         || _        d S r(   r   )r,   r   r   s      r0   r*   zHostnameValidation.__init__5  s    & r1   c                 b   | j         r6t                              |          st                              |          rdS 	 |                    d          }n# t
          $ r Y nw xY wt          |t                    s|                    d          }t          |          dk    rdS |
                    d          }|D ]7}|rt          |          dk    r dS | j                            |          s dS 8| j        r5t          |          dk     s | j                            |d	                   sdS dS )
NTidnaascii   F.?   rz   rO   )r   r   r   r   encodeUnicodeErrorrk   r   decoderV   splithostname_partr   r   tld_part)r,   hostnamepartsparts       r0   rL   zHostnameValidation.__call__9  sQ   = 	##H-- 1E1Eh1O1O t	v..HH 	 	 	D	 (L11 	0w//Hx==35 s## 	 	D 3t99r>>uu%++D11 uu  	5zzA~~T]%8%8r%C%C~uts   A 
A"!A"N)TF)r4   r5   r6   r7   r   r   r   r   r   r*   rL   r8   r1   r0   r   r   ,  so         
 BJBBMRRMrzGWWH! ! ! !    r1   r   )0
__future__r   r]   r   r   r}   r   ImportErrorr   wtforms.compatr   r   __all__r)   r#   r;   r$   objectr
   r   r   r   r   r   r   r   r   r   r    r   r"   r   r   r   r	   r   r   r!   r   r   r   r   r   r   r   r   r   r   r8   r1   r0   <module>r      s'   ' ' ' ' ' '  				     OOO   III 3 2 2 2 2 2 2 2< < < < <j < < <	; 	; 	; 	; 	;Y 	; 	; 	;/ / / / /f / / /@'X 'X 'X 'X 'XV 'X 'X 'XT%N %N %N %N %N& %N %N %NP# # # # #v # # #2#* #* #* #* #*6 #* #* #*L
 
 
 
 
| 
 
 
 * * * * *F * * *0    V   @:+ :+ :+ :+ :+F :+ :+ :+z6 6 6 6 6 6 6 6r? ? ? ? ? ? ? ?&"+ "+ "+ "+ "+& "+ "+ "+J+ + + + +6 + + +(7 7 7 7 7F 7 7 7@2 2 2 2 2V 2 2 2@+ + + + + + + +\ 	
				
s    ''0 ::