o
    Hb#                     @   s   d dl Z d dlZd dlZd dlmZ edZdZdZdd Z	dd	 Z
d
d ZG dd dejZG dd dejZG dd dejZG dd deejZG dd deejZdd ZdS )    N)	ucd_3_2_0u   [.。．｡]s   xn--zxn--c                 C   s  g }| D ]}t |rq|t | qd|} td| } | D ]5}t |sQt |sQt 	|sQt 
|sQt |sQt |sQt |sQt |sQt |rWtd| q"dd | D }|D ]}|r~tdd | D rrtd|d	 rz|d
 s~tdqa| S )N ZNFKCzInvalid character %rc                 S   s   g | ]}t |qS  )
stringprepZin_table_d1.0xr   r   %/usr/lib/python3.10/encodings/idna.py
<listcomp>)   s    znameprep.<locals>.<listcomp>c                 s   s    | ]}t |V  qd S )N)r   Zin_table_d2r   r   r   r	   	<genexpr>2   s    znameprep.<locals>.<genexpr>zViolation of BIDI requirement 2r   zViolation of BIDI requirement 3)r   Zin_table_b1appendZmap_table_b2joinunicodedataZ	normalizeZin_table_c12Zin_table_c22Zin_table_c3Zin_table_c4Zin_table_c5Zin_table_c6Zin_table_c7Zin_table_c8Zin_table_c9UnicodeErrorany)labelZnewlabelcZRandALr   r   r	   nameprep   sH   


	r   c                 C   s   z|  d} W n	 ty   Y nw dt|   k rdk r#| S  tdtdt| } z|  d} W n	 ty;   Y nw dt|   k rIdk rN| S  tdtd| tr[td|  d} t|  } dt|   k rqdk rv| S  tdtd)Nasciir   @   label empty or too longzLabel starts with ACE prefixpunycode)encoder   lenr   
startswithsace_prefix
ace_prefix)r   r   r   r	   ToASCII>   s6   

r   c                 C   s   t | trd}nz	| d} d}W n ty   d}Y nw |s6t| } z| d} W n ty5   tdw | ts@t| dS | ttd  }|	d}t
|}t| d t|dkrctd| ||S )NTr   FzInvalid character in IDN labelr   zIDNA does not round-trip)
isinstancebytesr   r   r   r   r   strr   decoder   lower)r   Z
pure_asciiZlabel1resultZlabel2r   r   r	   	ToUnicodei   s.   




r%   c                   @   s    e Zd ZdddZdddZdS )Codecstrictc                 C   s  |dkr
t d| |sdS z|d}W n	 ty   Y n5w |d}|d d D ]}dt|  k r;dk s@t d	 t d	q*t|d dkrMt d
|t|fS t }t|}|rg|d sgd}|d= nd}|D ]}|rt|d |t| qkt	|| t|fS )Nr'   unsupported error handling     r   r      .r   r   r   r   zlabel too longr*   )
r   r   UnicodeEncodeErrorsplitr   	bytearraydotsextendr   r    )selfinputerrorsr$   labelsr   trailing_dotr   r   r	   r      s<   


zCodec.encodec                 C   s   |dkr
t d| |sdS t|tst|}t|vr/z
|dt|fW S  ty.   Y nw |d}|rDt|d dkrDd}|d= nd	}g }|D ]	}|t	| qJd
|| t|fS )
Nr'   Unsupported error handling r   r   r   r+   r   r   .r   )r   r   r    r   r"   r   UnicodeDecodeErrorr-   r   r%   r   )r1   r2   r3   r4   r5   r$   r   r   r   r	   r"      s*   

zCodec.decodeN)r'   )__name__
__module____qualname__r   r"   r   r   r   r	   r&      s    
%r&   c                   @      e Zd Zdd ZdS )IncrementalEncoderc           	      C   s   |dkr
t d| |sdS t|}d}|r*|d s!d}|d= n	|s*|d= |r*d}t }d}|D ]}|r>|d |d7 }|t| |t|7 }q1||7 }|t|7 }t||fS )	Nr'   r(   r)   r*   r   r+   r      )r   r/   r-   r.   r0   r   r   r    	r1   r2   r3   finalr4   r5   r$   sizer   r   r   r	   _buffer_encode   s2   

z!IncrementalEncoder._buffer_encodeN)r:   r;   r<   rC   r   r   r   r	   r>          r>   c                   @   r=   )IncrementalDecoderc           	      C   s   |dkr
t d| |sdS t|trt|}n
t|d}|d}d}|r:|d s1d}|d= n	|s:|d= |r:d}g }d}|D ]}|t| |rO|d	7 }|t|7 }q@d|| }|t|7 }||fS )
Nr'   r6   r7   r   r8   r   r   r   r?   )	r   r   r!   r/   r-   r   r%   r   r   r@   r   r   r	   _buffer_decode   s6   


z!IncrementalDecoder._buffer_decodeN)r:   r;   r<   rF   r   r   r   r	   rE      rD   rE   c                   @      e Zd ZdS )StreamWriterNr:   r;   r<   r   r   r   r	   rH   $      rH   c                   @   rG   )StreamReaderNrI   r   r   r   r	   rK   '  rJ   rK   c                	   C   s    t jdt jt jttttdS )NZidna)namer   r"   incrementalencoderincrementaldecoderstreamwriterstreamreader)	codecs	CodecInfor&   r   r"   r>   rE   rH   rK   r   r   r   r	   getregentry,  s   rS   )r   rerQ   r   r   compiler/   r   r   r   r   r%   r&   BufferedIncrementalEncoderr>   BufferedIncrementalDecoderrE   rH   rK   rS   r   r   r   r	   <module>   s   
0+)H#'