
    j                    F   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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_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      =/var/www/html/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                      e Zd ZdZddZy)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.
    c                N   |dk7  rt        d| dd      |sy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  }|	|fS )Nr   r   r   r   r   r   r      .r   r   )r   r   splitappendr   r   join)
r   r   r   finallabelstrailing_dotresultsizelabelresult_bytess
             r   _buffer_encodez!IncrementalEncoder._buffer_encode3   s    X:6(!DK_``!''-":#2J2J#'L 	EMM&-(	CJD		 yy(<7L!!T!!r   N)r   r    r   r    r2   boolr!   r"   )r%   r&   r'   r(   r9   r)   r   r   r+   r+   '   s    	"r   r+   c                      e Zd ZdZddZy)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.
    c                   |dk7  rt        d| dd      |syt        |t              s	 t        |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  }|
|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   r-   .r   r   )
r   
isinstancer    UnicodeDecodeErrorr   r/   r0   r   r   r1   )r   r   r   r2   errr3   r4   r5   r6   r7   
result_strs              r   _buffer_decodez!IncrementalDecoder._buffer_decode]   s   X:6(!DK_``$$[4) "''-":"2J2J#&L 	EMM&-(	CJD		 XXf%4
L!!D!!3 & [ :QWZZ[s   C 	C CC N)r   r   r   r    r2   r:   r!   r$   )r%   r&   r'   r(   rE   r)   r   r   r<   r<   S   s    #"r   r<   c                      e Zd Zy)StreamWriterNr%   r&   r'   r)   r   r   rG   rG          r   rG   c                      e Zd Zy)StreamReaderNrH   r)   r   r   rK   rK      rI   r   rK   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<   rG   rK   )rN   s    r   search_functionrU      sC     zw~~w~~--!! r   )rN   r    r!   zcodecs.CodecInfo | None)
__future__r   rS   typingr   corer   r   r   r	   r
   r   r   BufferedIncrementalEncoderr+   BufferedIncrementalDecoderr<   rG   rK   rU   registerr)   r   r   <module>r\      s    "   M M'FLL '<)":: )"X-":: -"`	5&-- 		5&-- 	0   r   