
    BhS)                        S r SSKJr  SSKrSSKJr  SrSSS	S
S.r0 rS r	S r
S r " S S\5      r\
" S5      r\
" S5      r\
" S5      rS S jrS r\S4S jrS S jrS r\S4S jrS r " S S\5      r " S S\5      rg)!z

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                 ^    U R                  S5      R                  5       R                  S5      $ )a  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    G/var/www/html/env/lib/python3.13/site-packages/webencodings/__init__.pyascii_lowerr   #   s'    . == &&(//77    c                 6   [        U R                  S5      5      n [        R                  " U 5      nUc  g[        R                  U5      nUcL  US:X  a  SSKJn  O+[        R                  X5      n[        R                  " U5      n[        X5      nU[        U'   U$ )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1E::eD|yyH##2&**46K{3JD-dOr   c                 d    [        U S5      (       a  U $ [        U 5      nUc  [        SU -  5      eU$ )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   zUnknown encoding label: %r)hasattrr   LookupError)encoding_or_labelr   s     r   _get_encodingr#   [   s@      ,//  '(H69JJKKOr   c                   $    \ rS rSrSrS rS rSrg)r   m   a/  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                     Xl         X l        g N)r   r   )selfr   r   s      r   __init__Encoding.__init__|   s    	$r   c                      SU R                   -  $ )Nz<Encoding %s>)r   )r(   s    r   __repr__Encoding.__repr__   s    **r   )r   r   N)__name__
__module____qualname____firstlineno____doc__r)   r,   __static_attributes__ r   r   r   r   m   s    %+r   r   zutf-8zutf-16lezutf-16bec                     [        U5      n[        U 5      u  p0U=(       d    UnUR                  R                  X5      S   U4$ )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      sI      &&78%e,L00H%%e4Q7AAr   c                     U R                  S5      (       a  [        U SS 4$ U R                  S5      (       a  [        U SS 4$ U R                  S5      (       a  [        U SS 4$ SU 4$ )zBReturn (bom_encoding, input), with any BOM removed from the input.s      Ns   s   ﻿   )
startswith_UTF16LE_UTF16BEUTF8)r7   s    r   r6   r6      sq    $$qr""$$qr""((U12Y;r   strictc                 P    [        U5      R                  R                  X5      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
   )r7   r   r9   s      r   r
   r
      s%     "--44UCAFFr   c                 J    [        X5      n[        X5      n[        U5      nXE4$ )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)r7   r8   r9   decoder	generatorr   s         r   iter_decoderJ      s+    , !!2;G&u6IIHr   c              #   r  #    UR                   n[        U 5      n U  H5  nU" U5      nU(       d  M  UR                  c   eUR                  v   Uv     O2   U" SSS9nUR                  c   eUR                  v   U(       a  Uv   gU  H  nU" U5      nU(       d  M  Uv   M     U" SSS9nU(       a  Uv   gg7f)ziReturn a generator that first yields the :obj:`Encoding`,
then yields output chukns as Unicode strings.

Nr   Tfinal)r   iterr   )r7   rH   r   chunckoutputs        r   rF   rF      s     
 ^^FKE6##///"""L  4(+++L6L  Ct$F s   *B7A'B7B7c                 B    [        X5      R                  n[        X5      $ )u=  
“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)r7   r   r9   r
   s       r   iter_encoderT      s      188F!%00r   c              #   n   #    U  H  nU" U5      nU(       d  M  Uv   M     U" SSS9nU(       a  Uv   g g 7f)N TrL   r4   )r7   r
   rO   rP   s       r   rS   rS     s=     6L  Bd#F s   55c                   ,    \ rS rSrSrSS jrSS jrSrg)	rE   i  u3  
“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.

c                 Z    [        U5      U l        X l        SU l        S U l        S U l        g )Nr   )r#   _fallback_encoding_errors_buffer_decoderr   )r(   r8   r9   s      r   r)   IncrementalDecoder.__init__  s,    "/0A"B
 r   c                 F   U R                   nUb  U" X5      $ U R                  U-   n[        U5      u  pAUc)  [        U5      S:  a  U(       d  Xl        gU R                  nUR
                  R                  U R                  5      R                  nX0l         X@l	        U" X5      $ )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.

r=   rV   )
r\   r[   r6   lenrY   r   incrementaldecoderrZ   r   r   )r(   r7   rM   rH   r   s        r   r   IncrementalDecoder.decode'  s     --5((u$%e,5zA~e$22%%88FMM u$$r   )r[   r\   rZ   rY   r   Nreplace)F)r.   r/   r0   r1   r2   r)   r   r3   r4   r   r   rE   rE     s    	
%r   rE   c                   &    \ rS rSrSr\S4S jrSrg)rR   iC  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.

rB   c                 n    [        U5      nUR                  R                  U5      R                  U l        g r'   )r#   r   incrementalencoderr
   )r(   r   r9   s      r   r)   IncrementalEncoder.__init__T  s*     *))<<VDKKr   )r
   N)r.   r/   r0   r1   r2   rA   r)   r3   r4   r   r   rR   rR   C  s      !%X Lr   rR   rb   )r2   
__future__r   r   labelsr   VERSIONr   r   r   r   r#   objectr   rA   r?   r@   r   r6   r
   rJ   rF   rT   rS   rE   rR   r4   r   r   <module>rl      s    (   
 !$	 	84<$+v +0 g**B,   G8@ !%X 1 0% 0%fL Lr   