o
    òT·jB  ã                   @  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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Ú_max_domain_lengthÚ_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   úM/home/dinkstrade/pdmp-scanner/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                      sP   e Zd ZdZdd‡ fdd„Zd‡ fd	d
„Zddd„Zddd„Zddd„Z‡  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                   s   t ƒ  |¡ d| _d| _d S ©Nr   F)ÚsuperÚ__init__Ú_emittedÚ_trailing_dot©r   r   ©Ú	__class__r   r   r-   8   s   
zIncrementalEncoder.__init__c                   s   t ƒ  ¡  d| _d| _d S r+   )r,   Úresetr.   r/   ©r   r1   r   r   r3   =   s   

zIncrementalEncoder.resetr   c                 C  s    | j s| jsdS | j | j| jfS ©Nr   )Úbufferr.   r/   r4   r   r   r   ÚgetstateB   s   zIncrementalEncoder.getstateÚstatec                 C  s$   |r|\| _ | _| _d S |  ¡  d S ©N)r6   r.   r/   r3   ©r   r8   r   r   r   ÚsetstateG   s   zIncrementalEncoder.setstater   ÚfinalÚboolr   c                 C  sþ   |dkrt d|› d�dd�‚d}d}|rWt |¡}d}|r0|d s'd	}|d= n	|s0|d= |r0d	}g }|D ]}	| t|	ƒ¡ |rC|d
7 }|t|	ƒ7 }q4d	 |¡| }|t|ƒ7 }|  jt|ƒ7  _|rh| d	¡| _	| j	pm| }
| jt
|
 kr{t ddd�‚||fS )Nr   r   r   r   r   r   r   éÿÿÿÿó   .r   úDomain too longÚdomain_too_long)r   r   ÚsplitÚappendr   r   Újoinr.   Úendswithr/   r   )r   r   r   r<   Úresult_bytesÚsizeÚlabelsÚtrailing_dotÚresultÚlabelÚmay_end_with_dotr   r   r   Ú_buffer_encodeM   s<   
z!IncrementalEncoder._buffer_encoder$   ©r   r   r   r*   ©r   r*   )r   r   )r8   r   r   r*   )r   r   r   r   r<   r=   r   r   )
r%   r&   r'   r(   r-   r3   r7   r;   rM   Ú__classcell__r   r   r1   r   r)   '   s    

r)   c                      sP   e Zd ZdZdd‡ fdd„Zd‡ fd	d
„Zddd„Zddd„Zddd„Z‡  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                   s   t ƒ  |¡ d| _d S r5   )r,   r-   Ú	_consumedr0   r1   r   r   r-   …   s   
zIncrementalDecoder.__init__c                   s   t ƒ  ¡  d| _d S r5   )r,   r3   rR   r4   r1   r   r   r3   ‰   s   

zIncrementalDecoder.resetr   c                 C  s   | j | jfS r9   ©r6   rR   r4   r   r   r   r7   �   s   zIncrementalDecoder.getstater8   c                 C  s   |\| _ | _d S r9   rS   r:   r   r   r   r;   �   s   zIncrementalDecoder.setstater   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 | jt|ƒ td
 krCt ddd�‚t |¡}d}|r_|d sVd}|d= n	|s_|d= |r_d}g }d}|D ]}	| 	t
|	ƒ¡ |rt|d
7 }|t|	ƒ7 }qed |¡| }
|t|ƒ7 }|  j|7  _|
|fS )Nr   r   r   r   r   r"   ÚasciizInvalid ASCII in A-labelÚinvalid_asciir   r@   rA   r#   r>   Ú.r   )r   Ú
isinstancer   ÚUnicodeDecodeErrorrR   r   r   r   rB   rC   r   rD   )r   r   r   r<   ÚerrrH   rI   rJ   rG   rK   Ú
result_strr   r   r   Ú_buffer_decode“   sD   
€ÿ
z!IncrementalDecoder._buffer_decoder$   rN   rO   )r   r   )r8   r   r   r*   )r   r   r   r   r<   r=   r   r!   )
r%   r&   r'   r(   r-   r3   r7   r;   r[   rP   r   r   r1   r   rQ   v   s    

rQ   c                   @  ó   e Zd ZdS )ÚStreamWriterN©r%   r&   r'   r   r   r   r   r]   Á   ó    r]   c                   @  r\   )ÚStreamReaderNr^   r   r   r   r   r`   Å   r_   r`   Ú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)ra   r
   r	   ÚincrementalencoderÚincrementaldecoderÚstreamwriterÚstreamreader)	ÚcodecsÚ	CodecInfor   r
   r	   r)   rQ   r]   r`   )ra   r   r   r   Úsearch_functionÉ   s   ùrj   )ra   r   r   rb   )Ú
__future__r   rh   Útypingr   Úcorer   r   r   r   r	   r
   r   r   ÚBufferedIncrementalEncoderr)   ÚBufferedIncrementalDecoderrQ   r]   r`   rj   Úregisterr   r   r   r   Ú<module>   s    $OK
