a
    åzeèB  ã                   @   sn  g d ¢Z ddlmZ ddlZddlZddlmZ ddlmZ dZ	dZ
dZd	Zd
ZdZdZe	e	dfe	e	dfe	e	dfe	e	dfe	e	dfe	e	dfe	e	dfe	e	dfe	e	dfe	e	dfe	e	dfe	e	dfde
e
dfe
e
dfe
ddfe
ddfe
ddfe
e
dfee
dfdœZdddddddddddddddddddddddd
dœZdd dd!œZd,d"d#„Zd$d%„ Zd&d'„ Zd(d)„ ZG d*d+„ d+ƒZdS )-)ÚCharsetÚ	add_aliasÚadd_charsetÚ	add_codecé    )ÚpartialN)Úerrors)Úencode_7or8bité   é   é   é   úus-asciizunknown-8bitÚ )NNNúiso-2022-jpúutf-8)ú
iso-8859-1ú
iso-8859-2ú
iso-8859-3ú
iso-8859-4ú
iso-8859-9úiso-8859-10úiso-8859-13úiso-8859-14úiso-8859-15úiso-8859-16zwindows-1252Zvisciir   Úbig5Úgb2312úeuc-jpÚ	shift_jisr   zkoi8-rr   r   r   r   r   r   r   r   r   r   r   zks_c_5601-1987r   zeuc-kr)Úlatin_1zlatin-1Zlatin_2zlatin-2Zlatin_3zlatin-3Zlatin_4zlatin-4Zlatin_5zlatin-5Zlatin_6zlatin-6Zlatin_7zlatin-7Zlatin_8zlatin-8Zlatin_9zlatin-9Zlatin_10zlatin-10Úcp949Úeuc_jpÚeuc_krÚasciiÚeucgb2312_cnÚbig5_tw)r   r   r   c                 C   s"   |t krtdƒ‚|||ft| < d S )Nz!SHORTEST not allowed for body_enc)ÚSHORTESTÚ
ValueErrorÚCHARSETS)ÚcharsetZ
header_encZbody_encÚoutput_charset© r+   ú#/usr/lib/python3.9/email/charset.pyr   m   s    r   c                 C   s   |t | < d S ©N)ÚALIASES)ÚaliasZ	canonicalr+   r+   r,   r   ‰   s    r   c                 C   s   |t | < d S r-   )Ú	CODEC_MAP)r)   Z	codecnamer+   r+   r,   r   ’   s    r   c                 C   s"   |t kr|  dd¡S |  |¡S d S )Nr#   Úsurrogateescape)ÚUNKNOWN8BITÚencode)ÚstringÚcodecr+   r+   r,   Ú_encodeŸ   s    r6   c                   @   sX   e Zd Zefdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )r   c                 C   s¾   z$t |tƒr| d¡ n
t|dƒ}W n ty@   t |¡‚Y n0 | ¡ }t ||¡| _	t
 | j	ttd f¡\}}}|s|| j	}|| _|| _t ||¡| _t | j	| j	¡| _t | j| j¡| _d S )Nr#   )Ú
isinstanceÚstrr3   ÚUnicodeErrorr   ZCharsetErrorÚlowerr.   ÚgetÚinput_charsetr(   r&   ÚBASE64Úheader_encodingÚbody_encodingr*   r0   Zinput_codecÚoutput_codec)Úselfr<   ZhencZbencÚconvr+   r+   r,   Ú__init__Ó   s,    
ÿ
ÿÿzCharset.__init__c                 C   s
   | j  ¡ S r-   )r<   r:   ©rA   r+   r+   r,   Ú__repr__ô   s    zCharset.__repr__c                 C   s   t | ƒt |ƒ ¡ kS r-   )r8   r:   )rA   Úotherr+   r+   r,   Ú__eq__÷   s    zCharset.__eq__c                 C   s$   | j tkrdS | j tkrdS tS d S )Nzquoted-printableÚbase64)r?   ÚQPr=   r   rD   r+   r+   r,   Úget_body_encodingú   s
    

zCharset.get_body_encodingc                 C   s   | j p
| jS r-   )r*   r<   rD   r+   r+   r,   Úget_output_charset  s    zCharset.get_output_charsetc                 C   s6   | j pd}t||ƒ}|  |¡}|d u r*|S | ||¡S )Nr   )r@   r6   Ú_get_encoderÚheader_encode)rA   r4   r5   Úheader_bytesÚencoder_moduler+   r+   r,   rM     s    


zCharset.header_encodec                 C   s  | j pd}t||ƒ}|  |¡}t|j|d}|  ¡ }t|ƒt }g }	g }
t|ƒ| }|D ]Œ}|
 	|¡ t
 |
¡}| t||ƒ¡}||krX|
 ¡  |	s¤|
s¤|	 	d ¡ n.|	r¬dnd}t
 |
¡}t||ƒ}|	 	||ƒ¡ |g}
t|ƒ| }qXt
 |
¡}t||ƒ}|	 	||ƒ¡ |	S )Nr   )r)   ú r   )r@   r6   rL   r   rM   rK   ÚlenÚRFC2047_CHROME_LENÚnextÚappendÚEMPTYSTRINGÚjoinÚheader_lengthÚpop)rA   r4   Z
maxlengthsr5   rN   rO   Úencoderr)   ÚextraÚlinesZcurrent_lineÚmaxlenÚ	characterZ	this_lineÚlengthÚ	separatorZjoined_liner+   r+   r,   Úheader_encode_lines*  s6    








zCharset.header_encode_linesc                 C   s`   | j tkrtjS | j tkr tjS | j tkrXtj |¡}tj |¡}||k rPtjS tjS nd S d S r-   )r>   r=   ÚemailÚ
base64mimerI   Ú
quoprimimer&   rW   )rA   rN   Zlen64Zlenqpr+   r+   r,   rL   h  s    


zCharset._get_encoderc                 C   sŽ   |s|S | j tu r4t|tƒr(| | j¡}tj |¡S | j t	u rjt|tƒrT| | j¡}| 
d¡}tj |¡S t|tƒr†| | j¡ 
d¡}|S d S )NÚlatin1r#   )r?   r=   r7   r8   r3   r*   ra   rb   Úbody_encoderI   Údecoderc   )rA   r4   r+   r+   r,   re   w  s    	





zCharset.body_encodeN)Ú__name__Ú
__module__Ú__qualname__ÚDEFAULT_CHARSETrC   rE   rG   rJ   rK   rM   r`   rL   re   r+   r+   r+   r,   r   §   s   ,!>r   )NNN)Ú__all__Ú	functoolsr   Zemail.base64mimera   Zemail.quoprimimer   Zemail.encodersr   rI   r=   r&   rR   rj   r2   rU   r(   r.   r0   r   r   r   r6   r   r+   r+   r+   r,   Ú<module>   s†   æ èú
	