abc@s6dZddlmZddlZddlmZdZidd6d d 6d d 6d d6ZiZdZ dZ dZ de fdYZ e dZe dZe dZddZdZeddZddZdZeddZdZd e fd!YZd"e fd#YZdS($u 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. i(tunicode_literalsNi(tLABELSu0.5u iso-8859-8u iso-8859-8-iu mac-cyrillicux-mac-cyrillicu mac-romanu macintoshucp874u windows-874cCs|jdjjdS(u9Transform (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' uutf8(tencodetlowertdecode(tstring((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyt ascii_lower#scCst|jd}tj|}|dkr4dStj|}|dkr|dkrnddlm}n!tj||}t j |}t ||}|t|`_ algorithm. Supported labels are listed there. :param label: A string. :returns: An :class:`Encoding` object, or :obj:`None` for an unknown label. u ux-user-definedi(t codec_infoN( RtstripRtgettNonetCACHEtx_user_definedRt PYTHON_NAMEStcodecstlookuptEncoding(tlabeltnametencodingRt python_name((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyR=s     cCsBt|dr|St|}|dkr>td|n|S(u 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. u codec_infouUnknown encoding label: %rN(thasattrRR t LookupError(tencoding_or_labelR((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyt _get_encoding[s   RcBs eZdZdZdZRS(uOReresents 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||_||_dS(N(RR(tselfRR((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyt__init__|s cCs d|jS(Nu (R(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyt__repr__s(t__name__t __module__t__doc__RR(((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyRms uutf-8uutf-16leuutf-16beureplacecCsGt|}t|\}}|p'|}|jj||d|fS(u 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`. i(Rt _detect_bomRR(tinputtfallback_encodingterrorst bom_encodingR((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyRs  cCsa|jdrt|dfS|jdr:t|dfS|jdrWt|dfSd|fS(uBReturn (bom_encoding, input), with any BOM removed from the input.sissiN(t startswitht_UTF16LEt_UTF16BEtUTF8R (R ((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyRsustrictcCst|jj||dS(u; 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. i(RRR(R RR"((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyRs cCs4t||}t||}t|}||fS(u "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. (tIncrementalDecodert_iter_decode_generatortnext(R R!R"tdecodert generatorR((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyt iter_decodes ccs|j}t|}x]|D])}||}|r|jV|VPqqW|ddt}|jV|rq|VndSx(|D] }||}|r||Vq|q|W|ddt}|r|VndS(uqReturn a generator that first yields the :obj:`Encoding`, then yields output chukns as Unicode strings. ttfinalN(RtiterRtTrue(R R+Rtchuncktoutput((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyR)s(       cCst||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. (tIncrementalEncoderRt_iter_encode_generator(R RR"R((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyt iter_encodes ccsOx(|D] }||}|r|VqqW|ddt}|rK|VndS(NuR/(R1(R RR2R3((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyR5s   R(cBs&eZdZddZedZRS(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. ureplacecCs7t||_||_d|_d|_d|_dS(NR.(Rt_fallback_encodingt_errorst_bufferR t_decoderR(RR!R"((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyRs    cCs|j}|dk r"|||S|j|}t|\}}|dkrt|dkrs| rs||_dS|j}n|jj|jj }||_||_ |||S(uDecode 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. iuN( R:R R9RtlenR7RtincrementaldecoderR8RR(RR R/R+R((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyR's         (RRRRtFalseR(((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyR(s  R4cBseZdZeddZRS(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. ustrictcCs(t|}|jj|j|_dS(N(RRtincrementalencoderR(RRR"((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyRTs (RRRR'R(((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyR4Cs(Rt __future__RRtlabelsRtVERSIONR R RRRtobjectRR'R%R&RRRR-R)R6R5R(R4(((sE/usr/lib/python2.7/site-packages/pip/_vendor/webencodings/__init__.pyt s4             3