a
    %ñ»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œdd„Ze e¡ dS )é    )ÚannotationsN)ÚAnyé   )Ú	IDNAErrorÚ_max_domain_lengthÚ_unicode_dots_reÚalabelÚdecodeÚencodeÚulabelc                   @  s8   e Zd ZdZdddddœdd„Zddd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Ústrútuple[bytes, int])ÚdataÚerrorsÚreturnc                 C  s4   |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   ú0E:\soccer\ml_env\Lib\site-packages\idna/codec.pyr
      s
    zCodec.encodeÚbytesútuple[str, int]c                 C  s4   |dkrt d|› d�dd�‚|s$dS t|ƒt|ƒfS )Nr   r   r   r   r   ©Ú r   )r   r	   r   r   r   r   r   r	      s
    zCodec.decodeN)r   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r	   r   r   r   r   r   	   s   
	r   c                      sn   e Zd ZdZddddœ‡ fdd„Zddœ‡ fd	d
„Zddœdd„Zdddœdd„Zdddd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   ÚNone©r   r   c                   s   t ƒ  |¡ d| _d| _d S ©Nr   F)ÚsuperÚ__init__Ú_emittedÚ_trailing_dot©r   r   ©Ú	__class__r   r   r+   8   s    zIncrementalEncoder.__init__©r   c                   s   t ƒ  ¡  d| _d| _d S r)   )r*   Úresetr,   r-   ©r   r/   r   r   r2   =   s    
zIncrementalEncoder.resetr   c                 C  s    | j s| jsdS | j | j| jfS ©Nr   )Úbufferr,   r-   r3   r   r   r   ÚgetstateB   s    zIncrementalEncoder.getstate©Ústater   c                 C  s"   |r|\| _ | _| _n|  ¡  d S ©N)r5   r,   r-   r2   ©r   r8   r   r   r   ÚsetstateG   s    zIncrementalEncoder.setstateÚboolr   ©r   r   Úfinalr   c                 C  sþ   |dkrt d|› d�dd�‚d}d}|r®t |¡}d}|r`|d sNd	}|d= n|s`|d= |r`d	}g }|D ]*}	| t|	ƒ¡ |r†|d
7 }|t|	ƒ7 }qhd	 |¡| }|t|ƒ7 }|  jt|ƒ7  _|rÐ| d	¡| _	| j	pÚ| }
| 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>   Zresult_bytesÚsizeÚlabelsÚtrailing_dotÚresultÚlabelZmay_end_with_dotr   r   r   Ú_buffer_encodeM   s<    
z!IncrementalEncoder._buffer_encode)r   )
r"   r#   r$   r%   r+   r2   r6   r;   rL   Ú__classcell__r   r   r/   r   r&   '   s   r&   c                      sn   e Zd ZdZddddœ‡ fdd„Zddœ‡ fd	d
„Zddœdd„Zdddœdd„Zdddd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(   c                   s   t ƒ  |¡ d| _d S r4   )r*   r+   Ú	_consumedr.   r/   r   r   r+   …   s    zIncrementalDecoder.__init__r1   c                   s   t ƒ  ¡  d| _d S r4   )r*   r2   rO   r3   r/   r   r   r2   ‰   s    
zIncrementalDecoder.resetr   c                 C  s   | j | jfS r9   ©r5   rO   r3   r   r   r   r6   �   s    zIncrementalDecoder.getstater7   c                 C  s   |\| _ | _d S r9   rP   r:   r   r   r   r;   �   s    zIncrementalDecoder.setstater   r<   r   r=   c              
   C  s2  |dkrt d|› d�dd�‚|s$dS t|tƒspzt|dƒ}W n2 tyn } zt dd	d�|‚W Y d }~n
d }~0 0 | jt|ƒ td
 kr’t ddd�‚t |¡}d}|rÊ|d s¸d}|d= n|sÊ|d= |rÊd}g }d}|D ]*}	| 	t
|	ƒ¡ |rô|d
7 }|t|	ƒ7 }qÖd |¡| }
|t|ƒ7 }|  j|7  _|
|fS )Nr   r   r   r   r   r    ÚasciizInvalid ASCII in A-labelZinvalid_asciir   rA   rB   r!   r?   Ú.r   )r   Ú
isinstancer   ÚUnicodeDecodeErrorrO   r   r   r   rC   rD   r   rE   )r   r   r   r>   ÚerrrH   rI   rJ   rG   rK   Z
result_strr   r   r   Ú_buffer_decode“   s@    
$
z!IncrementalDecoder._buffer_decode)r   )
r"   r#   r$   r%   r+   r2   r6   r;   rV   rM   r   r   r/   r   rN   v   s   rN   c                   @  s   e Zd ZdS )ÚStreamWriterN©r"   r#   r$   r   r   r   r   rW   Á   s   rW   c                   @  s   e Zd ZdS )ÚStreamReaderNrX   r   r   r   r   rY   Å   s   rY   r   zcodecs.CodecInfo | None)Únamer   c              	   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``.
    Zidna2008N)rZ   r
   r	   ÚincrementalencoderÚincrementaldecoderÚstreamwriterÚstreamreader)	ÚcodecsÚ	CodecInfor   r
   r	   r&   rN   rW   rY   )rZ   r   r   r   Úsearch_functionÉ   s    ùra   )Ú
__future__r   r_   Útypingr   Úcorer   r   r   r   r	   r
   r   r   ÚBufferedIncrementalEncoderr&   ÚBufferedIncrementalDecoderrN   rW   rY   ra   Úregisterr   r   r   r   Ú<module>   s   $OK