B
    t\                 @   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
dd	d
ZdddZdd Zdd ZeG dd deddZdddZdS )    )
namedtupleN)literal_eval)unicodetotal_ordering)   u    u    Versionzmajor, minor, microFc          	   C   s   |r|  d}g }xHt|D ]<\}}y|d }W n tk
rD   Y qX |tkr|| qW xLt|D ]@}y&|| ||d   ||< ||d = W qf tk
r   Y qfX qfW | ds| ds| dkr|d |S td| S dS )	a  
    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.
    T   
 z
\n|\r\n|\rN)	
splitlines	enumerate
IndexError_NON_LINE_BREAKSappendreversedendswithresplit)stringkeependsZlstmergeilineZlast_chrindex r!   *lib/python3.7/site-packages/parso/utils.pysplit_lines   s(    


r#   utf-8strictc                sD    fdd}t trS |  t  ts8t dd t |S )aM  
    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                 sJ   t d} | rdS tdd}td|}|rB|dS  S dS )z
        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
        zb'\xef\xbb\xbf'zutf-8s   (?:[^\n]*\n){0,2}r   s   coding[=:]\s*([-\w.]+)r   N)r   
startswithr   matchgroupsearch)Z	byte_markZfirst_two_linesZpossible_encoding)encodingsourcer!   r"   detect_encodingO   s    

z0python_bytes_to_unicode.<locals>.detect_encodingzutf-8replace)
isinstancer   )r+   r*   errorsr,   r!   )r*   r+   r"   python_bytes_to_unicodeF   s    	

r0   c              C   s.   ddl m}  td| }tdd t|D  S )z`
    Returns a namedtuple of parso's version, similar to Python's
    ``sys.version_info``.
    r   )__version__z
[a-z]+|\d+c             S   s$   g | ]\}}|d kr|nt |qS )   )int).0r   xr!   r!   r"   
<listcomp>v   s    z version_info.<locals>.<listcomp>)Zparsor1   r   findallr   r   )r1   Ztuplr!   r!   r"   version_infoo   s    r8   c             C   sr   t d| }|d krtdt|d}|d}|d kr`|dkrJd}n|dkrXd}ntdt|}t||S )	Nz(\d+)(?:\.(\d)(?:\.\d+)?)?$zNThe given version is not in the right format. Use something like "3.2" or "3".r      7r2   6z7Sorry, no support yet for those fancy new/old versions.)r   r'   
ValueErrorr3   r(   NotImplementedErrorPythonVersionInfo)versionr'   majorminorr!   r!   r"   _parse_versiony   s    
rB   c                   s0   e Zd Z fddZ fddZdd Z  ZS )r>   c                sJ   t |tr.t|dkrtd| j| jf|kS tt| | | j| jfS )Nr9   z'Can only compare to tuples of length 2.)	r.   tuplelenr<   r@   rA   superr>   __gt__)selfother)	__class__r!   r"   rF      s    
zPythonVersionInfo.__gt__c                sB   t |tr.t|dkrtd| j| jf|kS tt| | d S )Nr9   z'Can only compare to tuples of length 2.)	r.   rC   rD   r<   r@   rA   rE   r>   __eq__)rG   rH   )rI   r!   r"   rJ      s
    
zPythonVersionInfo.__eq__c             C   s   |  | S )N)rJ   )rG   rH   r!   r!   r"   __ne__   s    zPythonVersionInfo.__ne__)__name__
__module____qualname__rF   rJ   rK   __classcell__r!   r!   )rI   r"   r>      s   	r>   zmajor, minorc             C   s8   | dkrdt jdd  } t| ttfs0tdt| S )z
    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.
    Nz%s.%sr9   z"version must be a string like 3.2.)sysr8   r.   r   str	TypeErrorrB   )r?   r!   r!   r"   parse_version_string   s
    rS   )F)r$   r%   )N)collectionsr   r   rP   Zastr   Zparso._compatibilityr   r   r   r   r#   r0   r8   rB   r>   rS   r!   r!   r!   r"   <module>   s   

,
)
