
    MhS)                     "   d Z ddlmZ ddlZddlmZ dZddd	d
dZi Zd Z	d Z
d Z G d de          Z e
d          Z e
d          Z e
d          Zd!dZd ZedfdZd!dZd ZedfdZd Z G d de          Z G d d e          ZdS )"a  

    webencodings
    ~~~~~~~~~~~~

    This is a Python implementation of the `WHATWG Encoding standard
    <http://encoding.spec.whatwg.org/>`. See README for details.

    :copyright: Copyright 2012 by Simon Sapin
    :license: BSD, see LICENSE for details.

    )unicode_literalsN   )LABELSz0.5.1z
iso-8859-8zmac-cyrillicz	mac-romancp874)ziso-8859-8-izx-mac-cyrillic	macintoshzwindows-874c                 v    |                      d                                                              d          S )a9  Transform (only) ASCII letters to lower case: A-Z is mapped to a-z.

    :param string: An Unicode string.
    :returns: A new Unicode string.

    This is used for `ASCII case-insensitive
    <http://encoding.spec.whatwg.org/#ascii-case-insensitive>`_
    matching of encoding labels.
    The same matching is also used, among other things,
    for `CSS keywords <http://dev.w3.org/csswg/css-values/#keywords>`_.

    This is different from the :meth:`~py:str.lower` method of Unicode strings
    which also affect non-ASCII characters,
    sometimes mapping them into the ASCII range:

        >>> keyword = u'Bac\N{KELVIN SIGN}ground'
        >>> assert keyword.lower() == u'background'
        >>> assert ascii_lower(keyword) != keyword.lower()
        >>> assert ascii_lower(keyword) == u'bac\N{KELVIN SIGN}ground'

    utf8)encodelowerdecode)strings    U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/webencodings/__init__.pyascii_lowerr   #   s0    . ==  &&((//777    c                 ^   t          |                     d                    } t          j        |           }|dS t                              |          }|V|dk    rddlm} n/t                              ||          }t          j	        |          }t          ||          }|t          |<   |S )u<  
    Look for an encoding by its label.
    This is the spec’s `get an encoding
    <http://encoding.spec.whatwg.org/#concept-encoding-get>`_ algorithm.
    Supported labels are listed there.

    :param label: A string.
    :returns:
        An :class:`Encoding` object, or :obj:`None` for an unknown label.

    z	
 Nzx-user-definedr   )
codec_info)r   stripr   getCACHEx_user_definedr   PYTHON_NAMEScodecslookupEncoding)labelnameencodingr   python_names        r   r   r   =   s     K0011E:eD|tyyH###2222222&**466K{33JD*--dOr   c                 p    t          | d          r| S t          |           }|t          d| z            |S )z
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    r   NzUnknown encoding label: %r)hasattrr   LookupError)encoding_or_labelr   s     r   _get_encodingr#   [   sK      ,// !  '((H69JJKKKOr   c                       e Zd ZdZd Zd ZdS )r   aO  Reresents a character encoding such as UTF-8,
    that can be used for decoding or encoding.

    .. attribute:: name

        Canonical name of the encoding

    .. attribute:: codec_info

        The actual implementation of the encoding,
        a stdlib :class:`~codecs.CodecInfo` object.
        See :func:`codecs.register`.

    c                 "    || _         || _        d S N)r   r   )selfr   r   s      r   __init__zEncoding.__init__|   s    	$r   c                     d| j         z  S )Nz<Encoding %s>)r   )r'   s    r   __repr__zEncoding.__repr__   s    **r   N)__name__
__module____qualname____doc__r(   r*    r   r   r   r   m   s<         % % %+ + + + +r   r   zutf-8zutf-16lezutf-16bereplacec                     t          |          }t          |           \  }} |p|}|j                            | |          d         |fS )a  
    Decode a single string.

    :param input: A byte string
    :param fallback_encoding:
        An :class:`Encoding` object or a label string.
        The encoding to use if :obj:`input` does note have a BOM.
    :param errors: Type of error handling. See :func:`codecs.register`.
    :raises: :exc:`~exceptions.LookupError` for an unknown encoding label.
    :return:
        A ``(output, encoding)`` tuple of an Unicode string
        and an :obj:`Encoding`.

    r   )r#   _detect_bomr   r   )inputfallback_encodingerrorsbom_encodingr   s        r   r   r      sS      &&788%e,,L%00H%%eV44Q7AAr   c                     |                      d          rt          | dd         fS |                      d          rt          | dd         fS |                      d          rt          | dd         fS d| fS )zBReturn (bom_encoding, input), with any BOM removed from the input.s      Ns   s   ﻿   )
