o
    i;                     @   s  d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZ ddlZddlZddlZddlZddlmZmZmZmZ dedeee eeef fd	d
ZdededefddZdedefddZ G dd deZ!		d9dededededede!fddZ"d:dededdfdd Z#d!ed"ed#ed$eddf
d%d&Z$d'edefd(d)Z%G d*d+ d+eZ&d;d,ed-ed.ede&fd/d0Z'd1eddfd2d3Z(G d4d5 d5eZ)d6ede)fd7d8Z*dS )<   )EmailSyntaxError)ValidatedEmail)EMAIL_MAX_LENGTHLOCAL_PART_MAX_LENGTHDOMAIN_MAX_LENGTHDOT_ATOM_TEXTDOT_ATOM_TEXT_INTLATEXT_REATEXT_INTL_DOT_REATEXT_HOSTNAME_INTL
QTEXT_INTLDNS_LABEL_LENGTH_LIMITDOT_ATOM_TEXT_HOSTNAMEDOMAIN_NAME_REGEXDOMAIN_LITERAL_CHARS    N)OptionalTuple	TypedDictUnionemailreturnc                 C   s4  dt dtt df dtt t f fdd}dt dtt tf fdd}|| d	\}}|d
r|| }||\}}|sNdd |D }|rNtddt| d t|dd d|vr\td|d}|d dkrktd|dd  d}||d\}	}
nd }||}	}
|
dr|
dd  }
||	\}	}||	|
|fS )Ntextspecials.r   c                 S   s   d}d}d}t | D ]I\}}td| |d  d |kr!||7 }q
|r>||7 }|dkr0|s0d}q
|dkr;|s;d}d}q
d}q
|dkrI||7 }d}q
||v rO n||7 }q
t|t| krpd| v rdtd	d
| v rltdtd| t|d  }||fS )NF NFCr   \T"u   ＠zZThe email address has the "full-width" at-sign (@) character instead of a regular at-sign.u   ﹫zWThe email address has the "small commercial at" character instead of a regular at-sign.z%An email address must have an @-sign.)	enumerateunicodedata	normalizelenr   )r   r   Zinside_quoteescaped	left_partic
right_part r'   M/home/app/Keep/.python/lib/python3.10/site-packages/email_validator/syntax.py split_string_at_unquoted_special2   s8   

	z5split_email.<locals>.split_string_at_unquoted_specialc              	   S   s   d}d}d}t | D ]O\}}|rJ|r||7 }d}q
|dkr d}q
|dkrE|t| d kr@tddd	d
 | |d d  D   ||fS ||7 }q
|dkrU|dkrUd}q
||7 }q
||fS )NFr   r   Tr   r   z,Extra character(s) found after close quote: , c                 s       | ]}t |V  qd S Nsafe_character_display.0r%   r'   r'   r(   	<genexpr>       z=split_email.<locals>.unquote_quoted_string.<locals>.<genexpr>r   )r   r!   r   join)r   quotedr"   valuer$   r%   r'   r'   r(   unquote_quoted_strings   s,   

