pocketx 0.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pocketx-0.0.4/MANIFEST.in +1 -0
- pocketx-0.0.4/PKG-INFO +21 -0
- pocketx-0.0.4/README.md +0 -0
- pocketx-0.0.4/pocketx/TWCASignDLL/TWCASignDLL_64.dll +0 -0
- pocketx-0.0.4/pocketx/TWCASignDLL/TwcaSignDLL.py +167 -0
- pocketx-0.0.4/pocketx/TWCASignDLL/__init__.py +0 -0
- pocketx-0.0.4/pocketx/TWCASignDLL/libeay32MD.dll +0 -0
- pocketx-0.0.4/pocketx/TWCASignDLL/p7Sign.properties +23 -0
- pocketx-0.0.4/pocketx/__init__.py +4 -0
- pocketx-0.0.4/pocketx/account.py +38 -0
- pocketx-0.0.4/pocketx/backend/__init__.py +0 -0
- pocketx-0.0.4/pocketx/base.py +228 -0
- pocketx-0.0.4/pocketx/constant.py +233 -0
- pocketx-0.0.4/pocketx/contracts.py +386 -0
- pocketx-0.0.4/pocketx/data.py +116 -0
- pocketx-0.0.4/pocketx/error.py +83 -0
- pocketx-0.0.4/pocketx/order.py +158 -0
- pocketx-0.0.4/pocketx/pocketx.py +468 -0
- pocketx-0.0.4/pocketx/position.py +205 -0
- pocketx-0.0.4/pocketx/stream_data_type.py +498 -0
- pocketx-0.0.4/pocketx.egg-info/PKG-INFO +21 -0
- pocketx-0.0.4/pocketx.egg-info/SOURCES.txt +28 -0
- pocketx-0.0.4/pocketx.egg-info/dependency_links.txt +1 -0
- pocketx-0.0.4/pocketx.egg-info/requires.txt +8 -0
- pocketx-0.0.4/pocketx.egg-info/top_level.txt +1 -0
- pocketx-0.0.4/pyproject.toml +44 -0
- pocketx-0.0.4/setup.cfg +4 -0
- pocketx-0.0.4/setup.py +47 -0
- pocketx-0.0.4/tests/test_user.py +60 -0
- pocketx-0.0.4/utils.py +3431 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include utils.py
|
pocketx-0.0.4/PKG-INFO
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pocketx
|
|
3
|
+
Version: 0.0.4
|
|
4
|
+
Summary: Pocket Security Trading Api
|
|
5
|
+
Author-email: FelixChih <felix6258925@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: pocket,pocket-sdk,pocket_sdk,pocket-api,pocket_api
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
10
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Requires-Python: >=3.7
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: requests>=2.31.0
|
|
15
|
+
Requires-Dist: pydantic>=2.9.1
|
|
16
|
+
Requires-Dist: websockets>=13.0.1
|
|
17
|
+
Requires-Dist: pulsar-client>=3.5.0
|
|
18
|
+
Requires-Dist: pandas<3.0,>=2.0.3
|
|
19
|
+
Requires-Dist: numpy>=1.24.4
|
|
20
|
+
Requires-Dist: aiohttp>=3.10.8
|
|
21
|
+
Requires-Dist: importlib_metadata>=8.4.0
|
pocketx-0.0.4/README.md
ADDED
|
File without changes
|
|
Binary file
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from ctypes import *
|
|
3
|
+
|
|
4
|
+
class TwcaSignDLL:
|
|
5
|
+
def __init__(self):
|
|
6
|
+
self.__GetErrorMsg = None
|
|
7
|
+
self.__GetErrorCode = None
|
|
8
|
+
self.__GetSignerCertFinger = None
|
|
9
|
+
self.__GetSignerCertSerial = None
|
|
10
|
+
self.__GetSignerCertNotAfter = None
|
|
11
|
+
self.__GetSignerCertNotBefore = None
|
|
12
|
+
self.__GetSignerCertIssuer = None
|
|
13
|
+
self.__GetSignerCertSubject = None
|
|
14
|
+
self.__GetSignerCertSubjectCN = None
|
|
15
|
+
self.__myDll = None
|
|
16
|
+
self.__ver = None
|
|
17
|
+
self.__makeTWCASignPasswd = None
|
|
18
|
+
self.__TWCASignInitial = None
|
|
19
|
+
self.__SignPkcs7 = None
|
|
20
|
+
self.__GetSignedPkcs7 = None
|
|
21
|
+
|
|
22
|
+
def initialDLL(self, dll_path_file):
|
|
23
|
+
try:
|
|
24
|
+
self.__myDll = cdll.LoadLibrary(dll_path_file)
|
|
25
|
+
|
|
26
|
+
# function mapping
|
|
27
|
+
self.__ver = getattr(self.__myDll, "?GetPkiVersion@@YAPEADXZ")
|
|
28
|
+
self.__ver.restype = c_char_p
|
|
29
|
+
|
|
30
|
+
self.__GetErrorCode = getattr(self.__myDll, "?GetErrorCode@@YAHXZ")
|
|
31
|
+
self.__GetErrorCode.restype = c_int
|
|
32
|
+
|
|
33
|
+
self.__GetErrorMsg = getattr(self.__myDll, "?GetErrorMsg@@YAPEADXZ")
|
|
34
|
+
self.__GetErrorMsg.restype = c_char_p
|
|
35
|
+
|
|
36
|
+
self.__makeTWCASignPasswd = getattr(self.__myDll, "?MakeTWCASignPasswd@@YAHPEBDPEAH00@Z")
|
|
37
|
+
self.__makeTWCASignPasswd.argtypes = [POINTER(c_char), POINTER(c_int), POINTER(c_char), POINTER(c_char)]
|
|
38
|
+
self.__makeTWCASignPasswd.restype = c_int
|
|
39
|
+
|
|
40
|
+
self.__TWCASignInitial = getattr(self.__myDll, "?TWCASignInitial@@YA_NPEBD0@Z")
|
|
41
|
+
self.__TWCASignInitial.argtypes = [POINTER(c_char), POINTER(c_char)]
|
|
42
|
+
self.__TWCASignInitial.restype = c_int
|
|
43
|
+
|
|
44
|
+
self.__SignPkcs7 = getattr(self.__myDll, "?SignPkcs7@@YAHPEBD0@Z")
|
|
45
|
+
self.__SignPkcs7.argtypes = [POINTER(c_char), POINTER(c_char)]
|
|
46
|
+
self.__SignPkcs7.restype = c_int
|
|
47
|
+
|
|
48
|
+
self.__GetSignedPkcs7 = getattr(self.__myDll, "?GetSignedPkcs7@@YAPEADXZ")
|
|
49
|
+
self.__GetSignedPkcs7.restype = c_char_p
|
|
50
|
+
# cert Info
|
|
51
|
+
self.__GetSignerCertSubject = getattr(self.__myDll, "?GetSignerCertSubject@@YAPEADXZ")
|
|
52
|
+
self.__GetSignerCertSubject.restype = c_char_p
|
|
53
|
+
|
|
54
|
+
self.__GetSignerCertSubjectCN = getattr(self.__myDll, "?GetSignerCertSubjectCN@@YAPEADXZ")
|
|
55
|
+
self.__GetSignerCertSubjectCN.restype = c_char_p
|
|
56
|
+
|
|
57
|
+
self.__GetSignerCertIssuer = getattr(self.__myDll, "?GetSignerCertIssuer@@YAPEADXZ")
|
|
58
|
+
self.__GetSignerCertIssuer.restype = c_char_p
|
|
59
|
+
|
|
60
|
+
self.__GetSignerCertNotBefore = getattr(self.__myDll, "?GetSignerCertNotBefore@@YAPEADXZ")
|
|
61
|
+
self.__GetSignerCertNotBefore.restype = c_char_p
|
|
62
|
+
|
|
63
|
+
self.__GetSignerCertNotAfter = getattr(self.__myDll, "?GetSignerCertNotAfter@@YAPEADXZ")
|
|
64
|
+
self.__GetSignerCertNotAfter.restype = c_char_p
|
|
65
|
+
|
|
66
|
+
self.__GetSignerCertSerial = getattr(self.__myDll, "?GetSignerCertSerial@@YAPEADXZ")
|
|
67
|
+
self.__GetSignerCertSerial.restype = c_char_p
|
|
68
|
+
|
|
69
|
+
self.__GetSignerCertFinger = getattr(self.__myDll, "?GetSignerCertFinger@@YAPEADXZ")
|
|
70
|
+
self.__GetSignerCertFinger.restype = c_char_p
|
|
71
|
+
return 0
|
|
72
|
+
except FileNotFoundError:
|
|
73
|
+
return -1
|
|
74
|
+
|
|
75
|
+
def getVersion(self):
|
|
76
|
+
return self.__ver().decode("utf-8")
|
|
77
|
+
|
|
78
|
+
def signInitial(self, property_file, pfx_pwd=None):
|
|
79
|
+
char_array = c_char * 512
|
|
80
|
+
encedPfxPasswd = char_array()
|
|
81
|
+
pfxPasswdLen = c_int(512)
|
|
82
|
+
# ret = self.__makeTWCASignPasswd(encedPfxPasswd, byref(pfxPasswdLen), bytes(property_file, 'utf-8'), bytes(pfx_pwd, 'utf-8'))
|
|
83
|
+
# ret = self.__makeTWCASignPasswd(encedPfxPasswd, byref(pfxPasswdLen), bytes(property_file, 'utf-8'), None)
|
|
84
|
+
|
|
85
|
+
ret = self.__TWCASignInitial(bytes(property_file, 'utf-8'), bytes("", 'utf-8'))
|
|
86
|
+
|
|
87
|
+
if ret == 1:
|
|
88
|
+
ret = 0
|
|
89
|
+
|
|
90
|
+
return ret
|
|
91
|
+
|
|
92
|
+
def signInitial_v2(self, property_file, ca_path, ca_passwd, person_id):
|
|
93
|
+
PFX_path, PFX_file = os.path.split(ca_path)
|
|
94
|
+
PFX_pswd = ca_passwd
|
|
95
|
+
PFX_signerFilter = f"//S_CN={person_id},S_OU=23470685-RA-CHUANTAI,S_OU=CHUANTAI,S_C=TW,S_O=TaiCA Secure CA - Evaluation Only,S_O=Certificate Service Provider - Evaluation Only//"
|
|
96
|
+
|
|
97
|
+
# 打印這四個參數以確認它們已正確傳入
|
|
98
|
+
print('-' * 50)
|
|
99
|
+
print(f"PFX.path={PFX_path}")
|
|
100
|
+
print(f"PFX.file={PFX_file}")
|
|
101
|
+
print(f"PFX.pswd={PFX_pswd}")
|
|
102
|
+
print(f"PFX.signerFilter={PFX_signerFilter}")
|
|
103
|
+
print('-' * 50)
|
|
104
|
+
|
|
105
|
+
# CA 簽名初始化操作
|
|
106
|
+
char_array = c_char * 512
|
|
107
|
+
encedPfxPasswd = char_array()
|
|
108
|
+
pfxPasswdLen = c_int(512)
|
|
109
|
+
|
|
110
|
+
# 手動傳入密碼,進行密碼加密操作
|
|
111
|
+
ret = self.__TWCASignInitial(
|
|
112
|
+
bytes(property_file, 'utf-8'),
|
|
113
|
+
bytes(PFX_path, 'utf-8'), # 傳入 CA 憑證路徑
|
|
114
|
+
bytes(PFX_file, 'utf-8'), # 傳入 CA 憑證文件名
|
|
115
|
+
bytes(PFX_pswd, 'utf-8'),
|
|
116
|
+
bytes(PFX_signerFilter, 'utf-8') # 傳入簽名過濾器
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
if ret == 1:
|
|
120
|
+
ret = 0
|
|
121
|
+
|
|
122
|
+
return ret
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def signPKCS7(self, plaintext_bytes):
|
|
126
|
+
encoding = b"UTF-16LE"
|
|
127
|
+
ret = self.__SignPkcs7(plaintext_bytes, encoding)
|
|
128
|
+
return ret
|
|
129
|
+
|
|
130
|
+
def getSignedPkcs7(self):
|
|
131
|
+
if self.__GetSignedPkcs7() is None:
|
|
132
|
+
return None
|
|
133
|
+
else:
|
|
134
|
+
return self.__GetSignedPkcs7().decode("utf-8")
|
|
135
|
+
|
|
136
|
+
def getSignerCertSubjectCN(self):
|
|
137
|
+
return self.__GetSignerCertSubjectCN().decode("utf-8")
|
|
138
|
+
|
|
139
|
+
def getSignerCertSubject(self):
|
|
140
|
+
if self.__GetSignerCertSubject is None:
|
|
141
|
+
return None
|
|
142
|
+
else:
|
|
143
|
+
return self.__GetSignerCertSubject().decode("utf-8")
|
|
144
|
+
|
|
145
|
+
def getSignerCertIssuer(self):
|
|
146
|
+
return self.__GetSignerCertIssuer().decode("utf-8")
|
|
147
|
+
|
|
148
|
+
def getSignerCertNotBefore(self):
|
|
149
|
+
return self.__GetSignerCertNotBefore().decode("utf-8")
|
|
150
|
+
|
|
151
|
+
def getSignerCertNotAfter(self):
|
|
152
|
+
return self.__GetSignerCertNotAfter().decode("utf-8")
|
|
153
|
+
|
|
154
|
+
def getSignerCertSerial(self):
|
|
155
|
+
return self.__GetSignerCertSerial().decode("utf-8")
|
|
156
|
+
|
|
157
|
+
def getSignerCertFinger(self):
|
|
158
|
+
return self.__GetSignerCertFinger().decode("utf-8")
|
|
159
|
+
|
|
160
|
+
def getErrorCode(self):
|
|
161
|
+
return self.__GetErrorCode()
|
|
162
|
+
|
|
163
|
+
def getErrorMsg(self):
|
|
164
|
+
if self.__GetErrorMsg is None:
|
|
165
|
+
return None
|
|
166
|
+
else:
|
|
167
|
+
return self.__GetErrorMsg().decode("big5")
|
|
File without changes
|
|
Binary file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
LOG.path=LOG
|
|
2
|
+
LOG.file=P7Sign.log
|
|
3
|
+
LOG.level=DEBUG
|
|
4
|
+
PSWD.license=44D5370067BA2AD2FEC05F7FF37621A88617499B4306F3B3DEA3C71ED68163FCBBA5761DA9A7849E34004C1AC5F90427AC29546236B073FD88CF49BC4A9FE32D
|
|
5
|
+
PFX.path=USER_PFX_PATH
|
|
6
|
+
PFX.file=USER_PFX_FILE
|
|
7
|
+
PFX.pswd=USER_PASSWORD
|
|
8
|
+
PFX.checkValid=true
|
|
9
|
+
PFX.checkKeyUsage=true
|
|
10
|
+
PFX.signerFilter=USER_PFX_SIGNERFILTER
|
|
11
|
+
PKCS7.digest=SHA256
|
|
12
|
+
PKCS7.addCert=2
|
|
13
|
+
PKCS7.addPlainText=true
|
|
14
|
+
PKCS7.addTimestamp=false
|
|
15
|
+
P7B.path=P7B
|
|
16
|
+
P7B0.name=TaiCA Secure CA_2012.p7b
|
|
17
|
+
P7B0.SKI=FA1F7F07700FEB1591AA6A21FD0CDC801B18C885
|
|
18
|
+
P7B1.name=TaiCA Secure CA_2014.p7b
|
|
19
|
+
P7B1.SKI=2E3B2E30EA9E85A1A574148DCA539795930B649C8C6635BFF98B0DBB8D16415C
|
|
20
|
+
P7B2.name=TWCA Financial User CA_2014.p7b
|
|
21
|
+
P7B2.SKI=F395038C0F5FD4B0F23A7D061087D5BD3060B6FB4A5A725D772C491B433AE76A
|
|
22
|
+
P7B3.name=TWCA Financial User CA_2017.p7b
|
|
23
|
+
P7B3.SKI=8DD0A0C9CF9B5062CB39073F083359A9FCD4612DCFBB4CB3A70446CB6E74B678
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
from pocketx.base import BaseModel
|
|
4
|
+
|
|
5
|
+
__all__ = ("Account StockAccount FutureAccount").split()
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AccountType(str, Enum):
|
|
9
|
+
Stock = "S"
|
|
10
|
+
Future = "F"
|
|
11
|
+
H = "H" # TODO declear
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class BaseAccount(BaseModel):
|
|
15
|
+
account_type: AccountType
|
|
16
|
+
person_id: str
|
|
17
|
+
broker_id: str
|
|
18
|
+
account_id: str
|
|
19
|
+
signed: bool = False
|
|
20
|
+
|
|
21
|
+
def astype(self):
|
|
22
|
+
return _ACCTTYPE.get(self.account_type, self.__class__)(**self.dict())
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Account(BaseAccount):
|
|
26
|
+
username: str = ""
|
|
27
|
+
nanoid: str = ""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class StockAccount(Account):
|
|
31
|
+
account_type: AccountType = AccountType.Stock
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class FutureAccount(Account):
|
|
35
|
+
account_type: AccountType = AccountType.Future
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
_ACCTTYPE = {"S": StockAccount, "F": FutureAccount}
|
|
File without changes
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from pydantic import (
|
|
4
|
+
BaseModel,
|
|
5
|
+
conint,
|
|
6
|
+
StrictInt,
|
|
7
|
+
constr,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
# _missing = object()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BaseModelV10(BaseModel):
|
|
14
|
+
def __repr_args__(self):
|
|
15
|
+
return [(k, v) for k, v in self._iter(to_dict=False, exclude_defaults=True)]
|
|
16
|
+
|
|
17
|
+
def _iter(
|
|
18
|
+
self,
|
|
19
|
+
to_dict: bool = False,
|
|
20
|
+
by_alias: bool = False,
|
|
21
|
+
allowed_keys: typing.Optional["SetStr"] = None,
|
|
22
|
+
include: typing.Union["AbstractSetIntStr", "DictIntStrAny"] = None,
|
|
23
|
+
exclude: typing.Union["AbstractSetIntStr", "DictIntStrAny"] = None,
|
|
24
|
+
exclude_unset: bool = False,
|
|
25
|
+
exclude_defaults: bool = False,
|
|
26
|
+
# exclude_none: bool = False,
|
|
27
|
+
):
|
|
28
|
+
if not to_dict:
|
|
29
|
+
if allowed_keys is None:
|
|
30
|
+
allowed_keys = set(self.__fields__)
|
|
31
|
+
if exclude:
|
|
32
|
+
for k in exclude:
|
|
33
|
+
allowed_keys.discard(k)
|
|
34
|
+
return super()._iter(
|
|
35
|
+
to_dict,
|
|
36
|
+
by_alias,
|
|
37
|
+
allowed_keys,
|
|
38
|
+
include,
|
|
39
|
+
exclude,
|
|
40
|
+
exclude_unset,
|
|
41
|
+
exclude_defaults,
|
|
42
|
+
# exclude_none,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
@classmethod
|
|
46
|
+
def _get_value(
|
|
47
|
+
cls,
|
|
48
|
+
v: typing.Any,
|
|
49
|
+
to_dict: bool,
|
|
50
|
+
by_alias: bool,
|
|
51
|
+
include: typing.Optional[typing.Union["AbstractSetIntStr", "DictIntStrAny"]],
|
|
52
|
+
exclude: typing.Optional[typing.Union["AbstractSetIntStr", "DictIntStrAny"]],
|
|
53
|
+
exclude_unset: bool,
|
|
54
|
+
exclude_defaults: bool,
|
|
55
|
+
# exclude_none: bool,
|
|
56
|
+
) -> typing.Any:
|
|
57
|
+
if to_dict and isinstance(v, Enum):
|
|
58
|
+
return v.value
|
|
59
|
+
return super()._get_value(
|
|
60
|
+
v,
|
|
61
|
+
to_dict,
|
|
62
|
+
by_alias,
|
|
63
|
+
include,
|
|
64
|
+
exclude,
|
|
65
|
+
exclude_unset,
|
|
66
|
+
exclude_defaults,
|
|
67
|
+
# exclude_none,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
def keys(self) -> typing.List[typing.Any]:
|
|
71
|
+
return self._calculate_keys(include=None, exclude=None, exclude_unset=True)
|
|
72
|
+
|
|
73
|
+
def __getitem__(self, key: typing.Any) -> typing.Any:
|
|
74
|
+
return self._get_value(
|
|
75
|
+
self.__dict__[key],
|
|
76
|
+
to_dict=True,
|
|
77
|
+
by_alias=False,
|
|
78
|
+
include=None,
|
|
79
|
+
exclude=None,
|
|
80
|
+
exclude_unset=True,
|
|
81
|
+
exclude_defaults=True,
|
|
82
|
+
# exclude_none=True,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
def lazy_setter(self, **kwargs):
|
|
86
|
+
[
|
|
87
|
+
setattr(self, kwarg, value)
|
|
88
|
+
for kwarg, value in kwargs.items()
|
|
89
|
+
if hasattr(self, kwarg)
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class BaseModelV15(BaseModel):
|
|
94
|
+
def __repr_args__(self):
|
|
95
|
+
return [(k, v) for k, v in self._iter(to_dict=False, exclude_defaults=True)]
|
|
96
|
+
|
|
97
|
+
@classmethod
|
|
98
|
+
def _get_value(
|
|
99
|
+
cls,
|
|
100
|
+
v: typing.Any,
|
|
101
|
+
to_dict: bool,
|
|
102
|
+
by_alias: bool,
|
|
103
|
+
include: typing.Optional[typing.Union["AbstractSetIntStr", "DictIntStrAny"]],
|
|
104
|
+
exclude: typing.Optional[typing.Union["AbstractSetIntStr", "DictIntStrAny"]],
|
|
105
|
+
exclude_unset: bool,
|
|
106
|
+
exclude_defaults: bool,
|
|
107
|
+
exclude_none: bool,
|
|
108
|
+
) -> typing.Any:
|
|
109
|
+
if to_dict and isinstance(v, Enum):
|
|
110
|
+
return v.value
|
|
111
|
+
return super()._get_value(
|
|
112
|
+
v,
|
|
113
|
+
to_dict,
|
|
114
|
+
by_alias,
|
|
115
|
+
include,
|
|
116
|
+
exclude,
|
|
117
|
+
exclude_unset,
|
|
118
|
+
exclude_defaults,
|
|
119
|
+
exclude_none,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
def keys(self) -> typing.List[typing.Any]:
|
|
123
|
+
return self._calculate_keys(include=None, exclude=None, exclude_unset=True)
|
|
124
|
+
|
|
125
|
+
def __getitem__(self, key: typing.Any) -> typing.Any:
|
|
126
|
+
return self._get_value(
|
|
127
|
+
self.__dict__[key],
|
|
128
|
+
to_dict=True,
|
|
129
|
+
by_alias=False,
|
|
130
|
+
include=None,
|
|
131
|
+
exclude=None,
|
|
132
|
+
exclude_unset=True,
|
|
133
|
+
exclude_defaults=True,
|
|
134
|
+
exclude_none=True,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
def lazy_setter(self, **kwargs):
|
|
138
|
+
[
|
|
139
|
+
setattr(self, kwarg, value)
|
|
140
|
+
for kwarg, value in kwargs.items()
|
|
141
|
+
if hasattr(self, kwarg)
|
|
142
|
+
]
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
class BaseModelV20(BaseModel):
|
|
146
|
+
__json__: dict = {}
|
|
147
|
+
|
|
148
|
+
def __repr_args__(self):
|
|
149
|
+
return [
|
|
150
|
+
(k, getattr(self, k))
|
|
151
|
+
for k, v in self.model_dump(exclude_defaults=True).items()
|
|
152
|
+
]
|
|
153
|
+
|
|
154
|
+
def keys(self) -> typing.Set[str]: # typing.List[typing.Any]:
|
|
155
|
+
if not self.__json__:
|
|
156
|
+
self.__json__ = self.model_dump(
|
|
157
|
+
mode="json",
|
|
158
|
+
by_alias=False,
|
|
159
|
+
include=None,
|
|
160
|
+
exclude=None,
|
|
161
|
+
exclude_unset=True,
|
|
162
|
+
exclude_defaults=True,
|
|
163
|
+
exclude_none=True,
|
|
164
|
+
)
|
|
165
|
+
return self.__json__.keys()
|
|
166
|
+
|
|
167
|
+
def __getitem__(self, key: str) -> typing.Any:
|
|
168
|
+
if not self.__json__:
|
|
169
|
+
self.__json__ = self.model_dump(
|
|
170
|
+
mode="json",
|
|
171
|
+
by_alias=False,
|
|
172
|
+
include=None,
|
|
173
|
+
exclude=None,
|
|
174
|
+
exclude_unset=True,
|
|
175
|
+
exclude_defaults=True,
|
|
176
|
+
exclude_none=True,
|
|
177
|
+
)
|
|
178
|
+
return self.__json__[key]
|
|
179
|
+
|
|
180
|
+
def lazy_setter(self, **kwargs):
|
|
181
|
+
[
|
|
182
|
+
setattr(self, kwarg, value)
|
|
183
|
+
for kwarg, value in kwargs.items()
|
|
184
|
+
if hasattr(self, kwarg)
|
|
185
|
+
]
|
|
186
|
+
|
|
187
|
+
def _clean_cache(self):
|
|
188
|
+
if self.__json__:
|
|
189
|
+
object.__setattr__(self, "__json__", {})
|
|
190
|
+
|
|
191
|
+
def __setattr__(self, name: str, value: typing.Any) -> None:
|
|
192
|
+
self._clean_cache()
|
|
193
|
+
return super().__setattr__(name, value)
|
|
194
|
+
|
|
195
|
+
def dict(self):
|
|
196
|
+
return self.model_dump(
|
|
197
|
+
mode="json",
|
|
198
|
+
include=None,
|
|
199
|
+
exclude=None,
|
|
200
|
+
by_alias=False,
|
|
201
|
+
exclude_unset=False,
|
|
202
|
+
exclude_defaults=False,
|
|
203
|
+
exclude_none=True,
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class MetaProps(type):
|
|
208
|
+
def __repr__(cls):
|
|
209
|
+
attrs = [attr for attr in cls.__dict__ if not attr.startswith("_")]
|
|
210
|
+
display_name = cls.__name__ if not cls.__name__.startswith("_") else ""
|
|
211
|
+
return "{}({})".format(display_name, (", ").join(attrs))
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
class BaseProps(metaclass=MetaProps):
|
|
215
|
+
pass
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
from importlib_metadata import version
|
|
219
|
+
|
|
220
|
+
if version("pydantic") >= "2.0":
|
|
221
|
+
BaseModel = BaseModelV20
|
|
222
|
+
ConStrAsciiMax32 = constr(max_length=32, pattern="^[ -~]*$")
|
|
223
|
+
elif version("pydantic") > "1.0":
|
|
224
|
+
BaseModel = BaseModelV15
|
|
225
|
+
ConStrAsciiMax32 = constr(max_length=32, regex="^[ -~]*$")
|
|
226
|
+
else:
|
|
227
|
+
BaseModel = BaseModelV10
|
|
228
|
+
ConStrAsciiMax32 = constr(max_length=32, regex="^[ -~]*$")
|