o
    6h                     @   s  d dl mZ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 		d4dedededede f
ddZ!d5dededdfddZ"ded ed!ed"eddf
d#d$Z#G d%d& d&eZ$d6d'ed(ed)ede$fd*d+Z%d,eddfd-d.Z&G d/d0 d0eZ'd1ede'fd2d3Z(dS )7   )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r`td| t|d  }||fS )	NF NFCr   \T"z%An email address must have an @-sign.)	enumerateunicodedata	normalizelenr   )r   r   inside_quoteescaped	left_partic
right_part r(   j/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/email_validator/syntax.py split_string_at_unquoted_special1   s0   

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>o       z=split_email.<locals>.unquote_quoted_string.<locals>.<genexpr>r   )r   r!   r   join)r   quotedr#   valuer%   r&   r(   r(   r)   unquote_quoted_string]   s,   

z*split_email.<locals>.unquote_quoted_string)@<r9   c                 S   s.   h | ]}t |s|d ks|dkrt|qS ) .r	   matchr/   r0   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.r:   z0There can't be anything after the email address.r   )r8   r8   )	strr   bool
startswithrstripr   r4   sortedcheck_unsafe_chars)r   r*   r7   r$   r'   display_namedisplay_name_quoted	bad_chars	addr_spec
local_partdomain_partis_quoted_local_partr(   r(   r)   split_email   s4   &$,



rP   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!   )rQ   rR   diffsuffixr(   r(   r)   get_length_reason   s   rY   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+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 )LocalPartValidationResultrM   ascii_local_partsmtputf8N)__name__
__module____qualname__rC   __annotations__r   rD   r(   r(   r(   r)   rg      s   
 rg   TFlocalallow_smtputf8allow_empty_localquoted_local_partc           	   
   C   s  t | dkr|std| | ddS t | tkr&t| td}td| dt| r1| | ddS d}d}t| r[|sVd	d
 | D }|rRtddt| d tdd}d}n4|rdd
 | D }|rst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)rM   rh   ri   rR   z0The email address is too long before the @-sign r;   Nc                 S      h | ]}t |st|qS r(   r<   r0   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   rs   r(   )r   r=   r/   r0   r(   r(   r)   r>   $  rt   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 )    ~   )rc   r/   r0   r(   r(   r)   r>   -  s
    r5   r?   utf8z0The email address contains an invalid character.r   z(["\\])z\\\1c                 S   rs   r(   )r
   r=   r/   r0   r(   r(   r)   r>   a  rt   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   rY   r   r=   r   r4   rG   rH   encode
ValueErrorresubcheck_dot_atom)	rn   ro   rp   rq   reasonvalidrequires_smtputf8rK   er(   r(   r)   validate_email_local_part   s   
	


r   rS   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   rZ   MZsZCz.The email address contains unsafe characters: r+   c                 s   r,   r-   r.   r0   r(   r(   r)   r2     r3   z%check_unsafe_chars.<locals>.<genexpr>r;   )setr   r   ra   addr   r4   rG   )rS   r@   rK   r%   r&   ra   r(   r(   r)   rH   r  s2   



rH   labelstart_descr	end_descrry   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;   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   formatrE   )r   r   r   ry   r(   r(   r)   r~     s   



r~   c                   @   s   e Zd ZU eed< eed< dS )DomainNameValidationResultascii_domaindomainN)rj   rk   rl   rC   rm   r(   r(   r(   r)   r     s   
 r   r   test_environmentglobally_deliverablec              
   C   s2  dd | D }|rt ddt| d t|  | }z
tj| ddd} W n tjy< } z	t d| d	|d
}~ww dd | D }|rSt ddt| d t| dddd | dD ]}t	
d|t	jrnt dq`t
| rw| }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rt|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%q||ks2|d| r6t d$qz
t|d%}W n tjyY } z	t d&| d	|d
}~ww d'd | D }|rqt 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   rs   r(   r   r=   r/   r0   r(   r(   r)   r>     rt   z-validate_email_domain_name.<locals>.<setcomp>z7The part after the @-sign contains invalid characters: r+   r;   F)
std3_rulestransitionalz7The part after the @-sign contains invalid characters ().Nc                 S   rs   r(   r   r0   r(   r(   r)   r>     rt   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 {}.Trx   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)r1   r   r(   r(   r)   r2   
  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.rr   z/The email address is too long after the @-sign r   r   rS   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   rs   r(   r   r0   r(   r(   r)   r>   `  rt   zXThe part after the @-sign became invalid after normalizing to international characters ()r   r   )r   r4   rG   rH   r   uts46_remap	IDNAErrorr~   splitr|   r=   Ir   r!   r   rY   r   r   searchr   r   r   r   rz   )r   r   r   rK   original_domainr   r   r   r   rW   rS   r   d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   r8   z9when the part after the @-sign is converted to IDNA ASCIIrw   r   rr   c                 s   s    | ]
}t |d V  qdS )rw   N)r!   rz   r0   r(   r(   r)   r2     s    z(validate_email_length.<locals>.<genexpr>r   rS   rT   rU   rV   r   z (r   zThe email address is too long r;   )original
normalizedrh   rM   r   r!   rz   r   rY   maxr   )
r   addresses_to_checkrQ   r   addr_lenaddr_utf8_lenrW   mbpcmcharsrX   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)	rj   rk   rl   r   	ipaddressIPv4AddressIPv6Addressrm   rC   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   rs   r(   )r   r=   r/   r0   r(   r(   r)   r>     rt   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.)r|   r=   r   r   r{   r   rE   r   
compressedr4   rG   )r   rQ   r   rK   r(   r(   r)   validate_email_domain_literal  s8   


r   )TFF)F)FT))exceptions_typesr   r   rfc_constantsr   r   r   r   r   r	   r
   r   r   r   r   r   r   r|   r   r   r   typingr   r   r   r   rC   rD   rP   intrY   r/   rg   r   rH   r~   r   r   r   r   r   r(   r(   r(   r)   <module>   s8    <" '
 "4 ??