
    OjB                    J   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       y)    )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y)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`.
    c                `    |dk7  rt        d| dd      |syt        |      t        |      fS )NstrictUnsupported error handling ""unsupported_errorscode)    r   )r   r   lenselfdataerrorss      a/var/www/origus_pro_usr/data/www/origus.pro/core/.venv/lib/python3.12/site-packages/idna/codec.pyr   zCodec.encode   s;    X:6(!DK_``d|SY&&r   c                `    |dk7  rt        d| dd      |syt        |      t        |      fS )Nr   r   r   r   r    r   )r   r
   r   r   s      r   r
   zCodec.decode   s;    X:6(!DK_``d|SY&&r   Nr   )r   strr   r!   returntuple[bytes, int])r   bytesr   r!   r"   tuple[str, int])__name__
__module____qualname____doc__r   r
    r   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 )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.
    c                @    t         |   |       d| _        d| _        y Nr   F)super__init___emitted_trailing_dotr   r   	__class__s     r   r0   zIncrementalEncoder.__init__8   s     "r   c                >    t         |           d| _        d| _        y r.   )r/   resetr1   r2   r   r4   s    r   r6   zIncrementalEncoder.reset=   s    "r   c                z    | j                   s| j                  sy| j                   | j                  | j                  fS Nr   )bufferr1   r2   r   s    r   getstatezIncrementalEncoder.getstateB   s-    {{4==T]]D,>,>??r   c                T    |r|\  | _         | _        | _        y | j                          y N)r:   r1   r2   r6   r   states     r   setstatezIncrementalEncoder.setstateG   s!    =B:DK(:JJLr   c                $   |dk7  rt        d| dd      d}d}|rt        j                  |      }d}|r|d   sd	}|d= n	|s|d= |rd	}g }|D ]1  }	|j                  t	        |	             |r|d
z  }|t        |	      z  }3 d	j                  |      |z   }|t        |      z  }| xj                  t        |      z  c_        |r|j                  d	      | _	        | j                  xs | }
| j                  t        |
z   kD  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   joinr1   endswithr2   r   )r   r   r   finalresult_bytessizelabelstrailing_dotresultlabelmay_end_with_dots              r   _buffer_encodez!IncrementalEncoder._buffer_encodeM   s9   X:6(!DK_``%++D1FLbz#'Lr
r
'+F #fUm,AIDE
"	#  99V,|;LC%%D
 	\**!-!6!6t!<D--:U==-0@@@-4EFFT!!r   r    r   r!   r"   Noner"   rU   )r"   r   )r@   r   r"   rU   )r   r!   r   r!   rK   boolr"   r#   )
r&   r'   r(   r)   r0   r6   r<   rA   rS   __classcell__r4   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.
    c                2    t         |   |       d| _        y r9   )r/   r0   	_consumedr3   s     r   r0   zIncrementalDecoder.__init__   s     r   c                0    t         |           d| _        y r9   )r/   r6   r]   r7   s    r   r6   zIncrementalDecoder.reset   s    r   c                2    | j                   | j                  fS r>   r:   r]   r;   s    r   r<   zIncrementalDecoder.getstate   s    T^^,,r   c                "    |\  | _         | _        y r>   r`   r?   s     r   rA   zIncrementalDecoder.setstate   s    &+#T^r   c                N   |dk7  rt        d| dd      |syt        |t              s	 t        |d      }| j                  t        |      z   t        d
z   kD  rt        dd      t        j                  |      }d}|r|d   sd}|d= n	|s|d= |rd}g }d}|D ]1  }	|j                  t        |	             |r|d
z  }|t        |	      z  }3 dj                  |      |z   }
|t        |      z  }| xj                  |z  c_        |
|fS # t        $ r}t        dd	      |d }~ww xY w)Nr   r   r   r   r   r   asciizInvalid ASCII in A-labelinvalid_asciir   rE   rF   r   rC   .r   )r   
isinstancer!   UnicodeDecodeErrorr]   r   r   r   rG   rH   r   rI   )r   r   r   rK   errrN   rO   rP   rM   rQ   
result_strs              r   _buffer_decodez!IncrementalDecoder._buffer_decode   sS   X:6(!DK_``$$[4) >>CI%(:Q(>>-4EFF!''-":"2J2J#&L 	EMM&-(	CJD		 XXf%4
L!!$D!!C & [ :QWZZ[s   D 	D$DD$r    rT   rV   )r"   r#   )r@   r#   r"   rU   )r   r   r   r!   rK   rW   r"   r%   )
r&   r'   r(   r)   r0   r6   r<   rA   rj   rX   rY   s   @r   r[   r[   v   s!    -,+"r   r[   c                      e Zd Zy)StreamWriterNr&   r'   r(   r*   r   r   rl   rl          r   rl   c                      e Zd Zy)StreamReaderNrm   r*   r   r   rp   rp      rn   r   rp   c           	         | dk7  ry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)namer   r
   incrementalencoderincrementaldecoderstreamwriterstreamreader)	codecs	CodecInfor   r   r
   r,   r[   rl   rp   )rs   s    r   search_functionrz      sC     zw~~w~~--!! r   )rs   r!   r"   zcodecs.CodecInfo | None)
__future__r   rx   typingr   corer   r   r   r	   r
   r   r   r   BufferedIncrementalEncoderr,   BufferedIncrementalDecoderr[   rl   rp   rz   registerr*   r   r   <module>r      s    "   a a a'FLL '<L":: L"^H":: H"V	5&-- 		5&-- 	0   r   