o
    ^"<fbQ                     @   s4  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 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mZ ddg di fZeG dd dZeG dd deZeededddZdd ZeG dd dZe ZedZeeeddZ edZ!ee!eddZ"dd Z#dd  Z$d!d" Z%e%ged#fe#ged$fe$ged%fd&Z&d'd( Z'dCd+d,Z(e(ed-d.Z)eG d/d0 d0Z*eG d1d2 d2e*Z+eG d3d4 d4e*Z,eG d5d6 d6e*Z-eG d7d8 d8e*Z.eG d9d: d:Z/eG d;d< d<Z0d=d> Z1d?d@ Z2eG dAdB dBZ3dS )D    N)Path)urlsplit
urlunsplit)ValidationError)deconstructible)RemovedInDjango41Warning)punycode)is_valid_ipv6_address)_lazy_re_compile)gettext_lazyngettext_lazy  c                   @   s>   e Zd ZdZedZdZdZdZdddZ	d	d
 Z
dd ZdS )RegexValidatorr   zEnter a valid value.invalidFr   Nc                 C   st   |d ur|| _ |d ur|| _|d ur|| _|d ur|| _|d ur#|| _| jr0t| j ts0tdt| j | j| _ d S )Nz@If the flags are set, regex must be a regular expression string.)	regexmessagecodeinverse_matchflags
isinstancestr	TypeErrorr
   )selfr   r   r   r   r   r   r   M/var/www/html/kck/venv/lib/python3.10/site-packages/django/core/validators.py__init__   s   zRegexValidator.__init__c                 C   s>   | j t|}| jr|n| }|rt| j| jd|iddS )z
        Validate that the input contains (or does *not* contain, if
        inverse_match is True) a match for the regular expression.
        valuer   paramsN)r   searchr   r   r   r   r   )r   r   regex_matchesinvalid_inputr   r   r   __call__+   s
   zRegexValidator.__call__c                 C   sN   t |to&| jj|jjko&| jj|jjko&| j|jko&| j|jko&| j|jkS N)r   r   r   patternr   r   r   r   r   otherr   r   r   __eq__5   s   



zRegexValidator.__eq__)NNNNN)__name__
__module____qualname__r   _r   r   r   r   r   r"   r'   r   r   r   r   r      s    

r   c                       s   e Zd ZdZdZdZde d e d e d Zde d	 Zd
e d Zde e e d Z	e
de d e d e	 d ejZedZg dZedZdZd fdd	Z fddZ  ZS )URLValidatoru   ¡-￿zW(?:0|25[0-5]|2[0-4]\d|1\d?\d?|[1-9]\d?)(?:\.(?:0|25[0-5]|2[0-4]\d|1\d?\d?|[1-9]\d?)){3}z\[[0-9a-f:.]+\]z[a-zz0-9](?:[a-zz0-9-]{0,61}[a-zz0-9])?z(?:\.(?!-)[a-zz0-9-]{1,63}(?<!-))*z\.(?!-)(?:[a-zz%-]{2,63}|xn--[a-z0-9]{1,59})(?<!-)\.?(z|localhost)z5^(?:[a-z0-9.+-]*)://(?:[^\s:@/]+(?::[^\s:@/]*)?@)?(?:|z )(?::\d{2,5})?(?:[/?#][^\s]*)?\ZzEnter a valid URL.)httphttpsftpftpsz	
i   Nc                    s(   t  jdi | |d ur|| _d S d S )Nr   )superr   schemes)r   r4   kwargs	__class__r   r   r   b   s   
zURLValidator.__init__c                    s  t |trt|| jkrt| j| jd|id| j|r(t| j| jd|id|	dd 
 }|| jvrAt| j| jd|idzt | W nS ty } zG|rzt|\}}}}}W n typ   t| j| jd|idw zt|}W n	 ty   |w t|||||f}t | n W Y d }~n-d }~ww tdt|j}	|	r|	d }
zt|
 W n ty   t| j| jd|idw tt|jdkrt| j| jd|idd S )Nr   r   z://r   z^\[(.+)\](?::\d{2,5})?$      )r   r   len
