o
    DDif                  
   @   s  U d dl Z d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZmZmZmZmZmZ d dlmZ d dlmZmZ d dlmZ d d	lmZmZmZ d d
lmZ d dlmZ ej Z!ee"d< ej#Z$ee"d< ej%Z&ee"d< ej'Z(ee"d< dZ)dZ*e+dej,Z-ee. e"d< eddG dd dZ/dee.e0f de.fddZ1de.de.fddZ2dee de.fd d!Z3de.de4fd"d#Z5dee de
e. fd$d%Z6dee.e0f d&edee.e.f fd'd(Z7dee.e0f d&ed)e4d*e4de/f
d+d,Z8dS )-    N)	dataclass)BytesIO)detect_encoding)	FrozenSetIterableIteratorPatternSetTupleUnion)
NEWLINE_RE)PythonTokenTypes	TokenType)split_lines)
AutoConfigParserConfigPartialParserConfig)Token)tokenize_lines_INDENT_NAME_NEWLINE_STRING
z    z\\(\r\n?|\n)_CONTINUATION_RET)frozenc                   @   s"   e Zd ZU eed< ee ed< dS )ConfigDetectionResultconfigtokensN)__name__
__module____qualname__r   __annotations__r   r    r#   r#   U/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/_parser/detect_config.pyr      s   
 r   sourcereturnc                 C   s    t | trdS tt| jd S )z
    Detects the encoding from the presence of a UTF-8 BOM or an encoding cookie as
    specified in PEP 263.

    If given a string (instead of bytes) the encoding is assumed to be utf-8.
    zutf-8r   )
isinstancestrpy_tokenize_detect_encodingr   readline)r%   r#   r#   r$   _detect_encoding'   s   
r+   
source_strc                 C   s    t | }|dur|dS tS )zN
    Finds the first newline, and uses that value as the default newline.
    Nr   )r   searchgroup_FALLBACK_DEFAULT_NEWLINE)r,   matchr#   r#   r$   _detect_default_newline4   s   
r1   r   c                 C   sH   zt dd | D }W n ty   t Y S w |j}|dus"J d|S )zY
    Finds the first INDENT token, and uses that as the value of the default indent.
    c                 s   s    | ]
}|j tu r|V  qd S )N)typer   ).0tr#   r#   r$   	<genexpr>C   s    z!_detect_indent.<locals>.<genexpr>Nz,INDENT tokens must contain a relative_indent)nextStopIteration_FALLBACK_DEFAULT_INDENTrelative_indent)r   first_indentfirst_indent_strr#   r#   r$   _detect_indent>   s   r<   c                 C   sD   t | dkst| d sdS t| dd  p t| dd   S )Nr   F)lenr   	fullmatchr   )r,   r#   r#   r$   _detect_trailing_newlineK   s
   rB   c                 C   s   t  }d}| D ]t}|dkr|jttfv rq|dkr!|jdkr!d}q|dkr-|jdkr-d}q|dkr9|jdkr9d}q|dkrE|jdkrEd	}q|dkrU|jtkrU||j q|d	kra|jtkrad}q|dkrk|jd
v rkq|dkrw|jtkrwd}q t|S t|S )zs
    Finds __future__ imports in their proper locations.

    See `https://www.python.org/dev/peps/pep-0236/`_
    r   from   
__future__   import   as   z(),)setr2   r   r   stringr   add	frozenset)r   future_importsstatetokr#   r#   r$   _detect_future_importsU   s.   rR   partialc                C   s<   |j }t|trt| n|}t| tr| n| |}||fS )zA
    Returns an (original encoding, converted source) tuple.
    )encodingr'   r   r+   r(   decode)r%   rS   partial_encodingrT   r,   r#   r#   r$   convert_to_utf8u   s   
rW   detect_trailing_newlinedetect_default_newlinec             
   C   s   |j }t| |d\}}|j}t|tr|rt|ntn|}|o"t|}	|r+|	s+||7 }t|dd}
t	||
|}|j
}t|trKt|\}}t|}n|}|j}t|trat|\}}t|}n|}tt|
||||	||d|dS )zf
    Computes a ParserConfig given the current source code to be parsed and a partial
    config.
    )rS   T)keepends)linesrT   default_indentdefault_newlinehas_trailing_newlineversionrO   )r   r   )parsed_python_versionrW   r]   r'   r   r1   r/   rB   r   r   r\   	itertoolsteer<   rO   rR   r   r   )r%   rS   rX   rY   python_versionrT   r,   partial_default_newliner]   r^   r[   r   partial_default_indent
tokens_dupr\   partial_future_importsrO   r#   r#   r$   detect_config   sN   




	rh   )9ra   redataclassesr   ior   tokenizer   r)   typingr   r   r   r   r	   r
   r   libcst._nodes.whitespacer   !libcst._parser.parso.python.tokenr   r   libcst._parser.parso.utilsr   libcst._parser.types.configr   r   r   libcst._parser.types.tokenr   libcst._parser.wrapped_tokenizer   INDENTr   r"   NAMEr   NEWLINEr   STRINGr   r/   r8   compileUNICODEr   r(   r   bytesr+   r1   r<   boolrB   rR   rW   rh   r#   r#   r#   r$   <module>   sX   
$

 



