U .eS)@sdZddlmZddlZddlmZdZddd d d ZiZd d Z ddZ ddZ Gddde Z e dZe dZe dZd+ddZddZedfddZd,dd Zd!d"Zedfd#d$Zd%d&ZGd'd(d(e ZGd)d*d*e ZdS)-a webencodings ~~~~~~~~~~~~ This is a Python implementation of the `WHATWG Encoding standard `. See README for details. :copyright: Copyright 2012 by Simon Sapin :license: BSD, see LICENSE for details. )unicode_literalsN)LABELSz0.5.1z iso-8859-8z mac-cyrillicz mac-romanZcp874)z iso-8859-8-izx-mac-cyrillic macintoshz windows-874cCs|ddS)a9Transform (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 `_ matching of encoding labels. The same matching is also used, among other things, for `CSS 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)encodelowerdecode)stringr E/usr/lib/python3.8/site-packages/pip/_vendor/webencodings/__init__.py ascii_lower#sr cCsxt|d}t|}|dkr$dSt|}|dkrt|dkrLddlm}nt||}t |}t ||}|t|<|S)u< Look for an encoding by its label. This is the spec’s `get an encoding `_ algorithm. Supported labels are listed there. :param label: A string. :returns: An :class:`Encoding` object, or :obj:`None` for an unknown label. z Nzx-user-definedr) codec_info) r striprgetCACHEZx_user_definedr PYTHON_NAMEScodecslookupEncoding)ZlabelnameencodingrZ python_namer r r r=s      rcCs.t|dr|St|}|dkr*td||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. rNzUnknown encoding label: %r)hasattrr LookupError)Zencoding_or_labelrr r r _get_encoding[s  rc@s eZdZdZddZddZdS)raOReresents 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`. cCs||_||_dSN)rr)selfrrr r r __init__|szEncoding.__init__cCs d|jS)Nz )r)rr r r __repr__szEncoding.__repr__N)__name__ __module__ __qualname____doc__rrr r r r rmsrzutf-8zutf-16lezutf-16bereplacecCs2t|}t|\}}|p|}|j||d|fS)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_bomrr )inputfallback_encodingerrorsZ bom_encodingrr r r r s r cCsV|drt|ddfS|dr4t|ddfS|drNt|ddfSd|fS)zBReturn (bom_encoding, input), with any BOM removed from the input.sNss) startswith_UTF16LE_UTF16BEUTF8)r%r r r r$s   r$strictcCst|j||dS)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)rrr)r%rr'r r r rs rcCs$t||}t||}t|}||fS)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_generatornext)r%r&r'decoder generatorrr r r iter_decodes  r4ccs|j}t|}|D]0}||}|r|jdk s0t|jV|Vqtq|ddd}|jdk s^t|jV|rp|VdS|D]}||}|rx|Vqx|ddd}|r|VdS)zqReturn a generator that first yields the :obj:`Encoding`, then yields output chukns as Unicode strings. NTfinal)r iterrAssertionError)r%r2r chunckoutputr r r r0s,  r0cCst||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%rr'rr r r iter_encodes r>ccs6|D]}||}|r|Vq|ddd}|r2|VdS)NTr6r )r%rr:r;r r r r=s r=c@s$eZdZdZd ddZd ddZdS) r/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#cCs&t||_||_d|_d|_d|_dS)Nr5)r_fallback_encoding_errors_buffer_decoderr)rr&r'r r r rs  zIncrementalDecoder.__init__FcCs||j}|dk r|||S|j|}t|\}}|dkrVt|dkrP|sP||_dS|j}|j|jj}||_||_ |||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. Nr)r?) rCrBr$lenr@rincrementaldecoderrAr r)rr%r7r2rr r r r 's    zIncrementalDecoder.decodeN)r#)F)rr r!r"rr r r r r r/s r/c@seZdZdZedfddZdS)r<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.cCst|}|j|j|_dSr)rrincrementalencoderr)rrr'r r r rTszIncrementalEncoder.__init__N)rr r!r"r-rr r r r r<Csr<)r#)r#)r"Z __future__rrlabelsrZVERSIONrrr rrobjectrr-r+r,r r$rr4r0r>r=r/r<r r r r s4       3