zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
U
¬ý°duã@s¤dZddlmZddlmZddlmZddlZddlZddl    m
Z
m Z dZ ddd    œd
d „Z d d d œdd„Zddd    œdd„Zdddd dœdd„Zdddœdd„ZdS)z6
:func:`~pandas.eval` source string parsing functions
é)Ú annotations)ÚStringIO)Ú    iskeywordN)ÚHashableÚIteratorédÚstr)ÚnameÚreturnc s‚| ¡rt|ƒs|Sdd„tj ¡Dƒ‰ˆ ddddddd    d
d œ¡d  ‡fd d„|Dƒ¡}d|›}| ¡s~td|›dƒ‚|S)a=
    Create valid Python identifiers from any string.
 
    Check if name contains any special characters. If it contains any
    special characters, the special characters will be replaced by
    a special string and a prefix is added.
 
    Raises
    ------
    SyntaxError
        If the returned name is not a Python valid identifier, raise an exception.
        This can happen if there is a hashtag in the name, as the tokenizer will
        than terminate and not find the backtick.
        But also for characters that fall out of the range of (U+0001..U+007F).
    cSs$i|]\}}|dtj|›d“qS)Ú_)ÚtokenÚtok_name)Ú.0ÚcharÚtokval©rúVd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/computation/parsing.pyÚ
<dictcomp>)sÿz2create_valid_python_identifier.<locals>.<dictcomp>r Z_QUESTIONMARK_Z_EXCLAMATIONMARK_Z _DOLLARSIGN_Z
_EUROSIGN_Z _DEGREESIGN_Z _SINGLEQUOTE_Z _DOUBLEQUOTE_)ú ú?ú!ú$u€õ°ú'ú"Úcsg|]}ˆ ||¡‘qSr)Úget)rr©Zspecial_characters_replacementsrrÚ
<listcomp>=sz2create_valid_python_identifier.<locals>.<listcomp>ZBACKTICK_QUOTED_STRING_zCould not convert 'z' to a valid Python identifier.)Ú isidentifierrÚtokenizeÚEXACT_TOKEN_TYPESÚitemsÚupdateÚjoinÚ SyntaxError)r    rrrÚcreate_valid_python_identifiers*þ÷ÿ
r&ztuple[int, str])Útokr
cCs&|\}}|tkrtjt|ƒfS||fS)a[
    Clean up a column name if surrounded by backticks.
 
    Backtick quoted string are indicated by a certain tokval value. If a string
    is a backtick quoted token it will processed by
    :func:`_create_valid_python_identifier` so that the parser can find this
    string when the query is executed.
    In this case the tok will get the NAME tokval.
 
    Parameters
    ----------
    tok : tuple of int, str
        ints correspond to the all caps constants in the tokenize module
 
    Returns
    -------
    tok : Tuple[int, str]
        Either the input or token or the replacement values
    )ÚBACKTICK_QUOTED_STRINGr ÚNAMEr&)r'ÚtoknumrrrrÚclean_backtick_quoted_toksFsr+rcCsDz&td|›dƒ}t|ƒd}t|ƒWStk
r>|YSXdS)a¼
    Function to emulate the cleaning of a backtick quoted name.
 
    The purpose for this function is to see what happens to the name of
    identifier if it goes to the process of being parsed a Python code
    inside a backtick quoted string and than being cleaned
    (removed of any special characters).
 
    Parameters
    ----------
    name : hashable
        Name to be cleaned.
 
    Returns
    -------
    name : hashable
        Returns the name after tokenizing and cleaning.
 
    Notes
    -----
        For some cases, a name cannot be converted to a valid Python identifier.
        In that case :func:`tokenize_string` raises a SyntaxError.
        In that case, we just return the name unmodified.
 
        If this name was used in the query string (this makes the query call impossible)
        an error will be raised by :func:`tokenize_backtick_quoted_string` instead,
        which is not caught and propagates to the user level.
    ú`éN)Útokenize_stringÚnextr&r%)r    Z    tokenizedrrrrÚclean_column_name`s  
r0zIterator[tokenize.TokenInfo]Úint)Útoken_generatorÚsourceÚ string_startr
cCs8|D]"\}}}}}|dkr|d}q(qt|||…fS)a»
    Creates a token from a backtick quoted string.
 
    Moves the token_generator forwards till right after the next backtick.
 
    Parameters
    ----------
    token_generator : Iterator[tokenize.TokenInfo]
        The generator that yields the tokens of the source string (Tuple[int, str]).
        The generator is at the first token after the backtick (`)
 
    source : str
        The Python source code string.
 
    string_start : int
        This is the start of backtick quoted string inside the source string.
 
    Returns
    -------
    tok: Tuple[int, str]
        The token that represents the backtick quoted string.
        The integer is equal to BACKTICK_QUOTED_STRING (100).
    r,r-)r()r2r3r4r rÚstartZ
string_endrrrÚtokenize_backtick_quoted_string…s
r6zIterator[tuple[int, str]])r3r
c cs’t|ƒj}t |¡}|D]t\}}}}}|dkr‚zt|||dddVWqŒtk
r~}ztd|›dƒ|‚W5d}~XYqŒXq||fVqdS)a$
    Tokenize a Python source code string.
 
    Parameters
    ----------
    source : str
        The Python source code string.
 
    Returns
    -------
    tok_generator : Iterator[Tuple[int, str]]
        An iterator yielding all tokens with only toknum and tokval (Tuple[ing, str]).
    r,r-)r4zFailed to parse backticks in 'z'.N)rÚreadliner Úgenerate_tokensr6Ú    Exceptionr%)r3Z line_readerr2r*rr5r Úerrrrrr.§s
 
 
ÿ &r.)Ú__doc__Ú
__future__rÚiorÚkeywordrr r Útypingrrr(r&r+r0r6r.rrrrÚ<module>s   3%"