reykit 1.1.39__py3-none-any.whl → 1.1.41__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.
- reykit/__init__.py +0 -0
- reykit/rall.py +0 -0
- reykit/rbase.py +1 -1
- reykit/rdata.py +3 -3
- reykit/rdll/__init__.py +0 -0
- reykit/rdll/rdll_core.py +0 -0
- reykit/remail.py +0 -0
- reykit/rimage.py +0 -0
- reykit/rlog.py +8 -8
- reykit/rmonkey.py +2 -2
- reykit/rnet.py +64 -3
- reykit/rnum.py +0 -0
- reykit/ros.py +0 -0
- reykit/rrand.py +0 -0
- reykit/rre.py +0 -0
- reykit/rschedule.py +0 -0
- reykit/rstdout.py +0 -0
- reykit/rsys.py +0 -0
- reykit/rtable.py +0 -0
- reykit/rtask.py +2 -2
- reykit/rtext.py +0 -0
- reykit/rtime.py +0 -0
- reykit/rwrap.py +257 -260
- reykit/rzip.py +0 -0
- {reykit-1.1.39.dist-info → reykit-1.1.41.dist-info}/METADATA +1 -1
- {reykit-1.1.39.dist-info → reykit-1.1.41.dist-info}/RECORD +11 -11
- {reykit-1.1.39.dist-info → reykit-1.1.41.dist-info}/WHEEL +0 -0
- {reykit-1.1.39.dist-info → reykit-1.1.41.dist-info}/licenses/LICENSE +0 -0
reykit/__init__.py
CHANGED
File without changes
|
reykit/rall.py
CHANGED
File without changes
|
reykit/rbase.py
CHANGED
@@ -946,7 +946,7 @@ def at_exit(*contents: str | Callable | tuple[Callable, Iterable, Mapping]) -> l
|
|
946
946
|
args = ()
|
947
947
|
kwargs = {}
|
948
948
|
if type(content) == str:
|
949
|
-
func = lambda
|
949
|
+
func = lambda: print(content)
|
950
950
|
elif callable(content):
|
951
951
|
func = content
|
952
952
|
elif type(content) == tuple:
|
reykit/rdata.py
CHANGED
@@ -362,7 +362,7 @@ def default_dict(default: T = null, data: dict[KT, VT] | None = None) -> Default
|
|
362
362
|
|
363
363
|
## Not callable.
|
364
364
|
else:
|
365
|
-
default_factory = lambda
|
365
|
+
default_factory = lambda: default
|
366
366
|
|
367
367
|
if data is None:
|
368
368
|
data = {}
|
@@ -409,10 +409,10 @@ class FunctionGenerator(Base):
|
|
409
409
|
self.args = args
|
410
410
|
self.kwargs = kwargs
|
411
411
|
self.params: list[tuple[tuple, dict]] = []
|
412
|
-
self.generator = self.
|
412
|
+
self.generator = self.__generator()
|
413
413
|
|
414
414
|
|
415
|
-
def
|
415
|
+
def __generator(self) -> Generator[Any, Any, None]:
|
416
416
|
"""
|
417
417
|
Create generator.
|
418
418
|
|
reykit/rdll/__init__.py
CHANGED
File without changes
|
reykit/rdll/rdll_core.py
CHANGED
File without changes
|
reykit/remail.py
CHANGED
File without changes
|
reykit/rimage.py
CHANGED
File without changes
|
reykit/rlog.py
CHANGED
@@ -106,7 +106,7 @@ class Log(Base):
|
|
106
106
|
self.logger.setLevel(self.DEBUG)
|
107
107
|
|
108
108
|
|
109
|
-
def
|
109
|
+
def __get_message_stack(self) -> dict:
|
110
110
|
"""
|
111
111
|
Get message stack parameters.
|
112
112
|
|
@@ -145,7 +145,7 @@ class Log(Base):
|
|
145
145
|
return stack_param
|
146
146
|
|
147
147
|
|
148
|
-
def
|
148
|
+
def __supply_format_standard(
|
149
149
|
self,
|
150
150
|
format_: str,
|
151
151
|
record: LogRecord
|
@@ -171,7 +171,7 @@ class Log(Base):
|
|
171
171
|
|
172
172
|
# Format 'format_path'.
|
173
173
|
if '%(format_path)s' in format_:
|
174
|
-
message_stack = self.
|
174
|
+
message_stack = self.__get_message_stack()
|
175
175
|
record.format_path = '%s:%s' % (
|
176
176
|
message_stack['filename'],
|
177
177
|
message_stack['lineno']
|
@@ -213,7 +213,7 @@ class Log(Base):
|
|
213
213
|
return color_code
|
214
214
|
|
215
215
|
|
216
|
-
def
|
216
|
+
def __supply_format_print(
|
217
217
|
self,
|
218
218
|
format_: str,
|
219
219
|
record: LogRecord
|
@@ -267,7 +267,7 @@ class Log(Base):
|
|
267
267
|
)
|
268
268
|
|
269
269
|
|
270
|
-
def
|
270
|
+
def __supply_format_file(
|
271
271
|
self,
|
272
272
|
format_: str,
|
273
273
|
record: LogRecord
|
@@ -326,17 +326,17 @@ class Log(Base):
|
|
326
326
|
"""
|
327
327
|
|
328
328
|
# Format standard.
|
329
|
-
self.
|
329
|
+
self.__supply_format_standard(format_, record)
|
330
330
|
|
331
331
|
match mode:
|
332
332
|
|
333
333
|
# Format print.
|
334
334
|
case 'print':
|
335
|
-
self.
|
335
|
+
self.__supply_format_print(format_, record)
|
336
336
|
|
337
337
|
# Format file.
|
338
338
|
case 'file':
|
339
|
-
self.
|
339
|
+
self.__supply_format_file(format_, record)
|
340
340
|
|
341
341
|
return True
|
342
342
|
|
reykit/rmonkey.py
CHANGED
@@ -259,7 +259,7 @@ def monkey_patch_pprint_modify_width_judgment() -> None:
|
|
259
259
|
|
260
260
|
|
261
261
|
# Define.
|
262
|
-
def
|
262
|
+
def __format(_self, obj, stream, indent, allowance, context, level):
|
263
263
|
|
264
264
|
from .rtext import get_width
|
265
265
|
|
@@ -289,7 +289,7 @@ def monkey_patch_pprint_modify_width_judgment() -> None:
|
|
289
289
|
|
290
290
|
|
291
291
|
# Modify.
|
292
|
-
PrettyPrinter.
|
292
|
+
PrettyPrinter.__format = __format
|
293
293
|
|
294
294
|
|
295
295
|
def monkey_path_pil_image_get_bytes():
|
reykit/rnet.py
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
-
from typing import Any, Literal, TypedDict, NotRequired
|
12
|
+
from typing import Any, Literal, TypedDict, NotRequired, overload
|
13
13
|
from collections.abc import Callable, Iterable
|
14
14
|
from warnings import filterwarnings
|
15
15
|
from os.path import abspath as os_abspath, isfile as os_isfile
|
@@ -206,6 +206,67 @@ def get_content_type(file: str | bytes) -> str | None:
|
|
206
206
|
return file_type
|
207
207
|
|
208
208
|
|
209
|
+
@overload
|
210
|
+
def request(
|
211
|
+
url: str,
|
212
|
+
params: dict | None = None,
|
213
|
+
*,
|
214
|
+
headers: dict[str, str] = {},
|
215
|
+
timeout: float | None = None,
|
216
|
+
proxies: dict[str, str] = {},
|
217
|
+
stream: bool = False,
|
218
|
+
verify: bool = False,
|
219
|
+
method: Literal['get', 'post', 'put', 'patch', 'delete', 'options', 'head'] = Literal['get'],
|
220
|
+
check: bool | int | Iterable[int] = False
|
221
|
+
) -> Response: ...
|
222
|
+
|
223
|
+
@overload
|
224
|
+
def request(
|
225
|
+
url: str,
|
226
|
+
params: dict | None = None,
|
227
|
+
*,
|
228
|
+
data: dict | str | bytes,
|
229
|
+
files: dict[str, str | bytes | tuple[str | bytes, dict]] | None = None,
|
230
|
+
headers: dict[str, str] = {},
|
231
|
+
timeout: float | None = None,
|
232
|
+
proxies: dict[str, str] = {},
|
233
|
+
stream: bool = False,
|
234
|
+
verify: bool = False,
|
235
|
+
method: Literal['get', 'post', 'put', 'patch', 'delete', 'options', 'head'] | None = Literal['post'],
|
236
|
+
check: bool | int | Iterable[int] = False
|
237
|
+
) -> Response: ...
|
238
|
+
|
239
|
+
@overload
|
240
|
+
def request(
|
241
|
+
url: str,
|
242
|
+
params: dict | None = None,
|
243
|
+
*,
|
244
|
+
data: dict | str | bytes | None = None,
|
245
|
+
files: dict[str, str | bytes | tuple[str | bytes, dict]],
|
246
|
+
headers: dict[str, str] = {},
|
247
|
+
timeout: float | None = None,
|
248
|
+
proxies: dict[str, str] = {},
|
249
|
+
stream: bool = False,
|
250
|
+
verify: bool = False,
|
251
|
+
method: Literal['get', 'post', 'put', 'patch', 'delete', 'options', 'head'] | None = Literal['post'],
|
252
|
+
check: bool | int | Iterable[int] = False
|
253
|
+
) -> Response: ...
|
254
|
+
|
255
|
+
@overload
|
256
|
+
def request(
|
257
|
+
url: str,
|
258
|
+
params: dict | None = None,
|
259
|
+
*,
|
260
|
+
json: dict,
|
261
|
+
headers: dict[str, str] = {},
|
262
|
+
timeout: float | None = None,
|
263
|
+
proxies: dict[str, str] = {},
|
264
|
+
stream: bool = False,
|
265
|
+
verify: bool = False,
|
266
|
+
method: Literal['get', 'post', 'put', 'patch', 'delete', 'options', 'head'] | None = Literal['post'],
|
267
|
+
check: bool | int | Iterable[int] = False
|
268
|
+
) -> Response: ...
|
269
|
+
|
209
270
|
def request(
|
210
271
|
url: str,
|
211
272
|
params: dict | None = None,
|
@@ -498,7 +559,7 @@ class RequestCache(Base):
|
|
498
559
|
|
499
560
|
|
500
561
|
@property
|
501
|
-
def
|
562
|
+
def __start_params(self) -> RequestCacheParameters:
|
502
563
|
"""
|
503
564
|
Get cache start parameters.
|
504
565
|
|
@@ -537,7 +598,7 @@ class RequestCache(Base):
|
|
537
598
|
"""
|
538
599
|
|
539
600
|
# Start.
|
540
|
-
requests_cache_install_cache(**self.
|
601
|
+
requests_cache_install_cache(**self.__start_params)
|
541
602
|
|
542
603
|
|
543
604
|
def stop(self) -> None:
|
reykit/rnum.py
CHANGED
File without changes
|
reykit/ros.py
CHANGED
File without changes
|
reykit/rrand.py
CHANGED
File without changes
|
reykit/rre.py
CHANGED
File without changes
|
reykit/rschedule.py
CHANGED
File without changes
|
reykit/rstdout.py
CHANGED
File without changes
|
reykit/rsys.py
CHANGED
File without changes
|
reykit/rtable.py
CHANGED
File without changes
|
reykit/rtask.py
CHANGED
@@ -684,11 +684,11 @@ class AsyncPool(Base):
|
|
684
684
|
self.futures: list[AFuture] = []
|
685
685
|
|
686
686
|
# Start.
|
687
|
-
self.
|
687
|
+
self.__start_loop()
|
688
688
|
|
689
689
|
|
690
690
|
@wrap_thread
|
691
|
-
def
|
691
|
+
def __start_loop(self) -> None:
|
692
692
|
"""
|
693
693
|
Start event loop.
|
694
694
|
"""
|
reykit/rtext.py
CHANGED
File without changes
|
reykit/rtime.py
CHANGED
File without changes
|
reykit/rwrap.py
CHANGED
@@ -10,21 +10,23 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
from typing import Any, Literal, overload
|
13
|
+
from types import TracebackType
|
13
14
|
from collections.abc import Callable
|
14
15
|
from io import IOBase, StringIO
|
15
|
-
from inspect import getdoc
|
16
|
-
from functools import wraps as functools_wraps
|
16
|
+
from inspect import getdoc as inspect_getdoc
|
17
|
+
from functools import wraps as functools_wraps, partial as functools_partial
|
18
|
+
from datetime import datetime as Datetime, timedelta as Timedelta
|
17
19
|
from threading import Thread
|
18
20
|
from argparse import ArgumentParser
|
19
21
|
from contextlib import redirect_stdout
|
20
22
|
|
21
|
-
from .rbase import catch_exc, get_arg_info
|
23
|
+
from .rbase import T, U, V, catch_exc, get_arg_info
|
22
24
|
from .rstdout import echo
|
23
25
|
from .rtime import now, time_to, TimeMark
|
24
26
|
|
25
27
|
|
26
28
|
__all__ = (
|
27
|
-
'
|
29
|
+
'wrap_wrap',
|
28
30
|
'wrap_runtime',
|
29
31
|
'wrap_thread',
|
30
32
|
'wrap_exc',
|
@@ -36,13 +38,17 @@ __all__ = (
|
|
36
38
|
)
|
37
39
|
|
38
40
|
|
39
|
-
|
41
|
+
type Decorated = Callable
|
42
|
+
type Decorator = Callable[..., Decorated]
|
43
|
+
|
44
|
+
|
45
|
+
def wrap_wrap(decorator: Decorator) -> Decorator:
|
40
46
|
"""
|
41
|
-
|
47
|
+
Decorate decorator.
|
42
48
|
|
43
49
|
Parameters
|
44
50
|
----------
|
45
|
-
decorator : Decorator
|
51
|
+
decorator : Decorator.
|
46
52
|
|
47
53
|
Retuens
|
48
54
|
-------
|
@@ -50,140 +56,138 @@ def wrap_frame(decorator: Callable) -> Callable:
|
|
50
56
|
|
51
57
|
Examples
|
52
58
|
--------
|
53
|
-
|
59
|
+
>>> @wrap_wrap
|
60
|
+
>>> def wrap_func(func, args, kwargs, **wrap_kwargs): ...
|
61
|
+
|
62
|
+
Method one.
|
54
63
|
>>> @wrap_func
|
55
|
-
>>> def func(): ...
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
>>> def func(): ...
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
>>>
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
>>>
|
64
|
+
>>> def func(*args, **kwargs): ...
|
65
|
+
|
66
|
+
Method two.
|
67
|
+
>>> @wrap_func(**wrap_kwargs)
|
68
|
+
>>> def func(*args, **kwargs): ...
|
69
|
+
|
70
|
+
Method three.
|
71
|
+
>>> def func(*args, **kwargs): ...
|
72
|
+
>>> func = wrap_func(func, **wrap_kwargs)
|
73
|
+
|
74
|
+
Method four.
|
75
|
+
>>> def func(*args, **kwargs): ...
|
76
|
+
>>> wrap_func = wrap_func(**wrap_kwargs)
|
68
77
|
>>> func = wrap_func(func)
|
69
|
-
>>> result = func(param_a, param_b, param_c=1, param_d=2)
|
70
78
|
|
71
|
-
|
72
|
-
>>> def func(): ...
|
73
|
-
>>> func = wrap_func(func, param_a, param_c=1, _execute=False)
|
74
|
-
>>> result = func(param_b, param_d=2)
|
79
|
+
>>> func(*args, **kwargs)
|
75
80
|
"""
|
76
81
|
|
77
82
|
|
78
83
|
# Decorate Decorator.
|
79
84
|
@overload
|
80
|
-
def
|
81
|
-
|
82
|
-
@overload
|
83
|
-
def wrap(func: Callable, /, *args: Any, _execute: Literal[True], **kwargs: Any) -> Any: ...
|
85
|
+
def _wrap(func: Callable, **wrap_kwargs: Any) -> Decorated: ...
|
84
86
|
|
85
87
|
@overload
|
86
|
-
def
|
88
|
+
def _wrap(**wrap_kwargs: Any) -> Decorator: ...
|
87
89
|
|
88
90
|
@functools_wraps(decorator)
|
89
|
-
def
|
91
|
+
def _wrap(func: Callable | None = None, **wrap_kwargs: Any) -> Decorated | Decorator:
|
90
92
|
"""
|
91
|
-
|
93
|
+
Decorated decorator.
|
92
94
|
|
93
95
|
Parameters
|
94
96
|
----------
|
95
97
|
func : Function.
|
96
|
-
|
97
|
-
_execute : Whether execute function, otherwise decorate function.
|
98
|
-
- `None`, When parameter `args` or `kwargs`: have values, then True, otherwise False.
|
99
|
-
- `bool`: Use this value.
|
100
|
-
kwargs : Keyword arguments of function.
|
98
|
+
wrap_kwargs : Keyword arguments of decorator.
|
101
99
|
|
102
100
|
Returns
|
103
101
|
-------
|
104
|
-
Decorated function or
|
102
|
+
Decorated function or decorated self.
|
105
103
|
"""
|
106
104
|
|
107
|
-
#
|
108
|
-
if
|
109
|
-
if args != () or kwargs != {}:
|
110
|
-
_execute = True
|
111
|
-
else:
|
112
|
-
_execute = False
|
105
|
+
# Method one and three.
|
106
|
+
if func is not None:
|
113
107
|
|
114
|
-
# Direct execution.
|
115
|
-
if _execute:
|
116
|
-
result = decorator(func, *args, **kwargs)
|
117
|
-
return result
|
118
108
|
|
109
|
+
@functools_wraps(func)
|
110
|
+
def _func(*args: Any, **kwargs: Any) -> Any:
|
111
|
+
"""
|
112
|
+
Decorated function.
|
119
113
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
Decorative sub shell.
|
114
|
+
Parameters
|
115
|
+
----------
|
116
|
+
args : Position arguments of function.
|
117
|
+
kwargs : Keyword arguments of function.
|
125
118
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
119
|
+
Returns
|
120
|
+
-------
|
121
|
+
Function return.
|
122
|
+
"""
|
130
123
|
|
131
|
-
|
132
|
-
|
133
|
-
Function return.
|
134
|
-
"""
|
124
|
+
# Decorate function.
|
125
|
+
result = decorator(func, args, kwargs, **wrap_kwargs)
|
135
126
|
|
136
|
-
|
137
|
-
result = decorator(func, *args, *_args, **kwargs, **_kwargs)
|
127
|
+
return result
|
138
128
|
|
139
|
-
|
129
|
+
|
130
|
+
return _func
|
140
131
|
|
141
132
|
|
142
|
-
|
133
|
+
# Method two and four.
|
134
|
+
else:
|
135
|
+
__wrap = functools_partial(_wrap, **wrap_kwargs)
|
136
|
+
return __wrap
|
143
137
|
|
144
138
|
|
145
|
-
return
|
139
|
+
return _wrap
|
146
140
|
|
147
141
|
|
148
142
|
@overload
|
149
143
|
def wrap_runtime(
|
150
|
-
func: Callable,
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
**kwargs: Any
|
155
|
-
) -> Any: ...
|
144
|
+
func: Callable[..., T],
|
145
|
+
*,
|
146
|
+
to_print: bool = True
|
147
|
+
) -> Callable[..., T]: ...
|
156
148
|
|
157
149
|
@overload
|
158
150
|
def wrap_runtime(
|
159
|
-
func: Callable,
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
**kwargs: Any
|
164
|
-
) -> tuple[Any, str]: ...
|
151
|
+
func: Callable[..., T],
|
152
|
+
to_return: Literal[True],
|
153
|
+
to_print: bool = True
|
154
|
+
) -> Callable[..., tuple[T, str, Datetime, Timedelta, Datetime]]: ...
|
165
155
|
|
166
|
-
@
|
156
|
+
@overload
|
167
157
|
def wrap_runtime(
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
158
|
+
*,
|
159
|
+
to_print: bool = True
|
160
|
+
) -> Callable[[Callable[..., T]], T]: ...
|
161
|
+
|
162
|
+
@overload
|
163
|
+
def wrap_runtime(
|
164
|
+
*,
|
165
|
+
to_return: Literal[True],
|
166
|
+
to_print: bool = True
|
167
|
+
) -> Callable[[Callable[..., T]], tuple[T, str, Datetime, Timedelta, Datetime]]: ...
|
168
|
+
|
169
|
+
@wrap_wrap
|
170
|
+
def wrap_runtime(
|
171
|
+
func: Callable[..., T],
|
172
|
+
args: Any,
|
173
|
+
kwargs: Any,
|
174
|
+
to_return: bool = False,
|
175
|
+
to_print: bool = True
|
176
|
+
) -> T | tuple[T, str, Datetime, Timedelta, Datetime]:
|
174
177
|
"""
|
175
|
-
Decorator, print or return runtime
|
178
|
+
Decorator, print or return runtime data of the function.
|
176
179
|
|
177
180
|
Parameters
|
178
181
|
----------
|
179
|
-
func : Function
|
180
|
-
args : Position arguments of
|
181
|
-
|
182
|
-
|
182
|
+
func : Function.
|
183
|
+
args : Position arguments of function.
|
184
|
+
kwargs : Keyword arguments of function.
|
185
|
+
to_print : Whether to print runtime.
|
186
|
+
to_return : Whether to return runtime.
|
183
187
|
|
184
188
|
Returns
|
185
189
|
-------
|
186
|
-
Function
|
190
|
+
Function return or runtime data.
|
187
191
|
"""
|
188
192
|
|
189
193
|
# Execute function and marking time.
|
@@ -194,7 +198,7 @@ def wrap_runtime(
|
|
194
198
|
|
195
199
|
# Generate report.
|
196
200
|
start_time = rtm.record[0]['datetime']
|
197
|
-
spend_time = rtm.record[1]['timedelta']
|
201
|
+
spend_time: Timedelta = rtm.record[1]['timedelta']
|
198
202
|
end_time = rtm.record[1]['datetime']
|
199
203
|
start_str = time_to(start_time, True)[:-3]
|
200
204
|
spend_str = time_to(spend_time, True)[:-3]
|
@@ -206,12 +210,13 @@ def wrap_runtime(
|
|
206
210
|
)
|
207
211
|
title = func.__name__
|
208
212
|
|
209
|
-
#
|
210
|
-
if
|
211
|
-
|
213
|
+
# Print.
|
214
|
+
if to_print:
|
215
|
+
echo(report, title=title)
|
212
216
|
|
213
|
-
#
|
214
|
-
|
217
|
+
# Return.
|
218
|
+
if to_return:
|
219
|
+
return result, report, start_time, spend_time, end_time
|
215
220
|
|
216
221
|
return result
|
217
222
|
|
@@ -219,33 +224,35 @@ def wrap_runtime(
|
|
219
224
|
@overload
|
220
225
|
def wrap_thread(
|
221
226
|
func: Callable,
|
222
|
-
|
223
|
-
|
224
|
-
_daemon: bool = True,
|
225
|
-
**kwargs: Any
|
226
|
-
) -> Thread: ...
|
227
|
+
daemon: bool = True
|
228
|
+
) -> Callable[..., Thread]: ...
|
227
229
|
|
228
|
-
@
|
230
|
+
@overload
|
231
|
+
def wrap_thread(
|
232
|
+
*,
|
233
|
+
daemon: bool = True
|
234
|
+
) -> Callable[[Callable], Thread]: ...
|
235
|
+
|
236
|
+
@wrap_wrap
|
229
237
|
def wrap_thread(
|
230
238
|
func: Callable,
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
**kwargs: Any
|
239
|
+
args: Any,
|
240
|
+
kwargs: Any,
|
241
|
+
daemon: bool = True
|
235
242
|
) -> Thread:
|
236
243
|
"""
|
237
244
|
Decorator, function start in thread.
|
238
245
|
|
239
246
|
Parameters
|
240
247
|
----------
|
241
|
-
func : Function
|
242
|
-
args : Position arguments of
|
243
|
-
|
244
|
-
|
248
|
+
func : Function.
|
249
|
+
args : Position arguments of function.
|
250
|
+
kwargs : Keyword arguments of function.
|
251
|
+
daemon : Whether it is a daemon thread.
|
245
252
|
|
246
253
|
Returns
|
247
254
|
-------
|
248
|
-
Thread
|
255
|
+
Thread instance.
|
249
256
|
"""
|
250
257
|
|
251
258
|
# Handle parameter.
|
@@ -253,7 +260,7 @@ def wrap_thread(
|
|
253
260
|
|
254
261
|
# Create thread.
|
255
262
|
thread = Thread(target=func, name=thread_name, args=args, kwargs=kwargs)
|
256
|
-
thread.daemon =
|
263
|
+
thread.daemon = daemon
|
257
264
|
|
258
265
|
# Start thread.
|
259
266
|
thread.start()
|
@@ -263,37 +270,40 @@ def wrap_thread(
|
|
263
270
|
|
264
271
|
@overload
|
265
272
|
def wrap_exc(
|
266
|
-
func: Callable,
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
) -> Any | None: ...
|
273
|
-
|
274
|
-
@wrap_frame
|
273
|
+
func: Callable[..., T],
|
274
|
+
handler: Callable[[tuple[str, type[BaseException], BaseException, TracebackType]], Any],
|
275
|
+
exception: BaseException | tuple[BaseException, ...] | None = BaseException
|
276
|
+
) -> Callable[..., T | None]: ...
|
277
|
+
|
278
|
+
@overload
|
275
279
|
def wrap_exc(
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
280
|
+
*,
|
281
|
+
handler: Callable[[tuple[str, type[BaseException], BaseException, TracebackType]], Any],
|
282
|
+
exception: BaseException | tuple[BaseException, ...] | None = BaseException
|
283
|
+
) -> Callable[[Callable[..., T]], T | None]: ...
|
284
|
+
|
285
|
+
@wrap_wrap
|
286
|
+
def wrap_exc(
|
287
|
+
func: Callable[..., T],
|
288
|
+
args: Any,
|
289
|
+
kwargs: Any,
|
290
|
+
handler: Callable[[tuple[str, type[BaseException], BaseException, TracebackType]], Any],
|
291
|
+
exception: BaseException | tuple[BaseException, ...] | None = BaseException
|
292
|
+
) -> T | None:
|
283
293
|
"""
|
284
|
-
Decorator, execute function with `try` and
|
294
|
+
Decorator, execute function with `try` syntax and handle exception.
|
285
295
|
|
286
296
|
Parameters
|
287
297
|
----------
|
288
|
-
func : Function
|
289
|
-
args : Position arguments of
|
290
|
-
|
291
|
-
|
292
|
-
|
298
|
+
func : Function.
|
299
|
+
args : Position arguments of function.
|
300
|
+
kwargs : Keyword arguments of function.
|
301
|
+
handler : Exception handler.
|
302
|
+
exception : Catch exception type.
|
293
303
|
|
294
304
|
Returns
|
295
305
|
-------
|
296
|
-
|
306
|
+
Function return.
|
297
307
|
"""
|
298
308
|
|
299
309
|
# Execute function.
|
@@ -301,130 +311,112 @@ def wrap_exc(
|
|
301
311
|
result = func(*args, **kwargs)
|
302
312
|
|
303
313
|
# Handle exception.
|
304
|
-
except
|
305
|
-
|
306
|
-
|
307
|
-
else:
|
308
|
-
result = None
|
314
|
+
except exception:
|
315
|
+
exc_report, exc_type, exc_instance, exc_traceback = catch_exc()
|
316
|
+
handler(exc_report, exc_type, exc_instance, exc_traceback)
|
309
317
|
|
310
|
-
|
318
|
+
else:
|
319
|
+
return result
|
311
320
|
|
312
321
|
|
313
322
|
@overload
|
314
323
|
def wrap_retry(
|
315
|
-
func: Callable,
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
**kwargs: Any
|
323
|
-
) -> Any: ...
|
324
|
-
|
325
|
-
@wrap_frame
|
324
|
+
func: Callable[..., T],
|
325
|
+
total: int = 1,
|
326
|
+
handler: Callable[[tuple[str, type[BaseException], BaseException, TracebackType]], Any] | None = None,
|
327
|
+
exception: BaseException | tuple[BaseException, ...] = BaseException
|
328
|
+
) -> Callable[..., T]: ...
|
329
|
+
|
330
|
+
@overload
|
326
331
|
def wrap_retry(
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
332
|
+
*,
|
333
|
+
total: int = 1,
|
334
|
+
handler: Callable[[tuple[str, type[BaseException], BaseException, TracebackType]], Any] | None = None,
|
335
|
+
exception: BaseException | tuple[BaseException, ...] = BaseException
|
336
|
+
) -> Callable[[Callable[..., T]], T]: ...
|
337
|
+
|
338
|
+
@wrap_wrap
|
339
|
+
def wrap_retry(
|
340
|
+
func: Callable[..., T],
|
341
|
+
args: Any,
|
342
|
+
kwargs: Any,
|
343
|
+
total: int = 2,
|
344
|
+
handler: Callable[[tuple[str, type[BaseException], BaseException, TracebackType]], Any] | None = None,
|
345
|
+
exception: BaseException | tuple[BaseException, ...] = BaseException
|
346
|
+
) -> T:
|
336
347
|
"""
|
337
|
-
Decorator, try again.
|
348
|
+
Decorator, try again and handle exception.
|
338
349
|
|
339
350
|
Parameters
|
340
351
|
----------
|
341
|
-
func : Function
|
342
|
-
args : Position arguments of
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
_try_total : Retry total.
|
348
|
-
_try_count : Retry count.
|
349
|
-
kwargs : Keyword arguments of decorated function.
|
352
|
+
func : Function.
|
353
|
+
args : Position arguments of function.
|
354
|
+
kwargs : Keyword arguments of function.
|
355
|
+
total : Retry total.
|
356
|
+
handler : Exception handler.
|
357
|
+
exception : Catch exception type.
|
350
358
|
|
351
359
|
Returns
|
352
360
|
-------
|
353
|
-
Function
|
361
|
+
Function return.
|
354
362
|
"""
|
355
363
|
|
356
|
-
#
|
357
|
-
|
364
|
+
# Loop.
|
365
|
+
for _ in range(0, total - 1):
|
358
366
|
|
359
|
-
|
367
|
+
# Try.
|
360
368
|
try:
|
361
369
|
result = func(*args, **kwargs)
|
362
|
-
except _exception:
|
363
|
-
|
364
|
-
## Report.
|
365
|
-
if _report is not None:
|
366
|
-
exc_report, *_ = catch_exc()
|
367
|
-
echo(
|
368
|
-
exc_report,
|
369
|
-
'Retrying...',
|
370
|
-
title=_report,
|
371
|
-
frame='half'
|
372
|
-
)
|
373
|
-
|
374
|
-
### Retry.
|
375
|
-
_try_count += 1
|
376
|
-
result = wrap_retry(
|
377
|
-
func,
|
378
|
-
*args,
|
379
|
-
_report=_report,
|
380
|
-
_exception=_exception,
|
381
|
-
_try_total=_try_total,
|
382
|
-
_try_count=_try_count,
|
383
|
-
**kwargs
|
384
|
-
)
|
385
370
|
|
386
|
-
|
387
|
-
|
388
|
-
|
371
|
+
## Handle.
|
372
|
+
except exception:
|
373
|
+
if handler is not None:
|
374
|
+
exc_report, exc_type, exc_instance, exc_traceback = catch_exc()
|
375
|
+
handler(exc_report, exc_type, exc_instance, exc_traceback)
|
376
|
+
|
377
|
+
else:
|
378
|
+
return result
|
379
|
+
|
380
|
+
# Last.
|
381
|
+
result = func(*args, **kwargs)
|
389
382
|
|
390
383
|
return result
|
391
384
|
|
392
385
|
|
393
386
|
@overload
|
394
387
|
def wrap_dos_command(
|
395
|
-
func: Callable
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
) ->
|
388
|
+
func: Callable[..., T]
|
389
|
+
) -> Callable[..., T]: ...
|
390
|
+
|
391
|
+
@overload
|
392
|
+
def wrap_dos_command() -> Callable[[Callable[..., T]], T]: ...
|
400
393
|
|
401
|
-
@
|
394
|
+
@wrap_wrap
|
402
395
|
def wrap_dos_command(
|
403
|
-
func: Callable,
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
) -> Any:
|
396
|
+
func: Callable[..., T],
|
397
|
+
args: Any,
|
398
|
+
kwargs: Any,
|
399
|
+
) -> T:
|
408
400
|
"""
|
409
401
|
Decorator, use DOS command to input arguments to function.
|
410
402
|
Use DOS command `python file --help` to view help information.
|
411
403
|
|
412
404
|
Parameters
|
413
405
|
----------
|
414
|
-
func : Function
|
415
|
-
args : Position arguments of
|
416
|
-
kwargs : Keyword arguments of
|
406
|
+
func : Function.
|
407
|
+
args : Position arguments of function.
|
408
|
+
kwargs : Keyword arguments of function.
|
417
409
|
|
418
410
|
Returns
|
419
411
|
-------
|
420
|
-
Function
|
412
|
+
Function return.
|
421
413
|
"""
|
422
414
|
|
423
415
|
# Get parameter.
|
424
416
|
arg_info = get_arg_info(func)
|
425
417
|
|
426
418
|
# Set DOS command.
|
427
|
-
usage =
|
419
|
+
usage = inspect_getdoc(func)
|
428
420
|
if usage is not None:
|
429
421
|
usage = 'input arguments to function "%s"\n\n%s' % (func.__name__, usage)
|
430
422
|
parser = ArgumentParser(usage=usage)
|
@@ -519,21 +511,23 @@ wrap_cache_data: dict[Callable, list[tuple[Any, Any, Any]]] = {}
|
|
519
511
|
|
520
512
|
@overload
|
521
513
|
def wrap_cache(
|
522
|
-
func: Callable,
|
523
|
-
|
524
|
-
|
525
|
-
_overwrite: bool = False,
|
526
|
-
**kwargs: Any
|
527
|
-
) -> Any: ...
|
514
|
+
func: Callable[..., T],
|
515
|
+
overwrite: bool = False
|
516
|
+
) -> Callable[..., T]: ...
|
528
517
|
|
529
|
-
@
|
518
|
+
@overload
|
530
519
|
def wrap_cache(
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
520
|
+
*,
|
521
|
+
overwrite: bool = False
|
522
|
+
) -> Callable[[Callable[..., T]], T]: ...
|
523
|
+
|
524
|
+
@wrap_wrap
|
525
|
+
def wrap_cache(
|
526
|
+
func: Callable[..., T],
|
527
|
+
args: Any,
|
528
|
+
kwargs: Any,
|
529
|
+
overwrite: bool = False
|
530
|
+
) -> T:
|
537
531
|
"""
|
538
532
|
Decorator, Cache the return result of function input.
|
539
533
|
if no cache, cache it.
|
@@ -541,14 +535,14 @@ def wrap_cache(
|
|
541
535
|
|
542
536
|
Parameters
|
543
537
|
----------
|
544
|
-
func : Function
|
545
|
-
args : Position arguments of
|
546
|
-
|
547
|
-
|
538
|
+
func : Function.
|
539
|
+
args : Position arguments of function.
|
540
|
+
kwargs : Keyword arguments of function.
|
541
|
+
overwrite : Whether to overwrite cache.
|
548
542
|
|
549
543
|
Returns
|
550
544
|
-------
|
551
|
-
Function
|
545
|
+
Function return.
|
552
546
|
"""
|
553
547
|
|
554
548
|
# Index.
|
@@ -559,7 +553,7 @@ def wrap_cache(
|
|
559
553
|
cache_args == args
|
560
554
|
and cache_kwargs == kwargs
|
561
555
|
):
|
562
|
-
if
|
556
|
+
if overwrite:
|
563
557
|
cache_index = index
|
564
558
|
break
|
565
559
|
else:
|
@@ -580,39 +574,42 @@ def wrap_cache(
|
|
580
574
|
|
581
575
|
@overload
|
582
576
|
def wrap_redirect_stdout(
|
583
|
-
func: Callable,
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
**kwargs: Any
|
588
|
-
) -> Any: ...
|
577
|
+
func: Callable[..., T],
|
578
|
+
*,
|
579
|
+
redirect: list | IOBase | None = None
|
580
|
+
) -> Callable[..., T]: ...
|
589
581
|
|
590
|
-
@
|
582
|
+
@overload
|
591
583
|
def wrap_redirect_stdout(
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
584
|
+
*,
|
585
|
+
redirect: list | IOBase | None = None
|
586
|
+
) -> Callable[[Callable[..., T]], T]: ...
|
587
|
+
|
588
|
+
@wrap_wrap
|
589
|
+
def wrap_redirect_stdout(
|
590
|
+
func: Callable[..., T],
|
591
|
+
args: Any,
|
592
|
+
kwargs: Any,
|
593
|
+
redirect: list | IOBase | None = None
|
594
|
+
) -> T:
|
598
595
|
"""
|
599
596
|
Redirect standard output.
|
600
597
|
|
601
598
|
Parameters
|
602
599
|
----------
|
603
|
-
func : Function
|
604
|
-
args : Position arguments of
|
605
|
-
|
606
|
-
|
600
|
+
func : Function.
|
601
|
+
args : Position arguments of function.
|
602
|
+
kwargs : Keyword arguments of function.
|
603
|
+
redirect : Redirect output list or IO object.
|
607
604
|
|
608
605
|
Returns
|
609
606
|
-------
|
610
|
-
Function
|
607
|
+
Function return.
|
611
608
|
"""
|
612
609
|
|
613
610
|
# Get parameter.
|
614
|
-
if isinstance(
|
615
|
-
str_io =
|
611
|
+
if isinstance(redirect, IOBase):
|
612
|
+
str_io = redirect
|
616
613
|
else:
|
617
614
|
str_io = StringIO()
|
618
615
|
|
@@ -621,8 +618,8 @@ def wrap_redirect_stdout(
|
|
621
618
|
result = func(*args, **kwargs)
|
622
619
|
|
623
620
|
# Save.
|
624
|
-
if type(
|
621
|
+
if type(redirect) == list:
|
625
622
|
value = str_io.getvalue()
|
626
|
-
|
623
|
+
redirect.append(value)
|
627
624
|
|
628
625
|
return result
|
reykit/rzip.py
CHANGED
File without changes
|
@@ -1,12 +1,12 @@
|
|
1
1
|
reykit/__init__.py,sha256=V86CHqPAAVkooVx3_QIOKpDIFVneQCTTSwfJ-uWgBno,788
|
2
2
|
reykit/rall.py,sha256=7Hip02YOkIDm3_xkoSDjvvYV2LhdBV2r4UKzWWnIfIo,628
|
3
|
-
reykit/rbase.py,sha256=
|
4
|
-
reykit/rdata.py,sha256=
|
3
|
+
reykit/rbase.py,sha256=KDiGiMwj-7u5sfGOPMEb4AgrWfJbUZqpFCYHIKs3O9w,22115
|
4
|
+
reykit/rdata.py,sha256=DqxoWkbN3WqGZ5FC9VRlhXAwpTGebv1M5VSeOeR2YnQ,10308
|
5
5
|
reykit/remail.py,sha256=s7TXbLgEWEqNoeM42c6FpPufB2LajHgQuahfZri3urQ,6706
|
6
6
|
reykit/rimage.py,sha256=p7caatLE71yy7GUTkTKyMOaJTeBfl6pZr_7BFjcDvY8,6159
|
7
|
-
reykit/rlog.py,sha256=
|
8
|
-
reykit/rmonkey.py,sha256=
|
9
|
-
reykit/rnet.py,sha256=
|
7
|
+
reykit/rlog.py,sha256=krjeLPptPiYgbXd9h4umx4Nf34Bt6jQBT0MEvatVKL4,25572
|
8
|
+
reykit/rmonkey.py,sha256=M-W19Q9OwuYWebLlJK4kpYhUOWufgtahDTAZVPbn83s,8143
|
9
|
+
reykit/rnet.py,sha256=zvEWAM42jAdQT868FFDrm-OPn5f3SNfMZP-bU8Sbx0A,16934
|
10
10
|
reykit/rnum.py,sha256=PhG4V_BkVfCJUsbpMDN1umGZly1Hsus80TW8bpyBtyY,3653
|
11
11
|
reykit/ros.py,sha256=xR79PnSlpHvHsoVKHWvEagreQB24N41XHq-psHQhlMI,40818
|
12
12
|
reykit/rrand.py,sha256=9QPXCsREIu45g6WP-XN67X05kmW3cTmctn3InvqYxuY,8947
|
@@ -15,14 +15,14 @@ reykit/rschedule.py,sha256=_nrfrXYxlFAKCDbM8ibTTb60zNDlHxyE310cv-A19Kw,5799
|
|
15
15
|
reykit/rstdout.py,sha256=Vgqm66rtjIaYWO-EFEm9PGzgXDzZXZGq-BS1Lg6zD40,8197
|
16
16
|
reykit/rsys.py,sha256=8Q9ZdggxRHXHMOwjMQa_kBN3gTkmpduHoXrKfa5UXqs,24933
|
17
17
|
reykit/rtable.py,sha256=Ua6R1eHMtq4jAaWvfFTsgk-KQmtz5KwuYq4kguzRKaY,12198
|
18
|
-
reykit/rtask.py,sha256=
|
18
|
+
reykit/rtask.py,sha256=98iCzNdJ_fFRDyOLjXEFNW3tzdAwXcCF7JkZ7Gf0fEE,22848
|
19
19
|
reykit/rtext.py,sha256=sFp5n5ykD6B812Bywhe6gqzscNmx-U6w80Zf8p1y-Ow,12859
|
20
20
|
reykit/rtime.py,sha256=PfhsXZLmSsKY2W1A0VrjhaVbMKVBHBD86AZ8nowNGig,17008
|
21
|
-
reykit/rwrap.py,sha256=
|
21
|
+
reykit/rwrap.py,sha256=gerzOTixYv4uufu3u6VnHhrjNaUZbaTZgVCLzsGaRGQ,15329
|
22
22
|
reykit/rzip.py,sha256=ABUDLwEHQIpcvZbJE_oV78H7dik6nC7kaRz660Ro9Os,3481
|
23
23
|
reykit/rdll/__init__.py,sha256=1VRawI2vCsLH7KK0PcBRWNc-bwseM-M05wkc_eamwJM,696
|
24
24
|
reykit/rdll/rdll_core.py,sha256=o6-rKcTQgxZQe0kD3GnwyNb3KL9IogzgCQNOmYLMm7A,5086
|
25
|
-
reykit-1.1.
|
26
|
-
reykit-1.1.
|
27
|
-
reykit-1.1.
|
28
|
-
reykit-1.1.
|
25
|
+
reykit-1.1.41.dist-info/METADATA,sha256=k5-h63vlGnc4U_Owg4cN1PVW77U8RrDrnhWjd9oZgVs,1872
|
26
|
+
reykit-1.1.41.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
27
|
+
reykit-1.1.41.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
28
|
+
reykit-1.1.41.dist-info/RECORD,,
|
File without changes
|
File without changes
|