max_lengthr   r   r   unsafe_charsintersectionsplitlowerr4   r3   r"   r   
ValueErrorr   UnicodeErrorr   rer   netlocvalidate_ipv6_addresshostname)r   r   schemeerC   pathqueryfragmenturl
host_matchpotential_ipr6   r   r   r"   g   sL   
zURLValidator.__call__r#   )r(   r)   r*   ulipv4_reipv6_rehostname_re	domain_retld_rehost_rer
   rB   
IGNORECASEr   r+   r   r4   	frozensetr<   r;   r   r"   __classcell__r   r   r6   r   r,   @   sF    r,   z^-?\d+\ZzEnter a valid integer.r   r   r   c                 C   s   t | S r#   )integer_validatorr   r   r   r   validate_integer      r[   c                   @   s   e Zd ZedZdZedejZ	edejZ
edejZdgZedd Zejd	d Zdd
dddZdd Zdd Zdd Zd
S )EmailValidatorzEnter a valid email address.r   z(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*\Z|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"\Z)zH((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+)(?:[A-Z0-9-]{2,63}(?<!-))\Zz\[([A-f0-9:.]+)\]\Z	localhostc                 C   s   t jdtdd | jS NzJThe domain_whitelist attribute is deprecated in favor of domain_allowlist.   
stacklevelwarningswarnr   domain_allowlist)r   r   r   r   domain_whitelist   s   zEmailValidator.domain_whitelistc                 C   s   t jdtdd || _d S r_   rc   )r   	allowlistr   r   r   rg      s   
N)	whitelistc                C   sN   |d ur|}t jdtdd |d ur|| _|d ur|| _|d ur%|| _d S d S )Nz;The whitelist argument is deprecated in favor of allowlist.r`   ra   )rd   re   r   r   r   rf   )r   r   r   rh   ri   r   r   r   r      s   
zEmailValidator.__init__c                 C   s   |rd|vst |dkrt| j| jd|id|dd\}}| j|s0t| j| jd|id|| jvr\| |s^zt	|}W n	 t
yI   Y nw | |rQd S t| j| jd|idd S d S )N@i@  r   r   r8   )r:   r   r   r   rsplit
user_regexmatchrf   validate_domain_partr   rA   )r   r   	user_partdomain_partr   r   r   r"      s"   

zEmailValidator.__call__c                 C   sP   | j |rdS | j|}|r&|d }zt| W dS  ty%   Y dS w dS )NTr8   F)domain_regexrm   literal_regexvalidate_ipv46_addressr   )r   rp   literal_match
ip_addressr   r   r   rn      s   z#EmailValidator.validate_domain_partc                 C   s.   t |to| j|jko| j|jko| j|jkS r#   )r   r]   rf   r   r   r%   r   r   r   r'      s   



zEmailValidator.__eq__NNN)r(   r)   r*   r+   r   r   r
   rB   rU   rl   rq   rr   rf   propertyrg   setterr   r"   rn   r'   r   r   r   r   r]      s0    
	
	r]   z^[-a-zA-Z0-9_]+\ZuP   Enter a valid “slug” consisting of letters, numbers, underscores or hyphens.z	^[-\w]+\ZuY   Enter a valid “slug” consisting of Unicode letters, numbers, underscores, or hyphens.c                 C   sf   zt |  W n ty   ttddd| idw tdd | dD r1ttddd| idd S )NEnter a valid IPv4 address.r   r   r   c                 s   s$    | ]}|d ko|d d kV  qdS )0r   Nr   ).0octetr   r   r   	<genexpr>  s
    
z(validate_ipv4_address.<locals>.<genexpr>.)	ipaddressIPv4Addressr@   r   r+   anyr>   rZ   r   r   r   validate_ipv4_address  s   r   c                 C   s"   t | sttddd| idd S )NEnter a valid IPv6 address.r   r   r   )r	   r   r+   rZ   r   r   r   rD   )  s   rD   c                 C   sT   zt |  W d S  ty)   zt|  W Y d S  ty(   ttddd| idw w )N#Enter a valid IPv4 or IPv6 address.r   r   r   )r   r   rD   r+   rZ   r   r   r   rs   .  s   rs   r   ry   r   )bothipv4ipv6c                 C   sF   | dkr
|r
t dzt|   W S  ty"   t d| ttf w )zq
    Depending on the given parameters, return the appropriate validators for
    the GenericIPAddressField.
    r   z=You can only use `unpack_ipv4` if `protocol` is set to 'both'z+The protocol '%s' is unknown. Supported: %s)r@   ip_address_validator_mapr?   KeyErrorlist)protocolunpack_ipv4r   r   r   ip_address_validators?  s   
r   ,Fc                 C   s.   t d|rdndt| d }t|||dS )Nz#^%(neg)s\d+(?:%(sep)s%(neg)s\d+)*\Zz(-)?r   )negseprX   )r
   rB   escaper   )r   r   r   allow_negativeregexpr   r   r   int_list_validatorN  s
   

r   z&Enter only digits separated by commas.)r   c                   @   sB   e Zd ZedZdZdddZdd Zdd	 Zd
d Z	dd Z
dS )BaseValidatorz<Ensure this value is %(limit_value)s (it is %(show_value)s).limit_valueNc                 C   s   || _ |r
|| _d S d S r#   )r   r   )r   r   r   r   r   r   r   `  s   
zBaseValidator.__init__c                 C   sP   |  |}t| jr|  n| j}|||d}| ||r&t| j| j|dd S )N)r   
show_valuer   r   )cleancallabler   comparer   r   r   )r   r   cleanedr   r   r   r   r   r"   e  s   
zBaseValidator.__call__c                 C   s4   t || jstS | j|jko| j|jko| j|jkS r#   )r   r7   NotImplementedr   r   r   r%   r   r   r   r'   l  s   

