-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathcommon.py
More file actions
93 lines (78 loc) · 2.66 KB
/
common.py
File metadata and controls
93 lines (78 loc) · 2.66 KB
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
import keyword
import re
from typing import Optional
from openapi_python_generator.common import PydanticVersion
_use_orjson: bool = False
_pydantic_version: PydanticVersion = PydanticVersion.V2
_custom_template_path: str = None
_pydantic_use_awaredatetime: bool = False
_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 set_pydantic_version(value: PydanticVersion) -> None:
"""
Set the value of the global variable
:param value: value of the variable
"""
global _pydantic_version
_pydantic_version = 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 get_pydantic_version() -> PydanticVersion:
"""
Get the value of the global variable _pydantic_version.
:return: value of the variable
"""
global _pydantic_version
return _pydantic_version
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 set_pydantic_use_awaredatetime(value: bool) -> None:
"""
Set whether to use AwareDateTime from pydantic instead of datetime.
:param value: value of the variable
"""
global _pydantic_use_awaredatetime
_pydantic_use_awaredatetime = value
def get_pydantic_use_awaredatetime() -> bool:
"""
Get whether to use AwareDateTime from pydantic instead of datetime.
:return: value of the variable
"""
global _pydantic_use_awaredatetime
return _pydantic_use_awaredatetime
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("-", "_").replace(" ", "_").replace(".", "_")
normalized_symbol = _symbol_ascii_strip_re.sub("", symbol)
if normalized_symbol in keyword.kwlist:
normalized_symbol = normalized_symbol + "_"
if len(normalized_symbol) > 0 and normalized_symbol[0].isnumeric():
normalized_symbol = "_" + normalized_symbol
return normalized_symbol