deepfos 1.1.60__py3-none-any.whl

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.
Files changed (175) hide show
  1. deepfos/__init__.py +6 -0
  2. deepfos/_version.py +21 -0
  3. deepfos/algo/__init__.py +0 -0
  4. deepfos/algo/graph.py +171 -0
  5. deepfos/algo/segtree.py +31 -0
  6. deepfos/api/V1_1/__init__.py +0 -0
  7. deepfos/api/V1_1/business_model.py +119 -0
  8. deepfos/api/V1_1/dimension.py +599 -0
  9. deepfos/api/V1_1/models/__init__.py +0 -0
  10. deepfos/api/V1_1/models/business_model.py +1033 -0
  11. deepfos/api/V1_1/models/dimension.py +2768 -0
  12. deepfos/api/V1_2/__init__.py +0 -0
  13. deepfos/api/V1_2/dimension.py +285 -0
  14. deepfos/api/V1_2/models/__init__.py +0 -0
  15. deepfos/api/V1_2/models/dimension.py +2923 -0
  16. deepfos/api/__init__.py +0 -0
  17. deepfos/api/account.py +167 -0
  18. deepfos/api/accounting_engines.py +147 -0
  19. deepfos/api/app.py +626 -0
  20. deepfos/api/approval_process.py +198 -0
  21. deepfos/api/base.py +983 -0
  22. deepfos/api/business_model.py +160 -0
  23. deepfos/api/consolidation.py +129 -0
  24. deepfos/api/consolidation_process.py +106 -0
  25. deepfos/api/datatable.py +341 -0
  26. deepfos/api/deep_pipeline.py +61 -0
  27. deepfos/api/deepconnector.py +36 -0
  28. deepfos/api/deepfos_task.py +92 -0
  29. deepfos/api/deepmodel.py +188 -0
  30. deepfos/api/dimension.py +486 -0
  31. deepfos/api/financial_model.py +319 -0
  32. deepfos/api/journal_model.py +119 -0
  33. deepfos/api/journal_template.py +132 -0
  34. deepfos/api/memory_financial_model.py +98 -0
  35. deepfos/api/models/__init__.py +3 -0
  36. deepfos/api/models/account.py +483 -0
  37. deepfos/api/models/accounting_engines.py +756 -0
  38. deepfos/api/models/app.py +1338 -0
  39. deepfos/api/models/approval_process.py +1043 -0
  40. deepfos/api/models/base.py +234 -0
  41. deepfos/api/models/business_model.py +805 -0
  42. deepfos/api/models/consolidation.py +711 -0
  43. deepfos/api/models/consolidation_process.py +248 -0
  44. deepfos/api/models/datatable_mysql.py +427 -0
  45. deepfos/api/models/deep_pipeline.py +55 -0
  46. deepfos/api/models/deepconnector.py +28 -0
  47. deepfos/api/models/deepfos_task.py +386 -0
  48. deepfos/api/models/deepmodel.py +308 -0
  49. deepfos/api/models/dimension.py +1576 -0
  50. deepfos/api/models/financial_model.py +1796 -0
  51. deepfos/api/models/journal_model.py +341 -0
  52. deepfos/api/models/journal_template.py +854 -0
  53. deepfos/api/models/memory_financial_model.py +478 -0
  54. deepfos/api/models/platform.py +178 -0
  55. deepfos/api/models/python.py +221 -0
  56. deepfos/api/models/reconciliation_engine.py +411 -0
  57. deepfos/api/models/reconciliation_report.py +161 -0
  58. deepfos/api/models/role_strategy.py +884 -0
  59. deepfos/api/models/smartlist.py +237 -0
  60. deepfos/api/models/space.py +1137 -0
  61. deepfos/api/models/system.py +1065 -0
  62. deepfos/api/models/variable.py +463 -0
  63. deepfos/api/models/workflow.py +946 -0
  64. deepfos/api/platform.py +199 -0
  65. deepfos/api/python.py +90 -0
  66. deepfos/api/reconciliation_engine.py +181 -0
  67. deepfos/api/reconciliation_report.py +64 -0
  68. deepfos/api/role_strategy.py +234 -0
  69. deepfos/api/smartlist.py +69 -0
  70. deepfos/api/space.py +582 -0
  71. deepfos/api/system.py +372 -0
  72. deepfos/api/variable.py +154 -0
  73. deepfos/api/workflow.py +264 -0
  74. deepfos/boost/__init__.py +6 -0
  75. deepfos/boost/py_jstream.py +89 -0
  76. deepfos/boost/py_pandas.py +20 -0
  77. deepfos/cache.py +121 -0
  78. deepfos/config.py +6 -0
  79. deepfos/core/__init__.py +27 -0
  80. deepfos/core/cube/__init__.py +10 -0
  81. deepfos/core/cube/_base.py +462 -0
  82. deepfos/core/cube/constants.py +21 -0
  83. deepfos/core/cube/cube.py +408 -0
  84. deepfos/core/cube/formula.py +707 -0
  85. deepfos/core/cube/syscube.py +532 -0
  86. deepfos/core/cube/typing.py +7 -0
  87. deepfos/core/cube/utils.py +238 -0
  88. deepfos/core/dimension/__init__.py +11 -0
  89. deepfos/core/dimension/_base.py +506 -0
  90. deepfos/core/dimension/dimcreator.py +184 -0
  91. deepfos/core/dimension/dimension.py +472 -0
  92. deepfos/core/dimension/dimexpr.py +271 -0
  93. deepfos/core/dimension/dimmember.py +155 -0
  94. deepfos/core/dimension/eledimension.py +22 -0
  95. deepfos/core/dimension/filters.py +99 -0
  96. deepfos/core/dimension/sysdimension.py +168 -0
  97. deepfos/core/logictable/__init__.py +5 -0
  98. deepfos/core/logictable/_cache.py +141 -0
  99. deepfos/core/logictable/_operator.py +663 -0
  100. deepfos/core/logictable/nodemixin.py +673 -0
  101. deepfos/core/logictable/sqlcondition.py +609 -0
  102. deepfos/core/logictable/tablemodel.py +497 -0
  103. deepfos/db/__init__.py +36 -0
  104. deepfos/db/cipher.py +660 -0
  105. deepfos/db/clickhouse.py +191 -0
  106. deepfos/db/connector.py +195 -0
  107. deepfos/db/daclickhouse.py +171 -0
  108. deepfos/db/dameng.py +101 -0
  109. deepfos/db/damysql.py +189 -0
  110. deepfos/db/dbkits.py +358 -0
  111. deepfos/db/deepengine.py +99 -0
  112. deepfos/db/deepmodel.py +82 -0
  113. deepfos/db/deepmodel_kingbase.py +83 -0
  114. deepfos/db/edb.py +214 -0
  115. deepfos/db/gauss.py +83 -0
  116. deepfos/db/kingbase.py +83 -0
  117. deepfos/db/mysql.py +184 -0
  118. deepfos/db/oracle.py +131 -0
  119. deepfos/db/postgresql.py +192 -0
  120. deepfos/db/sqlserver.py +99 -0
  121. deepfos/db/utils.py +135 -0
  122. deepfos/element/__init__.py +89 -0
  123. deepfos/element/accounting.py +348 -0
  124. deepfos/element/apvlprocess.py +215 -0
  125. deepfos/element/base.py +398 -0
  126. deepfos/element/bizmodel.py +1269 -0
  127. deepfos/element/datatable.py +2467 -0
  128. deepfos/element/deep_pipeline.py +186 -0
  129. deepfos/element/deepconnector.py +59 -0
  130. deepfos/element/deepmodel.py +1806 -0
  131. deepfos/element/dimension.py +1254 -0
  132. deepfos/element/fact_table.py +427 -0
  133. deepfos/element/finmodel.py +1485 -0
  134. deepfos/element/journal.py +840 -0
  135. deepfos/element/journal_template.py +943 -0
  136. deepfos/element/pyscript.py +412 -0
  137. deepfos/element/reconciliation.py +553 -0
  138. deepfos/element/rolestrategy.py +243 -0
  139. deepfos/element/smartlist.py +457 -0
  140. deepfos/element/variable.py +756 -0
  141. deepfos/element/workflow.py +560 -0
  142. deepfos/exceptions/__init__.py +239 -0
  143. deepfos/exceptions/hook.py +86 -0
  144. deepfos/lazy.py +104 -0
  145. deepfos/lazy_import.py +84 -0
  146. deepfos/lib/__init__.py +0 -0
  147. deepfos/lib/_javaobj.py +366 -0
  148. deepfos/lib/asynchronous.py +879 -0
  149. deepfos/lib/concurrency.py +107 -0
  150. deepfos/lib/constant.py +39 -0
  151. deepfos/lib/decorator.py +310 -0
  152. deepfos/lib/deepchart.py +778 -0
  153. deepfos/lib/deepux.py +477 -0
  154. deepfos/lib/discovery.py +273 -0
  155. deepfos/lib/edb_lexer.py +789 -0
  156. deepfos/lib/eureka.py +156 -0
  157. deepfos/lib/filterparser.py +751 -0
  158. deepfos/lib/httpcli.py +106 -0
  159. deepfos/lib/jsonstreamer.py +80 -0
  160. deepfos/lib/msg.py +394 -0
  161. deepfos/lib/nacos.py +225 -0
  162. deepfos/lib/patch.py +92 -0
  163. deepfos/lib/redis.py +241 -0
  164. deepfos/lib/serutils.py +181 -0
  165. deepfos/lib/stopwatch.py +99 -0
  166. deepfos/lib/subtask.py +572 -0
  167. deepfos/lib/sysutils.py +703 -0
  168. deepfos/lib/utils.py +1003 -0
  169. deepfos/local.py +160 -0
  170. deepfos/options.py +670 -0
  171. deepfos/translation.py +237 -0
  172. deepfos-1.1.60.dist-info/METADATA +33 -0
  173. deepfos-1.1.60.dist-info/RECORD +175 -0
  174. deepfos-1.1.60.dist-info/WHEEL +5 -0
  175. deepfos-1.1.60.dist-info/top_level.txt +1 -0
