o
    DDi                  	   @   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	m
Z
 dZeddG dd	 d	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eddG dd dZdedefddZd dee defddZdS )!    N)literal_eval)	dataclass)OptionalSequenceTupleUnion)   u    u    T)frozenc                   @   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   S/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/_parser/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_lines1   s.   


r1   utf-8strictsourceencodingerrorsc                    sR   dt ttf f fdd}ttrS | }t|ts#|dd}||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'``.
    r   c                     sV   t d} | rdS td}|du r S |d}td|}|r)|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's   utf-8s   (?:[^\n]*\n){0,2}Nr   s   coding[=:]\s*([-\w.]+)r   )r   
startswithr)   matchgroupsearch)	byte_markfirst_two_matchfirst_two_linespossible_encodingr5   r4   r   r   detect_encodingi   s   


z0python_bytes_to_unicode.<locals>.detect_encodingr2   replace)r   strbytes
isinstancedecode)r4   r5   r6   r@   actual_encodingr   r?   r   python_bytes_to_unicode]   s   

rG   c                   @   s   e Zd ZU eed< eed< ded eeef f defddZded eeef f defddZ	ded eeef f defd	d
Z
ded eeef f defddZded eeef f defddZded eeef f defddZdefddZdS )PythonVersionInfor   r   otherr   c                 C   sF   t |trt|dkrtd| j| jf|kS | j| jf|j|jfkS N   z'Can only compare to tuples of length 2.rD   tuplelen
ValueErrorr   r   selfrI   r   r   r   __gt__   
   
zPythonVersionInfo.__gt__c                 C      |  |p	| |S N)rR   __eq__rP   r   r   r   __ge__      zPythonVersionInfo.__ge__c                 C   sF   t |trt|dkrtd| j| jf|k S | j| jf|j|jfk S rJ   rL   rP   r   r   r   __lt__   rS   zPythonVersionInfo.__lt__c                 C   rT   rU   )rY   rV   rP   r   r   r   __le__   rX   zPythonVersionInfo.__le__c                 C   sF   t |trt|dkrtd| j| jf|kS | j| jf|j|jfkS rJ   rL   rP   r   r   r   rV      rS   zPythonVersionInfo.__eq__c                 C   s   |  | S rU   )rV   rP   r   r   r   __ne__   s   zPythonVersionInfo.__ne__c                 C   s   t | j| jfS rU   )hashr   r   )rQ   r   r   r   __hash__   s   zPythonVersionInfo.__hash__N)r   r   r   r   r   r   r   boolrR   rW   rY   rZ   rV   r[   r]   r   r   r   r   rH      s   
 """"""rH   versionc                 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+)(?:\.\d+)?)?$zNThe given version is not in the right format. Use something like "3.2" or "3".r   rK   7   6z7Sorry, no support yet for those fancy new/old versions.)r)   r8   rO   r   r9   NotImplementedErrorrH   )r_   r8   r   r   r   r   r   _parse_version   s"   

rd   c                 C   s"   | du rdt jd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.%srK   )sysversion_inford   )r_   r   r   r   parse_version_string   s   rg   )F)r2   r3   rU   )r)   re   astr   dataclassesr   typingr   r   r   r   r%   r   rB   r^   r1   rC   rG   rH   rd   rg   r   r   r   r   <module>   s.   -

/)