o
    ßË·eÜ  ã                	   @   sê   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m	Z	 dZ
G dd„ deƒZd d	ed
edee fdd„Z	d!de	eef dededefdd„Zdefdd„ZG dd„ deƒZeG dd„ deƒƒZdefdd„Zd"dedefdd„ZdS )#é    N)Úliteral_eval)Útotal_ordering)Ú
NamedTupleÚSequenceÚUnion)úúúúúõ   Â…u   â€¨u   â€©c                   @   s&   e Zd ZU eed< eed< eed< dS )ÚVersionÚmajorÚminorÚmicroN©Ú__name__Ú
__module__Ú__qualname__ÚintÚ__annotations__© r   r   úB/var/www/ideatree/venv/lib/python3.10/site-packages/parso/utils.pyr      s   
 r   FÚstringÚkeependsÚreturnc              	   C   sÒ   |rc|   d¡}g }t|ƒD ]\}}z|d }W n	 ty    Y qw |tv r*| |¡ qt|ƒD ]}z|| ||d   ||< ||d = W q/ tyM   Y q/w |  d¡s\|  d¡s\| dkra| d¡ |S t 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|\r)	Ú
splitlinesÚ	enumerateÚ
IndexErrorÚ_NON_LINE_BREAKSÚappendÚreversedÚendswithÚreÚsplit)r   r   ÚlstÚmergeÚiÚlineÚlast_chrÚindexr   r   r   Úsplit_lines   s.   
ÿ
€ý
r0   úutf-8ÚstrictÚsourceÚencodingÚerrorsc                    sZ   ‡ ‡fdd„}t ˆtƒrˆS |ƒ ‰ ztˆˆ |ƒW S  ty,   |dkr+tˆd|ƒ Y S ‚ 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                     s`   t dƒ} ˆ | ¡rdS t dˆ¡ d¡}t d|¡}|r.| 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'r1   s   (?:[^\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Úe©r4   r3   r   r   Údetect_encodingT   s   
ÿ

z0python_bytes_to_unicode.<locals>.detect_encodingr7   r1   )r<   r=   ÚLookupError)r3   r4   r5   rC   r   rB   r   Úpython_bytes_to_unicodeI   s   
ùrE   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 )é   )r   )Ú.0r,   Úxr   r   r   Ú
<listcomp>„   s   $ z version_info.<locals>.<listcomp>)ÚparsorF   r(   Úfindallr   r"   )rF   Útuplr   r   r   Úversion_info}   s   rN   c                   @   s   e Zd ZU eed< eed< dS )Ú_PythonVersionInfor   r   Nr   r   r   r   r   rO   ‡   s   
 rO   c                       s0   e Zd Z‡ fdd„Z‡ fdd„Zdd„ Z‡  ZS )ÚPythonVersionInfoc                    sF   t |tƒrt|ƒdkrtdƒ‚| j| jf|k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__r   r   rW   Ž   s   
zPythonVersionInfo.__gt__c                    s>   t |tƒrt|ƒdkrtdƒ‚| j| jf|kS tƒ  |¡ d S rQ   )r<   rS   rT   rU   r   r   rV   Ú__eq__rX   r[   r   r   r]   —   s
   
zPythonVersionInfo.__eq__c                 C   s   |   |¡ S ©N)r]   rX   r   r   r   Ú__ne__ž   s   zPythonVersionInfo.__ne__)r   r   r   rW   r]   r_   Ú__classcell__r   r   r[   r   rP   Œ   s    	rP   c                 C   sr   t  d| ¡}|d u rtdƒ‚t| d¡ƒ}| d¡}|d u r0|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   rR   Ú7rG   Ú6z7Sorry, no support yet for those fancy new/old versions.)r(   r9   rU   r   r:   ÚNotImplementedErrorrP   )Úversionr9   r   r   r   r   r   Ú_parse_version¢   s   

re   rd   c                 C   s4   | du rdt jdd…  } 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.%srR   z#version must be a string like "3.8")ÚsysrN   r<   r=   Ú	TypeErrorre   )rd   r   r   r   Úparse_version_string·   s
   
rh   )F)r1   r2   r^   )r(   rf   Úastr   Ú	functoolsr   Útypingr   r   r   r$   r   r=   Úboolr0   ÚbytesrE   rN   rO   rP   re   rh   r   r   r   r   Ú<module>   s0    -ÿ
ÿÿÿ
þ4
