reykit 1.1.40__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 +1 -1
- 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 +0 -0
- reykit/rmonkey.py +0 -0
- reykit/rnet.py +0 -0
- 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 +0 -0
- reykit/rtext.py +0 -0
- reykit/rtime.py +0 -0
- reykit/rwrap.py +257 -260
- reykit/rzip.py +0 -0
- {reykit-1.1.40.dist-info → reykit-1.1.41.dist-info}/METADATA +1 -1
- {reykit-1.1.40.dist-info → reykit-1.1.41.dist-info}/RECORD +7 -7
- {reykit-1.1.40.dist-info → reykit-1.1.41.dist-info}/WHEEL +0 -0
- {reykit-1.1.40.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
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
File without changes
|
reykit/rmonkey.py
CHANGED
File without changes
|
reykit/rnet.py
CHANGED
File without changes
|
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
File without changes
|
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,7 +1,7 @@
|
|
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
7
|
reykit/rlog.py,sha256=krjeLPptPiYgbXd9h4umx4Nf34Bt6jQBT0MEvatVKL4,25572
|
@@ -18,11 +18,11 @@ reykit/rtable.py,sha256=Ua6R1eHMtq4jAaWvfFTsgk-KQmtz5KwuYq4kguzRKaY,12198
|
|
18
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
|