ó
Ð²Ebc           @  s6  d  Z  d d l m Z d d l Z d d l m Z d Z i d d 6d	 d
 6d d 6d d 6Z i  Z d „  Z	 d „  Z
 d „  Z d e f d „  ƒ  YZ e
 d ƒ Z e
 d ƒ Z e
 d ƒ Z d d „ Z d „  Z e d d „ Z d d „ Z d „  Z e d d „ Z d „  Z d  e f d! „  ƒ  YZ d" e f d# „  ƒ  YZ d S($   u  

    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.

iÿÿÿÿ(   t   unicode_literalsNi   (   t   LABELSu   0.5.1u
   iso-8859-8u   iso-8859-8-iu   mac-cyrillicu   x-mac-cyrillicu	   mac-romanu	   macintoshu   cp874u   windows-874c         C  s   |  j  d ƒ j ƒ  j d ƒ S(   u9  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'

    u   utf8(   t   encodet   lowert   decode(   t   string(    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyt   ascii_lower#   s    c         C  s¯   t  |  j d ƒ ƒ }  t j |  ƒ } | d k r4 d St j | ƒ } | d k r« | d k rn d d l m } n! t j | | ƒ } t	 j
 | ƒ } t | | ƒ } | t | <n  | 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.

    u   	
 u   x-user-definedi   (   t
   codec_infoN(   R   t   stripR   t   gett   Nonet   CACHEt   x_user_definedR   t   PYTHON_NAMESt   codecst   lookupt   Encoding(   t   labelt   namet   encodingR   t   python_name(    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyR   =   s    c         C  sB   t  |  d ƒ r |  St |  ƒ } | d k r> t d |  ƒ ‚ 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_infou   Unknown encoding label: %rN(   t   hasattrR   R
   t   LookupError(   t   encoding_or_labelR   (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyt   _get_encoding[   s    	R   c           B  s    e  Z d  Z d „  Z d „  Z RS(   uO  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   (   t   selfR   R   (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyt   __init__|   s    	c         C  s   d |  j  S(   Nu   <Encoding %s>(   R   (   R   (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyt   __repr__€   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyR   m   s   	u   utf-8u   utf-16leu   utf-16beu   replacec         C  sG   t  | ƒ } t |  ƒ \ } }  | p' | } | j j |  | ƒ d | f S(   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    (   R   t   _detect_bomR   R   (   t   inputt   fallback_encodingt   errorst   bom_encodingR   (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyR   ‹   s    c         C  sa   |  j  d ƒ r t |  d f S|  j  d ƒ r: t |  d f S|  j  d ƒ rW t |  d f Sd |  f S(   uB   Return (bom_encoding, input), with any BOM removed from the input.s   ÿþi   s   þÿs   ï»¿i   N(   t
   startswitht   _UTF16LEt   _UTF16BEt   UTF8R
   (   R    (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyR   ¡   s    u   strictc         C  s   t  | ƒ j j |  | ƒ d S(   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    (   R   R   R   (   R    R   R"   (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyR   ¬   s    c         C  s4   t  | | ƒ } t |  | ƒ } t | ƒ } | | f S(   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.

    (   t   IncrementalDecodert   _iter_decode_generatort   next(   R    R!   R"   t   decodert	   generatorR   (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyt   iter_decodeº   s    c         c  sî   | j  } t |  ƒ }  x‡ |  D]> } | | ƒ } | r | j d k	 sI t ‚ | j V| VPq q W| d d t ƒ} | j d k	 s… t ‚ | j V| r› | Vn  d Sx( |  D]  } | | ƒ } | r¦ | Vq¦ q¦ W| d d t ƒ} | rê | Vn  d S(   uq   Return a generator that first yields the :obj:`Encoding`,
    then yields output chukns as Unicode strings.

    t    t   finalN(   R   t   iterR   R
   t   AssertionErrort   True(   R    R+   R   t   chunckt   output(    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyR)   Ö   s,    	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.

    (   t   IncrementalEncoderR   t   _iter_encode_generator(   R    R   R"   R   (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyt   iter_encodeö   s    c         c  sO   x( |  D]  } | | ƒ } | r | Vq q W| d d t  ƒ} | rK | Vn  d  S(   Nu    R/   (   R2   (   R    R   R3   R4   (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyR6     s    R(   c           B  s&   e  Z d  Z d d „ Z e d „ Z RS(   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.

    u   replacec         C  s7   t  | ƒ |  _ | |  _ d |  _ d  |  _ d  |  _ d  S(   NR.   (   R   t   _fallback_encodingt   _errorst   _bufferR
   t   _decoderR   (   R   R!   R"   (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyR     s
    			c         C  s¶   |  j  } | d k	 r" | | | ƒ S|  j | } t | ƒ \ } } | d k r t | ƒ d k  rs | rs | |  _ d S|  j } n  | j j |  j ƒ j	 } | |  _  | |  _
 | | | ƒ S(   uù   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.

        i   u    N(   R;   R
   R:   R   t   lenR8   R   t   incrementaldecoderR9   R   R   (   R   R    R/   R+   R   (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyR   '  s    
				(   R   R   R   R   t   FalseR   (    (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyR(     s   
R5   c           B  s   e  Z d  Z e d d „ Z RS(   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.

    u   strictc         C  s(   t  | ƒ } | j j | ƒ j |  _ d  S(   N(   R   R   t   incrementalencoderR   (   R   R   R"   (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyR   T  s    (   R   R   R   R'   R   (    (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyR5   C  s   (   R   t
   __future__R    R   t   labelsR   t   VERSIONR   R   R   R   R   t   objectR   R'   R%   R&   R   R   R   R-   R)   R7   R6   R(   R5   (    (    (    s>   /tmp/pip-build-UPPWic/pip/pip/_vendor/webencodings/__init__.pyt   <module>   s4   
					 	
3