startswith_UTF16LE_UTF16BEUTF8)r3   s    r   r2   r2      s    $$ #qrr""$$ #qrr""(( U122Y;r   strictc                 ^    t          |          j                            | |          d         S )a;  
    Encode a single string.

    :param input: An Unicode string.
    :param encoding: An :class:`Encoding` object or a label string.
    :param errors: Type of error handling. See :func:`codecs.register`.
    :raises: :exc:`~exceptions.LookupError` for an unknown encoding label.
    :return: A byte string.

    r   )r#   r   r
   )r3   r   r5   s      r   r
   r
      s*     ""-44UFCCAFFr   c                 h    t          ||          }t          | |          }t          |          }||fS )a  
    "Pull"-based decoder.

    :param input:
        An iterable of byte strings.

        The input is first consumed just enough to determine the encoding
        based on the precense of a BOM,
        then consumed on demand when the return value is.
    :param fallback_encoding:
        An :class:`Encoding` object or a label string.
        The encoding to use if :obj:`input` does note have a BOM.
    :param errors: Type of error handling. See :func:`codecs.register`.
    :raises: :exc:`~exceptions.LookupError` for an unknown encoding label.
    :returns:
        An ``(output, encoding)`` tuple.
        :obj:`output` is an iterable of Unicode strings,
        :obj:`encoding` is the :obj:`Encoding` that is being used.

    )IncrementalDecoder_iter_decode_generatornext)r3   r4   r5   decoder	generatorr   s         r   iter_decoderF      s9    , !!2F;;G&ug66IIHhr   c              #   .  K   |j         }t          |           } | D ]'} ||          }|r|j        J |j        V  |V   n(( |dd          }|j        J |j        V  |r|V  dS | D ]} ||          }|r|V   |dd          }|r|V  dS dS )zqReturn a generator that first yields the :obj:`Encoding`,
    then yields output chukns as Unicode strings.

    Nr   Tfinal)r   iterr   )r3   rD   r   chunckoutputs        r   rB   rB      s     
 ^FKKE   	#///""""LLLE		 4(((+++ 	LLL   	LLLVCt$$$F  r   c                 L    t          ||          j        }t          | |          S )uY  
    “Pull”-based encoder.

    :param input: An iterable of Unicode strings.
    :param encoding: An :class:`Encoding` object or a label string.
    :param errors: Type of error handling. See :func:`codecs.register`.
    :raises: :exc:`~exceptions.LookupError` for an unknown encoding label.
    :returns: An iterable of byte strings.

    )IncrementalEncoderr
   _iter_encode_generator)r3   r   r5   r
   s       r   iter_encoderP      s&      &118F!%000r   c              #   `   K   | D ]} ||          }|r|V   |dd          }|r|V  d S d S )N TrH   r/   )r3   r
   rK   rL   s       r   rO   rO     sg         	LLLVBd###F  r   c                   "    e Zd ZdZddZddZdS )	rA   uO  
    “Push”-based decoder.

    :param fallback_encoding:
        An :class:`Encoding` object or a label string.
        The encoding to use if :obj:`input` does note have a BOM.
    :param errors: Type of error handling. See :func:`codecs.register`.
    :raises: :exc:`~exceptions.LookupError` for an unknown encoding label.

    r0   c                 f    t          |          | _        || _        d| _        d | _        d | _        d S )Nr   )r#   _fallback_encoding_errors_buffer_decoderr   )r'   r4   r5   s      r   r(   zIncrementalDecoder.__init__  s5    "/0A"B"B
 r   Fc                 .   | j         }| |||          S | j        |z   }t          |          \  }}|%t          |          dk     r|s	|| _        dS | j        }|j                            | j                  j        }|| _         || _	         |||          S )zDecode one chunk of the input.

        :param input: A byte string.
        :param final:
            Indicate that no more input is available.
            Must be :obj:`True` if this is the last call.
        :returns: An Unicode string.

        Nr9   rR   )
rX   rW   r2   lenrU   r   incrementaldecoderrV   r   r   )r'   r3   rI   rD   r   s        r   r   zIncrementalDecoder.decode'  s     -75%(((u$%e,,%5zzA~~e~$r2%88FFM wue$$$r   Nr0   )F)r+   r,   r-   r.   r(   r   r/   r   r   rA   rA     sF        	 	
 
 
 
% % % % % %r   rA   c                       e Zd ZdZedfdZdS )rN   u  
    “Push”-based encoder.

    :param encoding: An :class:`Encoding` object or a label string.
    :param errors: Type of error handling. See :func:`codecs.register`.
    :raises: :exc:`~exceptions.LookupError` for an unknown encoding label.

    .. method:: encode(input, final=False)

        :param input: An Unicode string.
        :param final:
            Indicate that no more input is available.
            Must be :obj:`True` if this is the last call.
        :returns: A byte string.

    r>   c                 l    t          |          }|j                            |          j        | _        d S r&   )r#   r   incrementalencoderr
   )r'   r   r5   s      r   r(   zIncrementalEncoder.__init__T  s.     **)<<VDDKr   N)r+   r,   r-   r.   r=   r(   r/   r   r   rN   rN   C  s?           !%X L L L L L Lr   rN   r\   )r.   
__future__r   r   labelsr   VERSIONr   r   r   r   r#   objectr   r=   r;   r<   r   r2   r
   rF   rB   rP   rO   rA   rN   r/   r   r   <module>rd      s    ( ' ' ' ' '        
 !$	  	8 8 84  <  $+ + + + +v + + +0 vg6*6*B B B B,     G G G G   8  @ !%X 1 1 1 1   0% 0% 0% 0% 0% 0% 0% 0%fL L L L L L L L L Lr   