o
    DDiB                     @   sd  U d 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	 ddl
mZ ddlmZmZ dd	lmZmZ dd
lmZmZ ddlmZ ddlmZ e Zeed< defddZdedeeef dedededefddZdedeeef dedededefddZ efdeeef dedefddZ!efdededeeef fddZ"efdedede	fddZ#dS ) z
Parser entrypoints define the way users of our API are allowed to interact with the
parser. A parser entrypoint should take the source code and some configuration
information
    Npartial)Union)CSTNode)BaseExpression)Module)BaseCompoundStatementSimpleStatementLine)convert_to_utf8detect_config)get_grammarvalidate_grammar)PythonCSTParser)PartialParserConfig_DEFAULT_PARTIAL_PARSER_CONFIGreturnc                  C   s   t jd} | dkS )NLIBCST_PARSER_TYPEpure)osenvironget)typ r   S/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/_parser/entrypoints.py	is_native   s   r   
entrypointsourceconfigdetect_trailing_newlinedetect_default_newlinec                C   s   t  r>ddlm}m}m} t||d\}}	| dkr#t||d}
|
|	S | dkr-|}
|
|	S | dkr7|}
|
|	S td|  t| ||||d	S )
Nr   )parse_expressionparse_moduleparse_statementr   
file_input)encoding
stmt_inputexpression_inputzUnknown parser entry point: r   r   )	r   libcst.nativer    r!   r"   r
   r   
ValueError_pure_python_parse)r   r   r   r   r   r    r!   r"   r$   
source_strparser   r   r   _parse!   s(   r-   c          	      C   sR   t ||||d}t  t|j|j}t|j|j|| d}| }t	|t
s'J |S )N)r   r   r   )tokensr   pgen_grammarstart_nonterminal)r   r   r   parsed_python_versionfuture_importsr   r.   r   r,   
isinstancer   )	r   r   r   r   r   detection_resultgrammarparserresultr   r   r   r*   A   s"   r*   c                 C   $   t d| |ddd}t|tsJ |S )aI  
    Accepts an entire python module, including all leading and trailing whitespace.

    If source is ``bytes``, the encoding will be inferred and preserved. If
    the source is a ``string``, we will default to assuming UTF-8 encoding if the
    module is rendered back out to source as bytes. It is recommended that when
    calling :func:`~libcst.parse_module` with a string you access the serialized
    code using :class:`~libcst.Module`'s code attribute, and when calling it with
    bytes you access the serialized code using :class:`~libcst.Module`'s bytes
    attribute.
    r#   Tr'   )r-   r3   r   r   r   r7   r   r   r   r!   ^   s   r!   c                 C   s(   t d| |ddd}t|ttfsJ |S )aM  
    Accepts a statement followed by a trailing newline. If a trailing newline is not
    provided, one will be added. :func:`parse_statement` is provided mainly as a
    convenience function to generate semi-complex trees from code snippetes. If you
    need to represent a statement exactly, including all leading/trailing comments,
    you should instead use :func:`parse_module`.

    Leading comments and trailing comments (on the same line) are accepted, but
    whitespace (or anything else) after the statement's trailing newline is not valid
    (there's nowhere to store it on the statement node). Note that since there is
    nowhere to store leading and trailing comments/empty lines, code rendered out
    from a parsed statement using ``cst.Module([]).code_for_node(statement)`` will
    not include leading/trailing comments.
    r%   TFr'   )r-   r3   r	   r   r9   r   r   r   r"   x   s   r"   c                 C   r8   )a  
    Accepts an expression on a single line. Leading and trailing whitespace is not
    valid (there's nowhere to store it on the expression node).
    :func:`parse_expression` is provided mainly as a convenience function to generate
    semi-complex trees from code snippets. If you need to represent an expression
    exactly, including all leading/trailing comments, you should instead use
    :func:`parse_module`.
    r&   Fr'   )r-   r3   r   r9   r   r   r   r       s   r    )$__doc__r   	functoolsr   typingr   libcst._nodes.baser   libcst._nodes.expressionr   libcst._nodes.moduler   libcst._nodes.statementr   r	   libcst._parser.detect_configr
   r   libcst._parser.grammarr   r   libcst._parser.python_parserr   libcst._parser.types.configr   r   __annotations__boolr   strbytesr-   r*   r!   r"   r    r   r   r   r   <module>   s   

 