@@ -0,0 +1,264 @@
1
+ """
2
+ APIs provided by deepflow-server3-0
3
+
4
+ generated by api_code_gen.py
5
+ - **filename** : ``workflow.py``
6
+ - **json timestamp** : ``2023-05-08 11:11:46``
7
+ """
8
+ from deepfos.api.base import get, post, DynamicRootAPI, ChildAPI
9
+ from .models.workflow import *
10
+ from deepfos.lib.decorator import cached_property
11
+ from typing import List, Dict, Union, Any, Awaitable
12
+
13
+
14
+ __all__ = ['WorkFlowAPI']
15
+
16
+
17
+ class Process(ChildAPI):
18
+ endpoint = '/process/api'
19
+
20
+ @post('launch')
21
+ def launch(self, processLaunchDTO: ProcessLaunchDTO = None) -> Union[LaunchReturnVO, Awaitable[LaunchReturnVO]]:
22
+ """
23
+ 流程启动
24
+
25
+ """
26
+ return {'body': processLaunchDTO}
27
+
28
+ @get('launch-params')
29
+ def launch_params(self, elementName: str, folderId: str = None, path: str = None) -> Union[List[ProcessLaunchParamsVO], Awaitable[List[ProcessLaunchParamsVO]]]:
30
+ """
31
+ 获取工作流启动参数
32
+
33
+ """
34
+ return {'param': {'elementName': elementName, 'folderId': folderId, 'path': path}}
35
+
36
+ @post('launch/batch')
37
+ def launch_batch(self, processLaunchMultipleDTO: ProcessLaunchMultipleDTO = None) -> Union[List[LaunchReturnForBatchVO], Awaitable[List[LaunchReturnForBatchVO]]]:
38
+ """
39
+ 批量启动流程
40
+
41
+ """
42
+ return {'body': processLaunchMultipleDTO}
43
+
44
+ @post('process-instance/get-by-business-key')
45
+ def process_instance_get_by_business_key(self, businessKeyQueryDTO: BusinessKeyQueryDTO) -> Union[List[ProcessInstanceVO], Awaitable[List[ProcessInstanceVO]]]:
46
+ """
47
+ 通过【业务键】反查流程实例
48
+
49
+ """
50
+ return {'body': businessKeyQueryDTO}
51
+
52
+ @post('process-instance/get-by-launch-params')
53
+ def process_instance_get_by_launch_params(self, launchParamsDTO: LaunchParamsDTO) -> Union[List[ProcessInstanceVO], Awaitable[List[ProcessInstanceVO]]]:
54
+ """
55
+ 通过【启动参数】反查流程实例
56
+
57
+ """
58
+ return {'body': launchParamsDTO}
59
+
60
+ @get('process-instance/id')
61
+ def process_instance_id(self, procInstId: str) -> Union[ProcInstReturnVO, Awaitable[ProcInstReturnVO]]:
62
+ """
63
+ 根据流程实例id查询流程实例信息
64
+
65
+ """
66
+ return {'param': {'procInstId': procInstId}}
67
+
68
+ @post('send-message')
69
+ def send_message(self, sendMessageDTO: SendMessageParam) -> Union[Any, Awaitable[Any]]:
70
+ """
71
+ 发送消息
72
+
73
+ """
74
+ return {'body': sendMessageDTO}
75
+
76
+ @post('task-instance/get-by-business-key')
77
+ def task_instance_get_by_business_key(self, businessKeyQueryDTO: BusinessKeyQueryDTO) -> Union[List[TaskInstanceVO], Awaitable[List[TaskInstanceVO]]]:
78
+ """
79
+ 通过【业务键】反查任务实例
80
+
81
+ """
82
+ return {'body': businessKeyQueryDTO}
83
+
84
+ @post('task-instance/get-by-launch-params')
85
+ def task_instance_get_by_launch_params(self, launchParamsDTO: LaunchParamsDTO) -> Union[List[TaskInstanceVO], Awaitable[List[TaskInstanceVO]]]:
86
+ """
87
+ 通过【启动参数】反查任务实例
88
+
89
+ """
90
+ return {'body': launchParamsDTO}
91
+
92
+ @get('task-instance/id')
93
+ def task_instance_id(self, taskId: str) -> Union[TaskInstReturnVO, Awaitable[TaskInstReturnVO]]:
94
+ """
95
+ 根据任务实例id查询任务实例信息
96
+
97
+ """
98
+ return {'param': {'taskId': taskId}}
99
+
100
+
101
+ class ProcessInstance(ChildAPI):
102
+ endpoint = '/process/instance'
103
+
104
+ @post('global-params')
105
+ def global_params(self, vo: ProcessQueryDTO) -> Union[List[Value], Awaitable[List[Value]]]:
106
+ """
107
+ 工作流全局变量查询
108
+
109
+ """
110
+ return {'body': vo}
111
+
112
+ @post('monitor/page')
113
+ def monitor_page(self, filters: List[TaskQueryFilterDTO] = None, pageNo: int = None, pageSize: int = None, processInstanceQueryDTO: FlowInstanceQueryDto = None, search: str = None, status: str = None) -> Union[UnderwayPageInfo, Awaitable[UnderwayPageInfo]]:
114
+ """
115
+ 流程监控页面
116
+
117
+ 监控页面
118
+ """
119
+ return {
120
+ 'body': processInstanceQueryDTO,
121
+ 'param': {
122
+ 'filters': filters,
123
+ 'pageNo': pageNo,
124
+ 'pageSize': pageSize,
125
+ 'search': search,
126
+ 'status': status,
127
+ },
128
+ }
129
+
130
+ @post('started-by-me/page')
131
+ def started_by_me_page(self, processInstanceQueryDTO: FlowInstanceQueryDto = None) -> Union[UnderwayPageInfo, Awaitable[UnderwayPageInfo]]:
132
+ """
133
+ 我发起的流程
134
+
135
+ """
136
+ return {'body': processInstanceQueryDTO}
137
+
138
+
139
+ class ProcessMessage(ChildAPI):
140
+ endpoint = '/process/message'
141
+
142
+ @post('list')
143
+ def list(self, elementDetail: ElementDetailDTO) -> Union[List[Message], Awaitable[List[Message]]]:
144
+ """
145
+ 根据工作流元素,查询消息列表
146
+
147
+ """
148
+ return {'body': elementDetail}
149
+
150
+
151
+ class ProcessTask(ChildAPI):
152
+ endpoint = '/process/task'
153
+
154
+ @post('claim/list/page')
155
+ def claim_list_page(self, userTaskQueryDTO: UserTaskQueryDTO = None) -> Union[PageInfo, Awaitable[PageInfo]]:
156
+ """
157
+ 待认领的任务(分页)
158
+
159
+ 待认领的任务
160
+ """
161
+ return {'body': userTaskQueryDTO}
162
+
163
+ @post('express-complete')
164
+ def express_complete(self, taskCompleteDTO: TaskCompleteInstance) -> Union[bool, Awaitable[bool]]:
165
+ """
166
+ 完成任务
167
+
168
+ """
169
+ return {'body': taskCompleteDTO}
170
+
171
+ @post('list')
172
+ def list(self, taskQueryDTO: TaskQueryDto, status: str, processInstanceId: str) -> Union[List[UserTaskVO], Awaitable[List[UserTaskVO]]]:
173
+ """
174
+ 任务实例列表
175
+
176
+ """
177
+ return {
178
+ 'body': taskQueryDTO,
179
+ 'param': {'processInstanceId': processInstanceId, 'status': status},
180
+ }
181
+
182
+ @post('myTask/list/page')
183
+ def myTask_list_page(self, userTaskQueryDTO: UserTaskQueryDTO = None) -> Union[TodoPageInfo, Awaitable[TodoPageInfo]]:
184
+ """
185
+ 待办任务(分页)
186
+
187
+ 待办任务
188
+ """
189
+ return {'body': userTaskQueryDTO}
190
+
191
+
192
+ class Version(ChildAPI):
193
+ endpoint = '/version'
194
+
195
+ @get('list')
196
+ def list(self, elementName: str, folderId: str = None, path: str = None) -> Union[List[ProcessVersionVO], Awaitable[List[ProcessVersionVO]]]:
197
+ """
198
+ 查询流程版本列表
199
+
200
+ """
201
+ return {'param': {'elementName': elementName, 'folderId': folderId, 'path': path}}
202
+
203
+ @get('select-by-id')
204
+ def select_by_id(self, version: str, processId: str, elementName: str, folderId: str = None, path: str = None) -> Union[FlowQueryResp, Awaitable[FlowQueryResp]]:
205
+ """
206
+ 根据流程ID,版本号查询流程版本
207
+
208
+ """
209
+ return {
210
+ 'param': {
211
+ 'elementName': elementName,
212
+ 'folderId': folderId,
213
+ 'path': path,
214
+ 'processId': processId,
215
+ 'version': version,
216
+ },
217
+ }
218
+
219
+
220
+ class WorkFlowAPI(DynamicRootAPI, builtin=True):
221
+ """工作流组件接口"""
222
+ module_type = 'WKFL'
223
+ default_version = (3, 0)
224
+ multi_version = False
225
+ cls_name = 'WorkFlowAPI'
226
+ module_name = 'deepfos.api.workflow'
227
+ api_version = (3, 0)
228
+
229
+ @cached_property
230
+ def process(self) -> Process:
231
+ """
232
+ 工作流对外接口
233
+ """
234
+ return Process(self)
235
+
236
+ @cached_property
237
+ def instance(self) -> ProcessInstance:
238
+ """
239
+ 流程实例相关接口
240
+ """
241
+ return ProcessInstance(self)
242
+
243
+ @cached_property
244
+ def message(self) -> ProcessMessage:
245
+ """
246
+ 流程消息相关接口
247
+ """
248
+ return ProcessMessage(self)
249
+
250
+ @cached_property
251
+ def task(self) -> ProcessTask:
252
+ """
253
+ 流程任务相关接口
254
+ """
255
+ return ProcessTask(self)
256
+
257
+ @cached_property
258
+ def version_control(self) -> Version:
259
+ """
260
+ 版本管理相关接口
261
+ """
262
+ return Version(self)
263
+
264
+
@@ -0,0 +1,6 @@
1
+ try:
2
+ from . import pandas
3
+ from . import jstream
4
+ except ImportError: # pragma: no cover
5
+ from . import py_pandas as pandas
6
+ from . import py_jstream as jstream
@@ -0,0 +1,89 @@
1
+
2
+
3
+ def read(stream, streamer):
4
+ index = 0
5
+ empty = b''
6
+ stream_len = len(stream)
7
+ cp_stream = stream
8
+ matched_index = streamer.matched_index
9
+ key = streamer.key
10
+ is_started = streamer.is_started
11
+ in_double_quotation = streamer.in_double_quotation
12
+ in_escape = streamer.in_escape
13
+ lbrace = streamer.lbrace
14
+ rbrace = streamer.rbrace
15
+ finished = False
16
+
17
+ for i in range(stream_len):
18
+ c = cp_stream[i]
19
+ if 0 < matched_index < len(key) and c != key[matched_index]:
20
+ matched_index = 0
21
+ if in_double_quotation and not is_started and matched_index < len(key) and c == key[matched_index]:
22
+ matched_index += 1
23
+
24
+ if c == ord('\\'):
25
+ if not in_escape:
26
+ in_escape = True
27
+ else:
28
+ in_escape = False
29
+ index += 1
30
+ continue
31
+
32
+ if not in_escape and c == ord('"') and not in_double_quotation:
33
+ in_double_quotation = True
34
+ elif not in_escape and c == ord('"') and in_double_quotation:
35
+ in_double_quotation = False
36
+
37
+ if not in_double_quotation and is_started and (c == ord('{') or c == ord('[')):
38
+ lbrace += 1
39
+
40
+ if not in_double_quotation and is_started and (c == ord('}') or c == ord(']')):
41
+ rbrace += 1
42
+
43
+ # for value with brace
44
+ if is_started and lbrace > 0 and rbrace > 0 and lbrace - rbrace == 0:
45
+ finished = True
46
+ index += 1
47
+ break
48
+
49
+ # other
50
+ if is_started and not in_double_quotation and c == ord(',') and lbrace == 0 and rbrace == 0:
51
+ finished = True
52
+ break
53
+
54
+ if is_started and not in_double_quotation and (c == ord('}') or c == ord(']')) and lbrace == 0 and rbrace == 1:
55
+ finished = True
56
+ break
57
+
58
+ index += 1
59
+
60
+ if len(key) == matched_index and not is_started and c == ord(':'):
61
+ is_started = True
62
+ stream = stream[index:]
63
+ index = 0
64
+
65
+ if in_escape:
66
+ in_escape = False
67
+
68
+ if is_started:
69
+ streamer.finished = finished
70
+ stream = stream[:index]
71
+ if not finished:
72
+ streamer.matched_index = matched_index
73
+ streamer.key = key
74
+ streamer.is_started = is_started
75
+ streamer.in_double_quotation = in_double_quotation
76
+ streamer.in_escape = in_escape
77
+ streamer.lbrace = lbrace
78
+ streamer.rbrace = rbrace
79
+ return stream
80
+ else:
81
+ streamer.matched_index = matched_index
82
+ streamer.key = key
83
+ streamer.is_started = is_started
84
+ streamer.in_double_quotation = in_double_quotation
85
+ streamer.in_escape = in_escape
86
+ streamer.lbrace = lbrace
87
+ streamer.rbrace = rbrace
88
+ streamer.is_started = is_started
89
+ return empty
@@ -0,0 +1,20 @@
1
+ import pandas as pd
2
+ from pandas.core.dtypes.common import is_numeric_dtype
3
+ from typing import List, Dict, cast
4
+
5
+
6
+ def dataframe_to_dict(df: pd.DataFrame) -> List[Dict]:
7
+ cols = list(df)
8
+ col_arr_map = {}
9
+ for col in cols:
10
+ if not is_numeric_dtype(df[col].dtype): # 如果是不是数字类型,使用numpy array存储
11
+ col_arr_map[col] = df[col].to_numpy()
12
+ else:
13
+ col_arr_map[col] = df[col].tolist() # 如果是数字类型,则使用python原生list存储
14
+ records = [None] * len(df)
15
+
16
+ for i in range(len(df)):
17
+ record = {col: col_arr_map[col][i] for col in cols}
18
+ records[i] = record
19
+
20
+ return cast(List[Dict], records)
deepfos/cache.py ADDED
@@ -0,0 +1,121 @@
1
+ import functools
2
+ import weakref
3
+ from typing import Protocol
4
+
5
+ from cachetools import TTLCache, LRUCache
6
+
7
+ __all__ = [
8
+ 'Manager',
9
+ 'CustomedCache',
10
+ 'AppSeperatedBase',
11
+ 'SpaceSeperatedBase',
12
+ 'AppSeperatedTTLCache',
13
+ 'SpaceSeperatedTTLCache',
14
+ 'AppSeperatedLRUCache',
15
+ 'SpaceSeperatedLRUCache'
16
+ ]
17
+
18
+
19
+ class CacheProtocol(Protocol): # pragma: no cover
20
+ def clear(self) -> None:
21
+ ...
22
+
23
+
24
+ class CacheManager:
25
+ def __init__(self):
26
+ self._caches = []
27
+
28
+ def create_cache(self, cache_factory, *args, **kwargs) -> CacheProtocol:
29
+ cache = cache_factory(*args, **kwargs)
30
+ self._caches.append(weakref.ref(cache, self._caches.remove))
31
+ return cache
32
+
33
+ def clear(self):
34
+ for cache in self._caches:
35
+ cache().clear()
36
+
37
+ @property
38
+ def currsize(self):
39
+ return len(self._caches)
40
+
41
+ def __repr__(self): # pragma: no cover
42
+ return repr([c() for c in self._caches])
43
+
44
+
45
+ Manager = CacheManager()
46
+
47
+
48
+ class CustomedCache:
49
+ def __init_subclass__(cls, *args, **kwargs):
50
+ if hasattr(cls, 'clear'):
51
+ cls.clear = cls.customed_clear(getattr(cls, 'clear'))
52
+ if hasattr(cls, 'pop'):
53
+ cls.pop = cls.customed_pop(getattr(cls, 'pop'))
54
+
55
+ for funcname in {'__getitem__', '__setitem__', '__delitem__', '__contains__'}:
56
+ if hasattr(cls, funcname):
57
+ setattr(cls, funcname, cls.customize(getattr(cls, funcname)))
58
+
59
+ @staticmethod
60
+ def customize(ori_func):
61
+ @functools.wraps(ori_func)
62
+ def new_func(self, key, *args, **kwargs):
63
+ key = (self.additional_key(), key)
64
+ return ori_func(self, key, *args, **kwargs)
65
+
66
+ return new_func
67
+
68
+ @staticmethod
69
+ def customed_clear(ori_func):
70
+ @functools.wraps(ori_func)
71
+ def new_func(self):
72
+ for k in list(self):
73
+ try:
74
+ del self[k[1]]
75
+ except KeyError:
76
+ pass
77
+
78
+ return new_func
79
+
80
+ @staticmethod
81
+ def customed_pop(ori_func):
82
+ @functools.wraps(ori_func)
83
+ def new_func(self, key, *args, **kwargs):
84
+ key = key[1]
85
+ return ori_func(self, key, *args, **kwargs)
86
+
87
+ return new_func
88
+
89
+ @classmethod
90
+ def additional_key(cls): # pragma: no cover
91
+ raise NotImplementedError
92
+
93
+
94
+ class AppSeperatedBase(CustomedCache):
95
+ @classmethod
96
+ def additional_key(cls):
97
+ from deepfos import OPTION
98
+ return OPTION.api.header.get('app', 'Unknown_app')
99
+
100
+
101
+ class SpaceSeperatedBase(CustomedCache):
102
+ @classmethod
103
+ def additional_key(cls):
104
+ from deepfos import OPTION
105
+ return OPTION.api.header.get('space', 'Unknown_space')
106
+
107
+
108
+ class AppSeperatedTTLCache(TTLCache, AppSeperatedBase):
109
+ pass
110
+
111
+
112
+ class SpaceSeperatedTTLCache(TTLCache, SpaceSeperatedBase):
113
+ pass
114
+
115
+
116
+ class AppSeperatedLRUCache(LRUCache, AppSeperatedBase):
117
+ pass
118
+
119
+
120
+ class SpaceSeperatedLRUCache(LRUCache, SpaceSeperatedBase):
121
+ pass
deepfos/config.py ADDED
@@ -0,0 +1,6 @@
1
+ """
2
+ meta configuration for deepfos package
3
+ """
4
+
5
+ #: 全局变量使用上下文变量
6
+ USE_CONTEXT_OPTION = True
@@ -0,0 +1,27 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from deepfos.lazy import lazify
4
+
5
+ if TYPE_CHECKING: # pragma: no cover
6
+ from .cube import SysCube, Cube, as_function_node
7
+ from .dimension import (
8
+ DimMember, SysDimension, read_expr,
9
+ Dimension, DimExprAnalysor, ElementDimension
10
+ )
11
+ from .logictable import SQLCondition, BaseTable, MetaTable, TreeRenderer
12
+
13
+ lazify(
14
+ {
15
+ 'deepfos.core.cube': (
16
+ 'SysCube', 'Cube', 'as_function_node'
17
+ ),
18
+ 'deepfos.core.dimension': (
19
+ 'DimMember', 'SysDimension', 'read_expr',
20
+ 'Dimension', 'DimExprAnalysor', 'ElementDimension'
21
+ ),
22
+ 'deepfos.core.logictable': (
23
+ 'SQLCondition', 'BaseTable', 'MetaTable', 'TreeRenderer'
24
+ ),
25
+ },
26
+ globals()
27
+ )
@@ -0,0 +1,10 @@
1
+ from .cube import Cube
2
+ from .syscube import SysCube
3
+ from .formula import as_function_node
4
+
5
+
6
+ __all__ = [
7
+ 'Cube',
8
+ 'SysCube',
9
+ 'as_function_node'
10
+ ]