o
    !§ÑhS)  ã                   @   sæ   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d„ Z	dd„ Z
dd„ ZG dd„ deƒZe
dƒZe
dƒZe
dƒZd+dd„Zdd„ Zedfdd„Zd+dd „Zd!d"„ Zedfd#d$„Zd%d&„ ZG d'd(„ d(eƒZG d)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                 C   s   |   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)Ústring© r   úC/usr/lib/python3/dist-packages/pip/_vendor/webencodings/__init__.pyÚascii_lower#   s   r   c                 C   sx   t |  d¡ƒ} t | ¡}|du rdS t |¡}|du r:|dkr&ddlm} nt ||¡}t 	|¡}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_namer   r   r   r   =   s   



r   c                 C   s.   t | dƒr| S t| ƒ}|du rtd|  ƒ‚|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   r   r   r   Ú_get_encoding[   s   
	r   c                   @   s    e Zd ZdZdd„ Zd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                 C   s   || _ || _d S ©N)r   r   )Úselfr   r   r   r   r   Ú__init__|   s   
zEncoding.__init__c                 C   s
   d| j  S )Nz<Encoding %s>)r   )r!   r   r   r   Ú__repr__€   s   
zEncoding.__repr__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   r#   r   r   r   r   r   m   s    r   zutf-8zutf-16lezutf-16beÚreplacec                 C   s2   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   r   r   r   r
   ‹   s   r
   c                 C   sV   |   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)r*   r   r   r   r)   ¡   s   


r)   Ústrictc                 C   s   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   )r*   r   r,   r   r   r   r   ¬   s   r   c                 C   s$   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)r*   r+   r,   ÚdecoderÚ	generatorr   r   r   r   Úiter_decodeº   s   

r:   c                 c   s°   � |j }t| ƒ} | D ]}||ƒ}|r"|jdusJ ‚|jV  |V   nq
|ddd�}|jdus0J ‚|jV  |r9|V  dS | D ]}||ƒ}|rH|V  q=|ddd�}|rV|V  dS dS )zqReturn a generator that first yields the :obj:`Encoding`,
    then yields output chukns as Unicode strings.

    Nó    T©Úfinal)r
   Úiterr   )r*   r8   r
   ÚchunckÚoutputr   r   r   r6   Ö   s4   €ü€
ÿr6   c                 C   s   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)r*   r   r,   r   r   r   r   Úiter_encodeö   s   
rC   c                 c   s<   � | D ]}||ƒ}|r|V  q|ddd�}|r|V  d S d S )NÚ Tr<   r   )r*   r   r?   r@   r   r   r   rB     s   €€
ÿrB   c                   @   s$   e Zd ZdZd	dd„Zd
dd„ZdS )r5   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.

    r(   c                 C   s&   t |ƒ| _|| _d| _d | _d | _d S )Nr;   )r   Ú_fallback_encodingÚ_errorsÚ_bufferÚ_decoderr   )r!   r+   r,   r   r   r   r"     s
   

zIncrementalDecoder.__init__Fc                 C   s|   | j }|dur|||ƒS | j| }t|ƒ\}}|du r+t|ƒdk r(|s(|| _dS | j}|j | j¡j}|| _ || _	|||ƒS )zùDecode 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.

        Nr/   rD   )
rH   rG   r)   ÚlenrE   r   ÚincrementaldecoderrF   r
   r   )r!   r*   r=   r8   r   r   r   r   r
   '  s   



zIncrementalDecoder.decodeN©r(   )F)r$   r%   r&   r'   r"   r
   r   r   r   r   r5     s    

r5   c                   @   s   e Zd ZdZedfdd„ZdS )rA   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.

    r4   c                 C   s   t |ƒ}|j |¡j| _d S r    )r   r   Úincrementalencoderr   )r!   r   r,   r   r   r   r"   T  s   zIncrementalEncoder.__init__N)r$   r%   r&   r'   r3   r"   r   r   r   r   rA   C  s    rA   rK   )r'   Ú
__future__r   r   Úlabelsr   ÚVERSIONr   r   r   r   r   Úobjectr   r3   r1   r2   r
   r)   r   r:   r6   rC   rB   r5   rA   r   r   r   r   Ú<module>   s6   ü

 
3