
    ړi              	           d dl Z d dlZd dlmZ d dlmZ d dlmZmZ dZ	 G d de      Z
dded	ed
dfdZ	 ddeeef   deded
efdZd
e
fdZ G d de      Ze G d de             Zd
efdZdded
efdZy)    N)literal_eval)total_ordering)
NamedTupleUnion)   u    u    c                   ,    e Zd ZU eed<   eed<   eed<   y)VersionmajorminormicroN__name__
__module____qualname__int__annotations__     2/tmp/pip-target-20744g9h/lib/python/parso/utils.pyr   r      s    JJJr   r   stringkeependsreturnz	list[str]c                    |r| j                  d      }g }t        |      D ]%  \  }}	 |d   }|t        v s|j                  |       ' t        |      D ]  }	 ||   ||dz      z   ||<   ||dz   =  | j                  d      s| j                  d      s| dk(  r|j                  d       |S t        j                  d|       S # t        $ r Y w xY w# t        $ r Y w xY w)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|\r)	
splitlines	enumerate_NON_LINE_BREAKSappend
IndexErrorreversedendswithresplit)r   r   lstmergeilinelast_chrindexs           r   split_linesr3      s    %  ~ 	$GAt$8 //LLO	$ e_ 	E Z#eai.8E
	N	 ??4 FOOD$9Vr\JJrN
xxv..-     s#   CC	CC	CCsourceencodingerrorsc                       fd}t         t              r S  |       	 t         |      S # t        $ r |dk(  rt         d|      cY S  w xY w)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                     t        d      } j                  |       ryt        j                  d      j	                  d      }t        j
                  d|      }|r0|j	                  d      }t        |t              st        |dd      }|S 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'utf-8s   (?:[^\r\n]*(?:\r\n|\r|\n)){0,2}r   s   coding[=:]\s*([-\w.]+)r    asciireplace)r   
startswithr+   matchgroupsearch
isinstancestr)	byte_markfirst_two_linespossible_encodinger5   r4   s       r   detect_encodingz0python_bytes_to_unicode.<locals>.detect_encodingT   s     !!34	Y'((#FOUUVWXII&@&57!''*Aa%7I.H Or   r;   r9   )r@   rA   LookupError)r4   r5   r6   rF   s   ``  r   python_bytes_to_unicoderH   I   s`    . &# H
68V,, Y
 vw//s   0 AAc            	          ddl m}  t        j                  d|       }t	        t        |      D cg c]  \  }}|dk(  r|n
t        |       c}} S c c}}w )z`
    Returns a namedtuple of parso's version, similar to Python's
    ``sys.version_info``.
    r   )__version__z
[a-z]+|\d+   )parsorJ   r+   findallr   r%   r   )rJ   tuplr/   xs       r   version_inforP   }   sG    
 "::m[1D4IA!q&Qc!f,IJJIs   A
c                   "    e Zd ZU eed<   eed<   y)_PythonVersionInfor   r   Nr   r   r   r   rR   rR      s    JJr   rR   c                   .     e Zd Z fdZ fdZd Z xZS )PythonVersionInfoc                     t        |t              r4t        |      dk7  rt        d      | j                  | j
                  f|kD  S t        |   |       | j                  | j
                  fS N   z'Can only compare to tuples of length 2.)r@   tuplelen
ValueErrorr   r   super__gt__selfother	__class__s     r   r\   zPythonVersionInfo.__gt__   s[    eU#5zQ !JKKJJ

+e33u

DJJ''r   c                     t        |t              r4t        |      dk7  rt        d      | j                  | j
                  f|k(  S t        |   |       y rV   )r@   rX   rY   rZ   r   r   r[   __eq__r]   s     r   rb   zPythonVersionInfo.__eq__   sH    eU#5zQ !JKKJJ

+u44ur   c                 &    | j                  |       S N)rb   )r^   r_   s     r   __ne__zPythonVersionInfo.__ne__   s    ;;u%%%r   )r   r   r   r\   rb   re   __classcell__)r`   s   @r   rT   rT      s    (&r   rT   c                    t        j                  d|       }|t        d      t        |j	                  d            }|j	                  d      }||dk(  rd}n|dk(  rd}nt        d      t        |      }t        ||      S )	Nz-(\d+)(?:\.(\d{1,2})(?:\.\d+)?)?((a|b|rc)\d)?$zNThe given version is not in the right format. Use something like "3.8" or "3".r    rW   7rK   6z7Sorry, no support yet for those fancy new/old versions.)r+   r=   rZ   r   r>   NotImplementedErrorrT   )versionr=   r   r   s       r   _parse_versionrl      s    HHEwOE} < = 	= AEKKNE} A:EaZE%&_``JEUE**r   rk   c                 ~    | dt         j                  dd z  } t        | t              st	        d      t        |       S )z
    Checks for a valid version number (e.g. `3.8` or `3.10.1` or `3`) and
    returns a corresponding version info that is always two characters long in
    decimal.
    Nz%s.%srW   z#version must be a string like "3.8")sysrP   r@   rA   	TypeErrorrl   )rk   s    r   parse_version_stringrp      sA     C,,Ra00gs#=>>'""r   )F)r9   strictrd   )r+   rn   astr   	functoolsr   typingr   r   r&   r   rA   boolr3   bytesrH   rP   rR   rT   rl   rp   r   r   r   <module>rw      s    	 
  $ $

 j )/ )/t )/ )/Z GO1#u*1),1@C11hKg K 
 &* & &*+0 +*## #1B #r   