
    jB                    4   d dl mZ d dlZd dlmZ ddlmZmZmZm	Z	m
Z
mZmZ  G d dej                  Z G d d	ej                  Z G d
 dej                  Z G d deej                  Z G d deej                  ZddZ ej        e           dS )    )annotationsN)Any   )	IDNAError_max_domain_length_unicode_dots_realabeldecodeencodeulabelc                  &    e Zd ZdZdddZdddZdS )Codecaf  Stateless IDNA 2008 codec.

    Implements the :class:`codecs.Codec` protocol so that the whole-domain
    encoder (:func:`idna.encode`) and decoder (:func:`idna.decode`) are
    accessible through the standard codec machinery as ``"idna2008"``.

    Only the ``"strict"`` error handler is supported; any other handler
    raises :exc:`~idna.IDNAError`.
    strictdatastrerrorsreturntuple[bytes, int]c                |    |dk    rt          d| dd          |sdS t          |          t          |          fS )Nr   Unsupported error handling ""unsupported_errorscode)    r   )r   r   lenselfr   r   s      9/opt/deyu/venv/lib/python3.11/site-packages/idna/codec.pyr   zCodec.encode   sQ    XD6DDDK_```` 	6d||SYY&&r   bytestuple[str, int]c                |    |dk    rt          d| dd          |sdS t          |          t          |          fS )Nr   r   r   r   r    r   )r   r
   r   r   s      r   r
   zCodec.decode   sQ    XD6DDDK_```` 	5d||SYY&&r   Nr   )r   r   r   r   r   r   )r   r    r   r   r   r!   )__name__
__module____qualname____doc__r   r
    r   r   r   r   	   sP         ' ' ' ' '' ' ' ' ' ' 'r   r   c                  J     e Zd ZdZdd fdZd fdZdd
ZddZddZ xZ	S )IncrementalEncodera  Incremental IDNA 2008 encoder.

    Buffers a partial trailing label across calls until either the next
    label separator is seen or ``final=True``, so that streamed input is
    encoded one whole label at a time. Any of the four Unicode label
    separators (``U+002E``, ``U+3002``, ``U+FF0E``, ``U+FF61``) ends a
    label; the result always uses ``U+002E`` as the separator.

    The 253-octet domain length limit (254 with a trailing dot) that
    :func:`idna.encode` enforces is applied to the accumulated output, so
    that streaming a name and encoding it in one shot either both succeed
    with the same result or both raise :exc:`~idna.IDNAError`.

    Only the ``"strict"`` error handler is supported.
    r   r   r   r   Nonec                f    t                                          |           d| _        d| _        d S Nr   F)super__init___emitted_trailing_dotr   r   	__class__s     r   r1   zIncrementalEncoder.__init__8   s0       "r   c                d    t                                                       d| _        d| _        d S r/   )r0   resetr2   r3   r   r5   s    r   r7   zIncrementalEncoder.reset=   s)    "r   r   c                J    | j         s	| j        sdS | j         | j        | j        fS Nr   )bufferr2   r3   r   s    r   getstatezIncrementalEncoder.getstateB   s.    { 	4= 	1T]D,>??r   statec                `    |r|\  | _         | _        | _        d S |                                  d S N)r;   r2   r3   r7   r   r>   s     r   setstatezIncrementalEncoder.setstateG   s4     	=B:DK(:(:(:JJLLLLLr   r   finalboolr   c                P   |dk    rt          d| dd          d}d}|rt          j        |          }d}|r|d         sd	}|d= n	|s|d= |rd	}g }|D ]=}	|                    t	          |	                     |r|d
z  }|t          |	          z  }>d	                    |          |z   }|t          |          z  }| xj        t          |          z  c_        |r|                    d	          | _	        | j	        p| }
| j        t          |
z   k    rt          dd          ||fS )Nr   r   r   r   r   r   r      .r   Domain too longdomain_too_long)r   r   splitappendr	   r   joinr2   endswithr3   r   )r   r   r   rC   result_bytessizelabelstrailing_dotresultlabelmay_end_with_dots              r   _buffer_encodez!IncrementalEncoder._buffer_encodeM   s   XD6DDDK_```` 	&%+D11FL ,bz ,#'Lr

 ,r
 ,'+F # #fUmm,,, AIDE

"99V,,|;LC%%%D
 	\*** 	=!-!6!6t!<!<D-:U=-0@@@@-4EFFFFT!!r   r%   r   r   r   r-   r   r-   )r   r   )r>   r   r   r-   )r   r   r   r   rC   rD   r   r   )
r&   r'   r(   r)   r1   r7   r=   rB   rU   __classcell__r5   s   @r   r,   r,   '   s          # # # # # # #
# # # # # #
@ @ @ @
   &" &" &" &" &" &" &" &"r   r,   c                  J     e Zd ZdZdd fdZd fdZdd
ZddZddZ xZ	S )IncrementalDecodera  Incremental IDNA 2008 decoder.

    Buffers a partial trailing label across calls until either the next
    label separator is seen or ``final=True``, so that streamed input is
    decoded one whole label at a time.

    The 254-octet input length limit that :func:`idna.decode` enforces is
    applied to the accumulated input, so that streaming a name and decoding
    it in one shot either both succeed with the same result or both raise
    :exc:`~idna.IDNAError`.

    Only the ``"strict"`` error handler is supported.
    r   r   r   r   r-   c                X    t                                          |           d| _        d S r:   )r0   r1   	_consumedr4   s     r   r1   zIncrementalDecoder.__init__   s&       r   c                V    t                                                       d| _        d S r:   )r0   r7   r]   r8   s    r   r7   zIncrementalDecoder.reset   s    r   r   c                    | j         | j        fS r@   r;   r]   r<   s    r   r=   zIncrementalDecoder.getstate   s    T^,,r   r>   c                $    |\  | _         | _        d S r@   r`   rA   s     r   rB   zIncrementalDecoder.setstate   s    &+#T^^^r   r   r   rC   rD   r!   c                   |dk    rt          d| dd          |sdS t          |t                    s6	 t          |d          }n$# t          $ r}t          dd	          |d }~ww xY w| j        t          |          z   t          d
