ó
MšV]c           @   sÅ   d  d l  m Z d  d l Z d  d l Z d  d l m Z d  d l m Z m Z d Z	 e d d ƒ Z
 e d „ Z d d d „ Z d „  Z d „  Z e d e d d ƒ f d „  ƒ  Yƒ Z d d „ Z d S(   iÿÿÿÿ(   t
   namedtupleN(   t   literal_eval(   t   unicodet   total_orderingu   u   u   u   u   u   Â…u   â€¨u   â€©t   Versions   major, minor, microc         C   s  | r|  j  t ƒ } g  } xX t | ƒ D]J \ } } y | d } Wn t k
 rU q( X| t k r( | j | ƒ q( q( WxQ t | ƒ D]C } y) | | | | d | | <| | d =Wqƒ t k
 rÅ qƒ Xqƒ W|  j d ƒ sô |  j d ƒ sô |  d k r| j d ƒ n  | St j	 d |  ƒ Sd S(   s¯  
    Intended for Python code. In contrast to Python's :py:meth:`str.splitlines`,
    looks at form feeds and other special characters as normal text. Just
    splits ``\n`` and ``\r\n``.
    Also different: Returns ``[""]`` for an empty string input.

    In Python 2.7 form feeds are used as normal characters when using
    str.splitlines. However in Python 3 somewhere there was a decision to split
    also on form feeds.
    iÿÿÿÿi   s   
s   t    s
   \n|\r\n|\rN(
   t
   splitlinest   Truet	   enumeratet
   IndexErrort   _NON_LINE_BREAKSt   appendt   reversedt   endswitht   ret   split(   t   stringt   keependst   lstt   merget   it   linet   last_chrt   index(    (    s*   lib/python2.7/site-packages/parso/utils.pyt   split_lines   s(    *s   utf-8t   strictc            sb   ‡  ‡ f d †  } t  ˆ t ƒ r% ˆ S| ƒ  ‰  t  ˆ  t ƒ sR t ˆ  d d ƒ ‰  n  t ˆ ˆ  | ƒ S(   sM  
    Checks for unicode BOMs and PEP 263 encoding declarations. Then returns a
    unicode object like in :py:meth:`bytes.decode`.

    :param encoding: See :py:meth:`bytes.decode` documentation.
    :param errors: See :py:meth:`bytes.decode` documentation. ``errors`` can be
        ``'strict'``, ``'replace'`` or ``'ignore'``.
    c             sg   t  d ƒ }  ˆ j |  ƒ r d St j d ˆ ƒ j d ƒ } t j d | ƒ } | r_ | j d ƒ Sˆ  Sd S(   sà   
        For the implementation of encoding definitions in Python, look at:
        - http://www.python.org/dev/peps/pep-0263/
        - http://docs.python.org/2/reference/lexical_analysis.html#encoding-declarations
        s   b'\xef\xbb\xbf's   utf-8s   (?:[^\n]*\n){0,2}i    s   coding[=:]\s*([-\w.]+)i   N(   R   t
   startswithR   t   matcht   groupt   search(   t	   byte_markt   first_two_linest   possible_encoding(   t   encodingt   source(    s*   lib/python2.7/site-packages/parso/utils.pyt   detect_encodingO   s    		s   utf-8t   replace(   t
   isinstanceR   (   R"   R!   t   errorsR#   (    (   R!   R"   s*   lib/python2.7/site-packages/parso/utils.pyt   python_bytes_to_unicodeF   s    		c          C   sc   d d l  m }  t j d |  ƒ } t g  t | ƒ D]* \ } } | d k rP | n	 t | ƒ ^ q2 Œ  S(   s`   
    Returns a namedtuple of parso's version, similar to Python's
    ``sys.version_info``.
    iÿÿÿÿ(   t   __version__s
   [a-z]+|\d+i   (   t   parsoR(   R   t   findallR   R   t   int(   R(   t   tuplR   t   x(    (    s*   lib/python2.7/site-packages/parso/utils.pyt   version_infoo   s    c         C   s¯   t  j d |  ƒ } | d  k r- t d ƒ ‚ n  t | j d ƒ ƒ } | j d ƒ } | d  k r– | d k rr d } q– | d k r‡ d } q– t d ƒ ‚ n  t | ƒ } t | | ƒ S(	   Ns   (\d+)(?:\.(\d)(?:\.\d+)?)?$sN   The given version is not in the right format. Use something like "3.2" or "3".i   i   t   7i   t   6s7   Sorry, no support yet for those fancy new/old versions.(   R   R   t   Nonet
   ValueErrorR+   R   t   NotImplementedErrort   PythonVersionInfo(   t   versionR   t   majort   minor(    (    s*   lib/python2.7/site-packages/parso/utils.pyt   _parse_versiony   s    		R4   s   major, minorc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   sl   t  | t ƒ rF t | ƒ d k r0 t d ƒ ‚ n  |  j |  j f | k St t |  ƒ j | ƒ |  j |  j f S(   Ni   s'   Can only compare to tuples of length 2.(	   R%   t   tuplet   lenR2   R6   R7   t   superR4   t   __gt__(   t   selft   other(    (    s*   lib/python2.7/site-packages/parso/utils.pyR<      s    c         C   s`   t  | t ƒ rF t | ƒ d k r0 t d ƒ ‚ n  |  j |  j f | k St t |  ƒ j | ƒ d  S(   Ni   s'   Can only compare to tuples of length 2.(	   R%   R9   R:   R2   R6   R7   R;   R4   t   __eq__(   R=   R>   (    (    s*   lib/python2.7/site-packages/parso/utils.pyR?   ™   s
    c         C   s   |  j  | ƒ S(   N(   R?   (   R=   R>   (    (    s*   lib/python2.7/site-packages/parso/utils.pyt   __ne__    s    (   t   __name__t
   __module__R<   R?   R@   (    (    (    s*   lib/python2.7/site-packages/parso/utils.pyR4   Ž   s   			c         C   sN   |  d k r  d t j d  }  n  t |  t t f ƒ sD t d ƒ ‚ n  t |  ƒ S(   sª   
    Checks for a valid version number (e.g. `3.2` or `2.7.1` or `3`) and
    returns a corresponding version info that is always two characters long in
    decimal.
    s   %s.%si   s"   version must be a string like 3.2.N(   R1   t   sysR.   R%   R   t   strt	   TypeErrorR8   (   R5   (    (    s*   lib/python2.7/site-packages/parso/utils.pyt   parse_version_string¤   s
    (   u   u   u   u   u   u   Â…u   â€¨u   â€©(   t   collectionsR    R   RC   t   astR   t   parso._compatibilityR   R   R
   R   t   FalseR   R'   R.   R8   R4   R1   RF   (    (    (    s*   lib/python2.7/site-packages/parso/utils.pyt   <module>   s(          ,)	
	