zBaseValidator.__eq__c                 C   s   ||uS r#   r   r   abr   r   r   r   u  r\   zBaseValidator.comparec                 C   s   |S r#   r   r   xr   r   r   r   x  s   zBaseValidator.cleanr#   )r(   r)   r*   r+   r   r   r   r"   r'   r   r   r   r   r   r   r   [  s    
	r   c                   @       e Zd ZedZdZdd ZdS )MaxValueValidatorz;Ensure this value is less than or equal to %(limit_value)s.	max_valuec                 C      ||kS r#   r   r   r   r   r   r     r\   zMaxValueValidator.compareNr(   r)   r*   r+   r   r   r   r   r   r   r   r   |      r   c                   @   r   )MinValueValidatorz>Ensure this value is greater than or equal to %(limit_value)s.	min_valuec                 C      ||k S r#   r   r   r   r   r   r     r\   zMinValueValidator.compareNr   r   r   r   r   r     r   r   c                   @   ,   e Zd ZedddZdZdd Zdd Zd	S )
MinLengthValidatorzQEnsure this value has at least %(limit_value)d character (it has %(show_value)d).zREnsure this value has at least %(limit_value)d characters (it has %(show_value)d).r   
min_lengthc                 C   r   r#   r   r   r   r   r   r     r\   zMinLengthValidator.comparec                 C      t |S r#   r:   r   r   r   r   r     r\   zMinLengthValidator.cleanNr(   r)   r*   r   r   r   r   r   r   r   r   r   r         r   c                   @   r   )
MaxLengthValidatorzPEnsure this value has at most %(limit_value)d character (it has %(show_value)d).zQEnsure this value has at most %(limit_value)d characters (it has %(show_value)d).r   r;   c                 C   r   r#   r   r   r   r   r   r     r\   zMaxLengthValidator.comparec                 C   r   r#   r   r   r   r   r   r     r\   zMaxLengthValidator.cleanNr   r   r   r   r   r     r   r   c                   @   sR   e Zd ZdZededddedddedd	dd
Zdd Zdd Zdd Z	dS )DecimalValidatorz}
    Validate that the input does not exceed the maximum number of digits
    expected, otherwise raise ValidationError.
    zEnter a number.z:Ensure that there are no more than %(max)s digit in total.z;Ensure that there are no more than %(max)s digits in total.maxz9Ensure that there are no more than %(max)s decimal place.z:Ensure that there are no more than %(max)s decimal places.zJEnsure that there are no more than %(max)s digit before the decimal point.zKEnsure that there are no more than %(max)s digits before the decimal point.)r   