z   k    rt          dd          t          j        |          }d}|r|d         sd}|d= n	|s|d= |rd}g }d}|D ]=}	|	                    t          |	                     |r|d
z  }|t          |	          z  }>d                    |          |z   }
|t          |          z  }| xj        |z  c_        |
|fS )Nr   r   r   r   r   r#   asciizInvalid ASCII in A-labelinvalid_asciir   rH   rI   r$   rF   .r   )r   
isinstancer   UnicodeDecodeErrorr]   r   r   r   rJ   rK   r   rL   )r   r   r   rC   errrP   rQ   rR   rO   rS   
result_strs              r   _buffer_decodez!IncrementalDecoder._buffer_decode   s   XD6DDDK_```` 	7$$$ 	[[4))% [ [ [ :QQQWZZ[ >CII%(:Q(>>>-4EFFFF!'-- 	'": '"2JJ '2J '#&L 	 	EMM&--((( 	CJJDDXXf%%4
L!!!$D!!s   A 
A(A##A(r%   rV   rW   )r   r   )r>   r   r   r-   )r   r   r   r   rC   rD   r   r!   )
r&   r'   r(   r)   r1   r7   r=   rB   rj   rX   rY   s   @r   r[   r[   v   s                    - - - -, , , ,+" +" +" +" +" +" +" +"r   r[   c                      e Zd ZdS )StreamWriterNr&   r'   r(   r*   r   r   rl   rl              Dr   rl   c                      e Zd ZdS )StreamReaderNrm   r*   r   r   rp   rp      rn   r   rp   namer   r   codecs.CodecInfo | Nonec           	         | dk    rdS t          j        | t                      j        t                      j        t
          t          t          t                    S )a  Codec search function registered with :mod:`codecs`.

    Returns a :class:`codecs.CodecInfo` for the ``"idna2008"`` codec name
    so that ``str.encode("idna2008")`` and ``bytes.decode("idna2008")``
    invoke the IDNA 2008 codec defined in this module.

    :param name: The codec name being looked up.
    :returns: A :class:`codecs.CodecInfo` instance if ``name`` is
        ``"idna2008"``, otherwise ``None``.
    idna2008N)rq   r   r
   incrementalencoderincrementaldecoderstreamwriterstreamreader)	codecs	CodecInfor   r   r
   r,   r[   rl   rp   )rq   s    r   search_functionr{      sO     ztww~ww~--!!   r   )rq   r   r   rr   )
__future__r   ry   typingr   corer   r   r   r	   r
   r   r   r   BufferedIncrementalEncoderr,   BufferedIncrementalDecoderr[   rl   rp   r{   registerr*   r   r   <module>r      s   " " " " " "        a a a a a a a a a a a a a a a a a a' ' ' ' 'FL ' ' '<L" L" L" L" L": L" L" L"^H" H" H" H" H": H" H" H"V	 	 	 	 	5&- 	 	 		 	 	 	 	5&- 	 	 	   0           r   