o
    5t¾i+  ã                   @   sn   d Z ddlZddlmZ ddlmZ ddlmZ G dd„ deƒZd	ed
dfdd„Z	dd	eded
efdd„Z
dS )zA
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
é    N)ÚPattern)ÚFinalé   )ÚVarNameSanitizerc                   @   s”   e Zd ZU g d¢Zeed< g d¢Zeed< e d¡Z	eed< e d¡Z
eed< ed	ee fd
d„ƒZed	ee fdd„ƒZed	ee fdd„ƒZdS )ÚPythonVarNameSanitizer)ÚandÚdelÚfromÚnotÚwhileÚasÚelifÚglobalÚorÚwithÚassertÚelseÚifÚpassÚyieldÚbreakÚexceptÚimportÚprintÚclassÚexecÚinÚraiseÚcontinueÚfinallyÚisÚreturnÚdefÚforÚlambdaÚtryÚ1_PythonVarNameSanitizer__PYTHON_RESERVED_KEYWORDS)ÚFalseÚTrueÚNoneÚNotImplementedÚEllipsisÚ	__debug__Ú1_PythonVarNameSanitizer__PYTHON_BUILTIN_CONSTANTSz[^a-zA-Z0-9_]Ú,_PythonVarNameSanitizer__RE_INVALID_VAR_NAMEz^[^a-zA-Z]+Ú1_PythonVarNameSanitizer__RE_INVALID_VAR_NAME_HEADr!   c                 C   s   | j | j S ©N)r&   r-   ©Úself© r3   úS/home/ubuntu/.local/lib/python3.10/site-packages/pytablewriter/sanitizer/_python.pyÚreserved_keywords:   s   z(PythonVarNameSanitizer.reserved_keywordsc                 C   ó   | j S r0   )r/   r1   r3   r3   r4   Ú_invalid_var_name_head_re>   ó   z0PythonVarNameSanitizer._invalid_var_name_head_rec                 C   r6   r0   )r.   r1   r3   r3   r4   Ú_invalid_var_name_reB   r8   z+PythonVarNameSanitizer._invalid_var_name_reN)Ú__name__Ú
__module__Ú__qualname__r&   r   Ú__annotations__r-   ÚreÚcompiler.   r/   ÚpropertyÚlistÚstrr5   r   r7   r9   r3   r3   r3   r4   r      s   
 !	r   Úvar_namer!   c                 C   s   t | ƒ ¡  dS )a™  
    :param str var_name: Name to validate.
    :raises pathvalidate.ValidationError (ErrorReason.INVALID_CHARACTER):
        If the ``var_name`` is invalid as
        `Python identifier
        <https://docs.python.org/3/reference/lexical_analysis.html#identifiers>`__.
    :raises pathvalidate.ValidationError (ErrorReason.RESERVED_NAME):
        If the ``var_name`` is equals to
        `Python reserved keywords
        <https://docs.python.org/3/reference/lexical_analysis.html#keywords>`__
        or
        `Python built-in constants
        <https://docs.python.org/3/library/constants.html>`__.

    :Example:
        :ref:`example-validate-var-name`
    N)r   Úvalidate)rC   r3   r3   r4   Úvalidate_python_var_nameG   s   rE   Ú Úreplacement_textc                 C   s   t | ƒ |¡S )aß  
    Make a valid Python variable name from ``var_name``.

    To make a valid name:

    - Replace invalid characters for a Python variable name within
      the ``var_name`` with the ``replacement_text``
    - Delete invalid chars for the beginning of the variable name
    - Append underscore (``"_"``) at the tail of the name if sanitized name
      is one of the Python reserved names

    :param str filename: Name to sanitize.
    :param str replacement_text: Replacement text.
    :return: A replacement string.
    :rtype: str
    :raises ValueError: If ``var_name`` or ``replacement_text`` is invalid.

    :Example:
        :ref:`example-sanitize-var-name`

    .. seealso::
        :py:func:`.validate_python_var_name`
    )r   Úsanitize)rC   rG   r3   r3   r4   Úsanitize_python_var_name]   s   rI   )rF   )Ú__doc__r>   r   Útypingr   Ú_baser   r   rB   rE   rI   r3   r3   r3   r4   Ú<module>   s    ;