o
    ™©ZhÜ  ã                	   @   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/html/lang_env/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ÚlineZlast_chrÚindexr   r   r   Úsplit_lines   s.   
ÿ
€ý
r/   ú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'r0   s   (?:[^\r\n]*(?:\r\n|\r|\n)){0,2}r   s   coding[=:]\s*([-\w.]+)r   ÚasciiÚreplace)r   Ú
startswithr(   ÚmatchÚgroupÚsearchÚ
isinstanceÚstr)Z	byte_markZfirst_two_linesZpossible_encodingÚe©r3   r2   r   r   Údetect_encodingT   s   
ÿ

z0python_bytes_to_unicode.<locals>.detect_encodingr6   r0   )r;   r<   ÚLookupError)r2   r3   r4   r?   r   r>   r   Úpython_bytes_to_unicodeI   s   
ùrA   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>)ZparsorB   r(   Úfindallr   r"   )rB   Ztuplr   r   r   Úversion_info}   s   rH   c                   @   s   e Zd ZU eed< eed< dS )Ú_PythonVersionInfor   r   Nr   r   r   r   r   rI   ‡   s   
 rI   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   rQ   Ž   s   
zPythonVersionInfo.__gt__c                    s>   t |tƒrt|ƒdkrtdƒ‚| j| jf|kS tƒ  |¡ d S rK   )r;   rM   rN   rO   r   r   rP   Ú__eq__rR   rU   r   r   rW   —   s
   
zPythonVersionInfo.__eq__c                 C   s   |   |¡ S ©N)rW   rR   r   r   r   Ú__ne__ž   s   zPythonVersionInfo.__ne__)r   r   r   rQ   rW   rY   Ú__classcell__r   r   rU   r   rJ   Œ   s    	rJ   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   rL   Ú7rC   Ú6z7Sorry, no support yet for those fancy new/old versions.)r(   r8   rO   r   r9   ÚNotImplementedErrorrJ   )Úversionr8   r   r   r   r   r   Ú_parse_version¢   s   

r_   r^   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.%srL   z#version must be a string like "3.8")ÚsysrH   r;   r<   Ú	TypeErrorr_   )r^   r   r   r   Úparse_version_string·   s
   
rb   )F)r0   r1   rX   )r(   r`   Úastr   Ú	functoolsr   Útypingr   r   r   r$   r   r<   Úboolr/   ÚbytesrA   rH   rI   rJ   r_   rb   r   r   r   r   Ú<module>   s0    -ÿ
ÿÿÿ
þ4
