forked from MarcoMuellner/openapi-python-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
57 lines (45 loc) · 1.43 KB
/
common.py
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
import keyword
import re
from typing import Optional
_use_orjson: bool = False
_custom_template_path: str = None
_symbol_ascii_strip_re = re.compile(r"[^A-Za-z0-9_]")
def set_use_orjson(value: bool) -> None:
"""
Set the value of the global variable _use_orjson.
:param value: value of the variable
"""
global _use_orjson
_use_orjson = value
def get_use_orjson() -> bool:
"""
Get the value of the global variable _use_orjson.
:return: value of the variable
"""
global _use_orjson
return _use_orjson
def set_custom_template_path(value: Optional[str]) -> None:
"""
Set the value of the global variable _custom_template_path.
:param value: value of the variable
"""
global _custom_template_path
_custom_template_path = value
def get_custom_template_path() -> Optional[str]:
"""
Get the value of the global variable _custom_template_path.
:return: value of the variable
"""
global _custom_template_path
return _custom_template_path
def normalize_symbol(symbol: str) -> str:
"""
Remove invalid characters & keywords in Python symbol names
:param symbol: name of the identifier
:return: normalized identifier name
"""
symbol = symbol.replace("-", "_")
normalized_symbol = _symbol_ascii_strip_re.sub("", symbol)
if normalized_symbol in keyword.kwlist:
normalized_symbol = normalized_symbol + "_"
return normalized_symbol