a
    ze                     @   s   d dl Z dd Zdd Zdd Zdd	 Zd
d ZdZdd Zdd Zdd Z	d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 )'    Nc                 C   sP   t  }t }| D ]*}t|dk r0|t| q|| qt|}t||fS )N   )	bytearraysetordappendaddsortedbytes)strbaseextendedc r   (/usr/lib/python3.9/encodings/punycode.py	segregate
   s    r   c                 C   s&   d}| D ]}t ||k r|d7 }q|S )Nr      )r   )r
   maxresr   r   r   r   selective_len   s
    
r   c                 C   sN   t | }|d7 }||krdS | | }||kr8|d |fS ||k r|d7 }qd S )Nr   )r   )len)r
   charindexposlr   r   r   r   selective_find   s    r   c                 C   s   d}g }d}|D ]r}d }}t |}t| |}	|	d ||  }
t| |||\}}|dkrZq~|
|| 7 }
||
d  |}d}
q>|}q|S )Nr   r   r   r   )r   r   r   r   )r
   r   ZoldcharresultZoldindexr   r   r   r   Zcurlendeltar   r   r   insertion_unsort0   s"    
r   c                 C   s,   d| d  | }|dk rdS |dkr(dS |S )N$   r      r   )jbiasr   r   r   r   TF   s    r#   s$   abcdefghijklmnopqrstuvwxyz0123456789c                 C   sn   t  }d}t||}| |k r2|t|   t|S |t|| | d|     | | d|  } |d7 }q
d S )Nr   r   r   )r   r#   r   digitsr	   )Nr"   r   r!   tr   r   r   generate_generalized_integerN   s    
r'   c                 C   sX   |r| d } n| d } | | | 7 } d}| dkr@| d } |d7 }q&|d|  | d   }|S )Ni     r   i  #   r   &   r   )r   firstnumcharsZ	divisionsr"   r   r   r   adapt[   s    

r-   c                 C   sP   t  }d}t|D ]4\}}t||}|| t||dk| | d }qt|S )NH   r   r   )r   	enumerater'   extendr-   r	   )Zbaselendeltasr   r"   Zpointsr   sr   r   r   generate_integersj   s    

r3   c                 C   s8   t | \}}t| |}tt||}|r4|d | S |S )N   -)r   r   r3   r   )textr   r   r1   r   r   r   punycode_encodeu   s    
r6   c           
      C   s   d}d}d}zt | | }W n. tyJ   |dkr:td|d d f Y S 0 |d7 }d|  krhdkrvn n
|d }nHd|  krdkrn n
|d	 }n&|dkrtd
| |d   n|d fS t||}	||| 7 }||	k r||fS |d|	  }|d7 }qd S )Nr   r   strictzincomplete punicode stringA   Z   0   9      z Invalid extended code point '%s'r   )r   
IndexErrorUnicodeErrorr#   )
r   extposr"   errorsr   wr!   r   Zdigitr&   r   r   r   decode_generalized_number   s2    



rB   c           	      C   s   d}d}d}d}|t |k rt||||\}}|d u r:| S ||d 7 }||t | d  7 }|dkr~|dkrvtd| td	}|t | d  }| d | t| | |d   } t||dkt | }|}q| S )
Nr   r   r.   r   r   i r7   zInvalid character U+%x?)r   rB   r>   r   chrr-   )	r   r   r@   r   r   r"   r?   Znewposr   r   r   r   insertion_sort   s*     rE   c                 C   s   t | tr| d} t | tr&t| } | d}|dkrLd}t| d }n.t| d | d|}t| |d d  d }t|||S )Nasciir4   r    r   )
isinstancer
   encode
memoryviewr	   rfindupperrE   )r5   r@   r   r   r   r   r   r   punycode_decode   s    



rM   c                   @   s    e Zd ZdddZdddZdS )	Codecr7   c                 C   s   t |}|t|fS N)r6   r   selfinputr@   r   r   r   r   rI      s    zCodec.encodec                 C   s*   |dvrt d| t||}|t|fS N)r7   replaceignorezUnsupported error handling )r>   rM   r   rP   r   r   r   decode   s    
zCodec.decodeN)r7   )r7   )__name__
__module____qualname__rI   rV   r   r   r   r   rN      s   
rN   c                   @   s   e Zd ZdddZdS )IncrementalEncoderFc                 C   s   t |S rO   )r6   rQ   rR   finalr   r   r   rI      s    zIncrementalEncoder.encodeN)F)rW   rX   rY   rI   r   r   r   r   rZ      s   rZ   c                   @   s   e Zd ZdddZdS )IncrementalDecoderFc                 C   s$   | j dvrtd| j  t|| j S rS   )r@   r>   rM   r[   r   r   r   rV      s    
zIncrementalDecoder.decodeN)F)rW   rX   rY   rV   r   r   r   r   r]      s   r]   c                   @   s   e Zd ZdS )StreamWriterNrW   rX   rY   r   r   r   r   r^      s   r^   c                   @   s   e Zd ZdS )StreamReaderNr_   r   r   r   r   r`      s   r`   c                	   C   s    t jdt jt jttttdS )NZpunycode)namerI   rV   incrementalencoderincrementaldecoderstreamwriterstreamreader)	codecs	CodecInforN   rI   rV   rZ   r]   r^   r`   r   r   r   r   getregentry   s    rh   )rf   r   r   r   r   r#   r$   r'   r-   r3   r6   rB   rE   rM   rN   rZ   r]   r^   r`   rh   r   r   r   r   <module>   s&   