max_digitsmax_decimal_placesmax_whole_digitsc                 C   s   || _ || _d S r#   )r   decimal_places)r   r   r   r   r   r   r     s   
zDecimalValidator.__init__c                 C   s6  |  dd  \}}|dv rt| jd dd|id|dkr't|| }d}nt|t|kr6t| }}nt|}t|}|| }| jd urZ|| jkrZt| jd d| j|dd| jd urr|| jkrrt| jd	 d	| j|dd| jd ur| jd ur|| j| j krt| jd
 d
| j| j |ddd S d S d S )Nr8   >   FNnr   r   r   r   r   )r   r   r   r   )as_tupler   messagesr:   absr   r   )r   r   digit_tupleexponentdigitsdecimalswhole_digitsr   r   r   r"     s@   

zDecimalValidator.__call__c                 C   $   t || jo| j|jko| j|jkS r#   )r   r7   r   r   r%   r   r   r   r'     
   

zDecimalValidator.__eq__N)
r(   r)   r*   __doc__r+   r   r   r   r"   r'   r   r   r   r   r     s,    )r   c                   @   s2   e Zd ZedZdZd
ddZdd Zdd	 ZdS )FileExtensionValidatorub   File extension “%(extension)s” is not allowed. Allowed extensions are: %(allowed_extensions)s.invalid_extensionNc                 C   s@   |d urdd |D }|| _ |d ur|| _|d ur|| _d S d S )Nc                 S   s   g | ]}|  qS r   r?   )r{   allowed_extensionr   r   r   
<listcomp>  s    z3FileExtensionValidator.__init__.<locals>.<listcomp>)allowed_extensionsr   r   )r   r   r   r   r   r   r   r     s   
zFileExtensionValidator.__init__c                 C   sV   t |jjdd   }| jd ur'|| jvr)t| j| j|d| j|ddd S d S )Nr8   z, )	extensionr   r   r   )	r   namesuffixr?   r   r   r   r   join)r   r   r   r   r   r   r"     s   
zFileExtensionValidator.__call__c                 C   s0   t || jo| j|jko| j|jko| j|jkS r#   )r   r7   r   r   r   r%   r   r   r   r'     s   


zFileExtensionValidator.__eq__rv   )	r(   r)   r*   r+   r   r   r   r"   r'   r   r   r   r   r     s    
	r   c                  C   s@   zddl m}  W n ty   g  Y S w |   dd | jD S )Nr   Imagec                 S   s   g | ]
}|  d d qS )r8   Nr   )r{   extr   r   r   r   (  s    z2get_available_image_extensions.<locals>.<listcomp>)PILr   ImportErrorinit	EXTENSIONr   r   r   r   get_available_image_extensions!  s   r   c                 C   s   t t d| S )N)r   )r   r   rZ   r   r   r   validate_image_file_extension+  s   r   c                   @   s6   e Zd ZdZedZdZdddZdd Zd	d
 Z	dS )ProhibitNullCharactersValidatorz<Validate that the string doesn't contain the null character.z Null characters are not allowed.null_characters_not_allowedNc                 C   s$   |d ur|| _ |d ur|| _d S d S r#   rX   )r   r   r   r   r   r   r   5  s
   
z(ProhibitNullCharactersValidator.__init__c                 C   s&   dt |v rt| j| jd|idd S )N r   r   )r   r   r   r   )r   r   r   r   r   r"   ;  s   z(ProhibitNullCharactersValidator.__call__c                 C   r   r#   )r   r7   r   r   r%   r   r   r   r'   ?  r   z&ProhibitNullCharactersValidator.__eq__)NN)
r(   r)   r*   r   r+   r   r   r   r"   r'   r   r   r   r   r   /  s    
r   )r   Nr   F)4r   rB   rd   pathlibr   urllib.parser   r   django.core.exceptionsr   django.utils.deconstructr   django.utils.deprecationr   django.utils.encodingr   django.utils.ipv6r	   django.utils.regex_helperr
   django.utils.translationr   r+   r   EMPTY_VALUESr   r,   rY   r[   r]   validate_emailslug_revalidate_slugslug_unicode_revalidate_unicode_slugr   rD   rs   r   r   r   %validate_comma_separated_integer_listr   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s    ,Tb
 M&