z*split_email.<locals>.unquote_quoted_string)@<r8   c                 S   s.   h | ]}t |s|d ks|dkrt|qS ) .r	   matchr.   r/   r'   r'   r(   	<setcomp>   s    zsplit_email.<locals>.<setcomp>z>The display name contains invalid characters when not quoted: r*   r:   Tallow_space>zoAn open angle bracket at the start of the email address has to be followed by a close angle bracket at the end.r9   z0There can't be anything after the email address.r   )r7   r7   )	strr   bool
startswithrstripr   r3   sortedcheck_unsafe_chars)r   r)   r6   r#   r&   Zdisplay_nameZdisplay_name_quoted	bad_charsZ	addr_spec
local_partZdomain_partZis_quoted_local_partr'   r'   r(   split_email   s4   &$A



rJ   addrlimitc                 C   s.   t | | }|dkrdnd}d| d| dS )zEHelper function to return an error message related to invalid length.r   sr   (
 character
 too many))r!   )rK   rL   diffsuffixr'   r'   r(   get_length_reason   s   rS   r%   c                 C   sp   | dkr
d|  dS t | d dv rt| S t| dk r(dt| d }n
dt| d }t | |S )	Nr   r   r   LNPSi  zU+Z04x08x)r   categoryreprorduppername)r%   hr'   r'   r(   r.      s   r.   c                   @   s*   e Zd ZU eed< ee ed< eed< dS )LocalPartValidationResultrI   ascii_local_partsmtputf8N)__name__
__module____qualname__rB   __annotations__r   rC   r'   r'   r'   r(   r`      s   
 r`   TFlocalallow_smtputf8allow_empty_localquoted_local_partstrictc           
   
   C   s  t | dkr|std| | ddS |r(t | tkr(t| td}td| dt| r3| | ddS d}d}t| r]|sXd	d
 | D }|rTtddt| d tdd}d}n4|rdd
 | D }|rutddt| d dd
 | D }|rd}|stddt| d d}|rt	| |dkd z| 
d W n ty }	 ztd|	d}	~	ww |dkrdtdd|  d } | |s| |dS d|dS dd
 | D }|rtddt| d t| dddd td) z;Validates the syntax of the local part of an email address.r   z*There must be something before the @-sign.F)rI   ra   rb   rL   z0The email address is too long before the @-sign r:   Nc                 S      h | ]}t |st|qS r'   r;   r/   r'   r'   r(   r=   "      z,validate_email_local_part.<locals>.<setcomp>zBInternationalized characters before the @-sign are not supported: r*   zAInternationalized characters before the @-sign are not supported.zdot-atomTc                 S   rm   r'   )r   r<   r.   r/   r'   r'   r(   r=   :  rn   zKThe email address contains invalid characters in quotes before the @-sign: c                 S   s.   h | ]}d t |  krdksn t|qS )    ~   )r\   r.   r/   r'   r'   r(   r=   C  s
    r4   r>   utf8z0The email address contains an invalid character.r   z(["\\])z\\\1c                 S   rm   r'   )r
   r<   r.   r/   r'   r'   r(   r=   w  rn   zAThe email address contains invalid characters before the @-sign: z(An email address cannot start with a {}.z@An email address cannot have a {} immediately before the @-sign.is_hostnamez@The email address contains invalid characters before the @-sign.)r!   r   r   rS   r   r<   r   r3   rF   rG   encode
ValueErrorresubcheck_dot_atom)
rg   rh   ri   rj   rk   reasonZvalidZrequires_smtputf8rH   er'   r'   r(   validate_email_local_part   s   
	


r{   rM   r?   c                 C   s   t  }t| D ]I\}}t|}|d dv rq|d dkr'|dkr&|| q|dkr3|s2|| q|d dkr?|| q|d dkrK|| q|| q|retddd	d
 t|D  d d S )Nr   rT   MZsZCz.The email address contains unsafe characters: r*   c                 s   r+   r,   r-   r/   r'   r'   r(   r1     r2   z%check_unsafe_chars.<locals>.<genexpr>r:   )setr   r   rZ   addr   r3   rF   )rM   r?   rH   r$   r%   rZ   r'   r'   r(   rG     s2   



rG   labelstart_descr	end_descrrs   c                 C   s   |  drt|d| drt|dd| v r td|rF|  dr.t|d| dr:t|dd| v sBd| v rHtd	d S d S )
Nr:   Zperiodz..z2An email address cannot have two periods in a row.-hyphenz.-z-.zFAn email address cannot have a period and a hyphen next to each other.)endswithr   formatrD   )r   r   r   rs   r'   r'   r(   rx     s   



rx   charc                 C   s   t | }d|  krdkrdS  d|  krdkr4n nd|  kr&dks4n d|  kr1d	krPn dS |d
v sPd|  krBdksPn d|  krNdkrRdS  ndS tt|dv r]dS dtt|dv rkdS dS )N      Fi   i`   i$   i&   i(   i.   )   id   i  i   i   i i T)ZCfCnCoCsr}   ZZlZZpZ002Er9   )r\   r   rZ   chrdecompositionsplit)r   r%   r'   r'   r(   uts46_valid_char  s"   Dr   c                   @   s   e Zd ZU eed< eed< dS )DomainNameValidationResultascii_domaindomainN)rc   rd   re   rB   rf   r'   r'   r'   r(   r     s   
 r   r   test_environmentglobally_deliverablec              
   C   s`  dd | D }|rt ddt| d t|  dd | D }|r0t ddt| d | }z
tj| ddd} W n tjyR } z	t d	| d
|d}~ww dd | D }|rit ddt| d t| dddd | dD ]}t	
d|t	jrt dqvt
| r| }n/zddd | dD }W n tjy } z	t d| d
|d}~ww t
|st dt|tkr||krt|td}t d| dt|t }	|	dkrdnd}
t d|	 d|
 d|dD ]}t|tkr	t|td}t d | dq|r(d|vr|d!kr|st d"t|s(t d#dd$lm} |D ]}|d!kr<|r<q0||ksI|d| rMt d%q0z
t|d&}W n tjyp } z	t d'| d
|d}~ww d(d |D }|rt ddt| d t| zt| W n tjy } z	t d)| d
|d}~ww ||d*S )+z<Validates the syntax of the domain part of an email address.c                 S   rm   r'   r   r<   r.   r/   r'   r'   r(   r=     rn   z-validate_email_domain_name.<locals>.<setcomp>z7The part after the @-sign contains invalid characters: r*   r:   c                 S   s   h | ]
}t |st|qS r'   )r   r.   r/   r'   r'   r(   r=     s    F)
std3_rulestransitionalz7The part after the @-sign contains invalid characters ().Nc                 S   rm   r'   r   r/   r'   r'   r(   r=     rn   zSThe part after the @-sign contains invalid characters after Unicode normalization: z?An email address cannot have a {} immediately after the @-sign.z&An email address cannot end with a {}.Trr   z
(?!xn)..--zAn email address cannot have two letters followed by two dashes immediately after the @-sign or after a period, except Punycode.c                 s   s     | ]}t |d V  qdS )asciiN)idnaalabeldecode)r0   r   r'   r'   r(   r1   G  s
    
z-validate_email_domain_name.<locals>.<genexpr>z&The part after the @-sign is invalid (zSThe email address contains invalid characters after the @-sign after IDNA encoding.rl   z/The email address is too long after the @-sign r   r   rM   z0The email address is too long after the @-sign ( bytez too many after IDNA encoding).zDAfter the @-sign, periods cannot be separated by so many characters testz@The part after the @-sign is not valid. It should have a period.zRThe part after the @-sign is not valid. It is not within a valid top-level domain.)SPECIAL_USE_DOMAIN_NAMESz[The part after the @-sign is a special-use or reserved name that cannot be used with email.r   z-The part after the @-sign is not valid IDNA (c                 S   rm   r'   r   r/   r'   r'   r(   r=     rn   zXThe part after the @-sign became invalid after normalizing to international characters ()r   r   )r   r3   rF   rG   r   uts46_remap	IDNAErrorrx   r   rv   r<   Ir   r!   r   rS   r   r   searchr   r   r   r   rt   )r   r   r   rH   Zoriginal_domainrz   r   r   ry   rQ   rM   r   dZdomain_i18nr'   r'   r(   validate_email_domain_name  s   
	


	
r   addrinfoc           
      C   s*  | j d f| jdf| jp| jpdd | j dfg}|D ]x\}}t|}t|d}|t }|dkr|d u r@||kr@t|td}nJ|d u rwt	dd	 |D }t	d
|| }|d
krZdnd}	||krjd| d|	 d}n d| d| d|	 d}n|d
kr}dnd}	|d| d|	 d7 }t
d| dqd S )Nzafter normalizationr   r7   z9when the part after the @-sign is converted to IDNA ASCIIrq   r   rl   c                 s   s    | ]
}t |d V  qdS )rq   N)r!   rt   r/   r'   r'   r(   r1     s    z(validate_email_length.<locals>.<genexpr>r   rM   rN   rO   rP   r   z (r   zThe email address is too long r:   )original
normalizedra   rI   r   r!   rt   r   rS   maxr   )
r   Zaddresses_to_checkrK   ry   Zaddr_lenZaddr_utf8_lenrQ   ZmbpcZmcharsrR   r'   r'   r(   validate_email_length  s.   r   c                   @   s*   e Zd ZU eejejf ed< eed< dS )DomainLiteralValidationResultdomain_addressr   N)	rc   rd   re   r   	ipaddressIPv4AddressIPv6Addressrf   rB   r'   r'   r'   r(   r     s   
 r   domain_literalc              
   C   s   t d| r,zt| }W n ty" } z	td| d|d }~ww |d| ddS | dr\zt| dd  }W n tyQ } z	td	| d
|d }~ww |d|j ddS d| vrdtddd | D }|rztdd	t
| d td)Nz
^[0-9\.]+$zRThe address in brackets after the @-sign is not valid: It is not an IPv4 address (z') or is missing an address literal tag.[])r   r   zIPv6:   z<The IPv6 address in brackets after the @-sign is not valid (r   z[IPv6::z\The part after the @-sign in brackets is not an IPv4 address and has no address literal tag.c                 S   rm   r'   )r   r<   r.   r/   r'   r'   r(   r=   ,  rn   z0validate_email_domain_literal.<locals>.<setcomp>zCThe part after the @-sign contains invalid characters in brackets: r*   r:   zNThe part after the @-sign contains an invalid address literal tag in brackets.)rv   r<   r   r   ru   r   rD   r   
compressedr3   rF   )r   rK   rz   rH   r'   r'   r(   validate_email_domain_literal  s8   


r   )TFFF)F)FT)+
exceptionsr   typesr   Zrfc_constantsr   r   r   r   r   r	   r
   r   r   r   r   r   r   rv   r   r   r   typingr   r   r   r   rB   rC   rJ   intrS   r.   r`   r{   rG   rx   r   r   r   r   r   r   r'   r'   r'   r(   <module>   s@    <" <
 "4 H?