o
    j                     @  s   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 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dZee dS )    )annotationsN)Any   )	IDNAError_unicode_dots_realabeldecodeencodeulabelc                   @  s(   e Zd ZdZdddd	Zd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                 C  4   |dkrt d| ddd|sdS t|t|fS )Nr   Unsupported error handling ""unsupported_errorscode    r   )r   r	   lenselfr   r    r   H/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/idna/codec.pyr	      
   zCodec.encodebytestuple[str, int]c                 C  r   )Nr   r   r   r   r    r   )r   r   r   r   r   r   r   r      r   zCodec.decodeN)r   )r   r   r   r   r   r   )r   r    r   r   r   r!   )__name__
__module____qualname____doc__r	   r   r   r   r   r   r   	   s    
	r   c                   @  s   e Zd ZdZdd	d
Zd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.

    Only the ``"strict"`` error handler is supported.
    r   r   r   finalboolr   r   c           
      C  s   |dkrt d| ddd|sdS t|}d}|r.|d s%d	}|d= n	|s.|d= |r.d	}g }d
}|D ]}|t| |rC|d7 }|t|7 }q4d	|| }	|t|7 }|	|fS )Nr   r   r   r   r   r   r      .r   r   )r   r   splitappendr   r   join)
r   r   r   r)   labelstrailing_dotresultsizelabelresult_bytesr   r   r   _buffer_encode3   s0   
z!IncrementalEncoder._buffer_encodeN)r   r   r   r   r)   r*   r   r   )r$   r%   r&   r'   r6   r   r   r   r   r(   '   s    r(   c                   @  s   e Zd ZdZdd
dZd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.

    Only the ``"strict"`` error handler is supported.
    r   r   r   r   r)   r*   r   r!   c              
   C  s   |dkrt d| ddd|sdS t|ts2zt|d}W n ty1 } zt dd	d|d }~ww t|}d
}|rN|d sEd}|d= n	|sN|d= |rNd}g }d}|D ]}	|t|	 |rc|d7 }|t|	7 }qTd	|| }
|t|7 }|
|fS )Nr   r   r   r   r   r"   asciizInvalid ASCII in A-labelinvalid_asciir#   r+   .r   r   )
r   
isinstancer   UnicodeDecodeErrorr   r-   r.   r
   r   r/   )r   r   r   r)   errr0   r1   r2   r3   r4   
result_strr   r   r   _buffer_decode]   s>   

z!IncrementalDecoder._buffer_decodeN)r   r   r   r   r)   r*   r   r!   )r$   r%   r&   r'   r?   r   r   r   r   r7   S   s    	r7   c                   @     e Zd ZdS )StreamWriterNr$   r%   r&   r   r   r   r   rA          rA   c                   @  r@   )StreamReaderNrB   r   r   r   r   rD      rC   rD   namer   r   codecs.CodecInfo | Nonec              	   C  s,   | dkrdS t j| t jt jttttd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)rE   r	   r   incrementalencoderincrementaldecoderstreamwriterstreamreader)	codecs	CodecInfor   r	   r   r(   r7   rA   rD   )rE   r   r   r   search_function   s   rN   )rE   r   r   rF   )
__future__r   rL   typingr   corer   r   r   r   r	   r
   r   BufferedIncrementalEncoderr(   BufferedIncrementalDecoderr7   rA   rD   rN   registerr   r   r   r   <module>   s     ,0
