reykit 1.1.26__py3-none-any.whl → 1.1.28__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/rtask.py CHANGED
@@ -30,9 +30,8 @@ from asyncio import (
30
30
  )
31
31
  from aiohttp import ClientSession, ClientResponse
32
32
 
33
- from .rexc import throw, check_most_one, check_response_code
33
+ from .rbase import T, Base, throw, check_most_one, check_response_code
34
34
  from .rtime import randn, TimeMark
35
- from .rtype import T, Base
36
35
  from .rwrap import wrap_thread
37
36
 
38
37
 
@@ -371,48 +370,24 @@ def async_run(
371
370
 
372
371
 
373
372
  @overload
374
- async def async_sleep(
375
- *,
376
- precision: None = None
377
- ) -> int: ...
373
+ async def async_sleep() -> int: ...
378
374
 
379
375
  @overload
380
- async def async_sleep(
381
- second: int,
382
- *,
383
- precision: None = None
384
- ) -> int: ...
376
+ async def async_sleep(second: int) -> int: ...
385
377
 
386
378
  @overload
387
- async def async_sleep(
388
- low: int = 0,
389
- high: int = 10,
390
- *,
391
- precision: None = None
392
- ) -> int: ...
379
+ async def async_sleep(low: int = 0, high: int = 10) -> int: ...
393
380
 
394
381
  @overload
395
- async def async_sleep(
396
- *thresholds: float,
397
- precision: None = None
398
- ) -> float: ...
382
+ async def async_sleep(*thresholds: float) -> float: ...
399
383
 
400
384
  @overload
401
- async def async_sleep(
402
- *thresholds: float,
403
- precision: Literal[0] = None
404
- ) -> int: ...
385
+ async def async_sleep(*thresholds: float, precision: Literal[0]) -> int: ...
405
386
 
406
387
  @overload
407
- async def async_sleep(
408
- *thresholds: float,
409
- precision: int = None
410
- ) -> float: ...
411
-
412
- async def async_sleep(
413
- *thresholds: float,
414
- precision: int | None = None
415
- ) -> float:
388
+ async def async_sleep(*thresholds: float, precision: int) -> float: ...
389
+
390
+ async def async_sleep(*thresholds: float, precision: int | None = None) -> float:
416
391
  """
417
392
  Sleep random seconds, in the coroutine.
418
393
 
reykit/rtext.py CHANGED
@@ -15,9 +15,8 @@ from decimal import Decimal
15
15
  from pprint import pformat as pprint_pformat
16
16
  from json import dumps as json_dumps
17
17
 
18
- from .rexc import throw
18
+ from .rbase import throw
19
19
  from .rmonkey import monkey_patch_pprint_modify_width_judgment
20
- from .rrand import randi
21
20
 
22
21
 
23
22
  __all__ = (
reykit/rtime.py CHANGED
@@ -9,7 +9,7 @@
9
9
  """
10
10
 
11
11
 
12
- from typing import Any, TypedDict, Literal, overload
12
+ from typing import Any, TypedDict, Literal, NoReturn, overload
13
13
  from collections.abc import Callable
14
14
  from time import (
15
15
  struct_time as StructTime,
@@ -29,12 +29,11 @@ from pandas import (
29
29
  Timedelta as PTimedelta
30
30
  )
31
31
 
32
- from .rexc import throw
33
- from .rnum import digits, to_number
32
+ from .rbase import T, Base, throw
33
+ from .rnum import digits
34
34
  from .rrand import randn
35
35
  from .rre import search
36
36
  from .rstdout import echo
37
- from .rtype import T, Base
38
37
 
39
38
 
40
39
  __all__ = (
@@ -55,16 +54,16 @@ RecordData = TypedDict('RecordData', {'timestamp': int, 'datetime': Datetime, 't
55
54
  def now(format_: Literal['datetime'] = 'datetime') -> Datetime: ...
56
55
 
57
56
  @overload
58
- def now(format_: Literal['date'] = 'datetime') -> Date: ...
57
+ def now(format_: Literal['date']) -> Date: ...
59
58
 
60
59
  @overload
61
- def now(format_: Literal['time'] = 'datetime') -> Time: ...
60
+ def now(format_: Literal['time']) -> Time: ...
62
61
 
63
62
  @overload
64
- def now(format_: Literal['datetime_str', 'date_str', 'time_str'] = 'datetime') -> str: ...
63
+ def now(format_: Literal['datetime_str', 'date_str', 'time_str']) -> str: ...
65
64
 
66
65
  @overload
67
- def now(format_: Literal['timestamp'] = 'datetime') -> int: ...
66
+ def now(format_: Literal['timestamp']) -> int: ...
68
67
 
69
68
  def now(
70
69
  format_: Literal[
@@ -125,9 +124,16 @@ def time_to(
125
124
 
126
125
  @overload
127
126
  def time_to(
128
- obj: T,
127
+ obj: Any,
129
128
  decimal: bool = False,
130
- raising: Literal[False] = True
129
+ raising: Literal[True] = True
130
+ ) -> NoReturn: ...
131
+
132
+ @overload
133
+ def time_to(
134
+ obj: T,
135
+ *,
136
+ raising: Literal[False]
131
137
  ) -> T: ...
132
138
 
133
139
  def time_to(
@@ -301,22 +307,16 @@ def text_to_time(
301
307
 
302
308
 
303
309
  @overload
304
- def to_time(
305
- obj: str,
306
- raising: bool = True
307
- ) -> Datetime | Date | Time: ...
310
+ def to_time(obj: str, raising: bool = True) -> Datetime | Date | Time: ...
308
311
 
309
312
  @overload
310
- def to_time(
311
- obj: StructTime | float,
312
- raising: bool = True
313
- ) -> Datetime: ...
313
+ def to_time(obj: StructTime | float, raising: bool = True) -> Datetime: ...
314
314
 
315
315
  @overload
316
- def to_time(
317
- obj: T,
318
- raising: Literal[False] = True
319
- ) -> T: ...
316
+ def to_time(obj: Any, raising: Literal[True] = True) -> NoReturn: ...
317
+
318
+ @overload
319
+ def to_time(obj: T, raising: Literal[False]) -> T: ...
320
320
 
321
321
  def to_time(
322
322
  obj: Any,
@@ -379,43 +379,22 @@ def to_time(
379
379
 
380
380
 
381
381
  @overload
382
- def sleep(
383
- *,
384
- precision: None = None
385
- ) -> int: ...
382
+ def sleep() -> int: ...
386
383
 
387
384
  @overload
388
- def sleep(
389
- second: int,
390
- *,
391
- precision: None = None
392
- ) -> int: ...
385
+ def sleep(second: int) -> int: ...
393
386
 
394
387
  @overload
395
- def sleep(
396
- low: int = 0,
397
- high: int = 10,
398
- *,
399
- precision: None = None
400
- ) -> int: ...
388
+ def sleep(low: int = 0, high: int = 10) -> int: ...
401
389
 
402
390
  @overload
403
- def sleep(
404
- *thresholds: float,
405
- precision: None = None
406
- ) -> float: ...
391
+ def sleep(*thresholds: float) -> float: ...
407
392
 
408
393
  @overload
409
- def sleep(
410
- *thresholds: float,
411
- precision: Literal[0] = None
412
- ) -> int: ...
394
+ def sleep(*thresholds: float, precision: Literal[0]) -> int: ...
413
395
 
414
396
  @overload
415
- def sleep(
416
- *thresholds: float,
417
- precision: int = None
418
- ) -> float: ...
397
+ def sleep(*thresholds: float, precision: int) -> float: ...
419
398
 
420
399
  def sleep(
421
400
  *thresholds: float,
reykit/rwrap.py CHANGED
@@ -18,9 +18,8 @@ from threading import Thread
18
18
  from argparse import ArgumentParser
19
19
  from contextlib import redirect_stdout
20
20
 
21
- from .rexc import catch_exc
21
+ from .rbase import catch_exc, get_arg_info
22
22
  from .rstdout import echo
23
- from .rsys import get_arg_info
24
23
  from .rtime import now, time_to, TimeMark
25
24
 
26
25
 
@@ -78,13 +77,13 @@ def wrap_frame(decorator: Callable) -> Callable:
78
77
 
79
78
  # Decorate Decorator.
80
79
  @overload
81
- def wrap(func: Callable, /, *args: Any, _execute: None = None, **kwargs: Any) -> Callable | Any: ...
80
+ def wrap(func: Callable, /, *args: Any, **kwargs: Any) -> Callable | Any: ...
82
81
 
83
82
  @overload
84
- def wrap(func: Callable, /, *args: Any, _execute: Literal[True] = None, **kwargs: Any) -> Any: ...
83
+ def wrap(func: Callable, /, *args: Any, _execute: Literal[True], **kwargs: Any) -> Any: ...
85
84
 
86
85
  @overload
87
- def wrap(func: Callable, /, *args: Any, _execute: Literal[False] = None, **kwargs: Any) -> Callable: ...
86
+ def wrap(func: Callable, /, *args: Any, _execute: Literal[False], **kwargs: Any) -> Callable: ...
88
87
 
89
88
  @functools_wraps(decorator)
90
89
  def wrap(func: Callable, /, *args: Any, _execute: bool | None = None, **kwargs: Any) -> Callable | Any:
@@ -160,7 +159,7 @@ def wrap_runtime(
160
159
  func: Callable,
161
160
  /,
162
161
  *args: Any,
163
- _return_report: Literal[True] = False,
162
+ _return_report: Literal[True],
164
163
  **kwargs: Any
165
164
  ) -> tuple[Any, str]: ...
166
165
 
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reykit
3
- Version: 1.1.26
4
- Summary: Rey's kit method set.
3
+ Version: 1.1.28
4
+ Summary: Kit method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reykit/
6
6
  Author-email: Rey <reyxbo@163.com>
7
7
  License: Copyright 2025 ReyXBo
@@ -0,0 +1,28 @@
1
+ reykit/__init__.py,sha256=V86CHqPAAVkooVx3_QIOKpDIFVneQCTTSwfJ-uWgBno,788
2
+ reykit/rall.py,sha256=7Hip02YOkIDm3_xkoSDjvvYV2LhdBV2r4UKzWWnIfIo,628
3
+ reykit/rbase.py,sha256=npUa3FMfcFF422fZDElFoZrjDESFgW9mzZrNbuWZu-w,22512
4
+ reykit/rdata.py,sha256=RDrDWcNLIVEznNqT27155eLqdQLsp9rp6gxYbopI5yg,10138
5
+ reykit/remail.py,sha256=s7TXbLgEWEqNoeM42c6FpPufB2LajHgQuahfZri3urQ,6706
6
+ reykit/rimage.py,sha256=p7caatLE71yy7GUTkTKyMOaJTeBfl6pZr_7BFjcDvY8,6159
7
+ reykit/rlog.py,sha256=JgxLeMEl2UBwZG5IiGr-Cr_NPfkkkc2Yebb6tgH1zLQ,25525
8
+ reykit/rmonkey.py,sha256=ZTHsXI3T81WE0rlfVUhf6N5SYoxPbsgVImAasFJqnKU,8315
9
+ reykit/rnet.py,sha256=uS27Ownt9ELsjVKpGMPVN1Endc9s7z7CfIBkfE8bPMs,15033
10
+ reykit/rnum.py,sha256=PhG4V_BkVfCJUsbpMDN1umGZly1Hsus80TW8bpyBtyY,3653
11
+ reykit/ros.py,sha256=GZBhU_Ni1W5EqjLoS0mYWUk5-I7lmhg6b4sv3WvkDoA,40855
12
+ reykit/rrand.py,sha256=9QPXCsREIu45g6WP-XN67X05kmW3cTmctn3InvqYxuY,8947
13
+ reykit/rre.py,sha256=4DVxy28dl5zn6_II8-cgr7E2nVPH5QJIJVB4o7Vsf1A,6078
14
+ reykit/rschedule.py,sha256=_nrfrXYxlFAKCDbM8ibTTb60zNDlHxyE310cv-A19Kw,5799
15
+ reykit/rstdout.py,sha256=U9so0RGyiJrv1lhCA392XbzxIOnT4XZUrWQ_kuPjlAk,9840
16
+ reykit/rsys.py,sha256=-1MYplwvp9HOrTiNU6eS1FW8vCnpt-iXbYxhR0yPQCE,24894
17
+ reykit/rtable.py,sha256=MYEkm-PvYyNgCy1cHodNF4JgJNg1pzTy6NtYfF6CHRs,12001
18
+ reykit/rtask.py,sha256=FPRBKVIzuH5PUR9XyY3J9YF8rXDpIMWySXLc3y6zAwk,22812
19
+ reykit/rtext.py,sha256=l8yRxaWmDxdPLkXfQufUGjXSRMbmKfbYkkiihtvNixQ,11048
20
+ reykit/rtime.py,sha256=e9I5LieY3DFQq04qzyRT_dwsxc40Dcj9CMDAEmXsGw8,16938
21
+ reykit/rwrap.py,sha256=RK3wlc2cd-lnAvzqzvKsS21EtCmBNTA3i8HRbaolWE4,15275
22
+ reykit/rzip.py,sha256=ABUDLwEHQIpcvZbJE_oV78H7dik6nC7kaRz660Ro9Os,3481
23
+ reykit/rdll/__init__.py,sha256=tdKb-BOKLFn-diCvXjSLg9x71VuRKzkg2KtpOLGLTR4,679
24
+ reykit/rdll/rdll_core.py,sha256=o6-rKcTQgxZQe0kD3GnwyNb3KL9IogzgCQNOmYLMm7A,5086
25
+ reykit-1.1.28.dist-info/METADATA,sha256=TWLwOmgrzneuBFPj_Qx0XU9LuOooqLm5x_3KJoZEhzc,1913
26
+ reykit-1.1.28.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
+ reykit-1.1.28.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
28
+ reykit-1.1.28.dist-info/RECORD,,
reykit/rexc.py DELETED
@@ -1,335 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2024-07-17 09:46:40
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : Exception methods.
9
- """
10
-
11
-
12
- from typing import Any, NoReturn, overload
13
- from types import TracebackType
14
- from collections.abc import Iterable
15
- from sys import exc_info as sys_exc_info
16
- from os.path import exists as os_exists
17
- from traceback import format_exc
18
- from warnings import warn as warnings_warn
19
-
20
- from .rtype import Base, null
21
-
22
-
23
- __all__ = (
24
- 'Error',
25
- 'ActiveError',
26
- 'throw',
27
- 'warn',
28
- 'catch_exc',
29
- 'check_least_one',
30
- 'check_most_one',
31
- 'check_file_found',
32
- 'check_file_exist',
33
- 'check_response_code'
34
- )
35
-
36
-
37
- class Error(Base, Exception):
38
- """
39
- Error type.
40
- """
41
-
42
-
43
- class ActiveError(Error):
44
- """
45
- Active error type.
46
- """
47
-
48
-
49
- def throw(
50
- exception: type[BaseException] = AssertionError,
51
- value: Any = null,
52
- *values: Any,
53
- text: str | None = None,
54
- frame: int = 2
55
- ) -> NoReturn:
56
- """
57
- Throw exception.
58
-
59
- Parameters
60
- ----------
61
- exception : Exception Type.
62
- value : Exception value.
63
- values : Exception values.
64
- text : Exception text.
65
- frame : Number of code to upper level.
66
- """
67
-
68
- # Text.
69
- if text is None:
70
- if exception.__doc__ is not None:
71
- text = exception.__doc__.strip()
72
- if (
73
- text is None
74
- or text == ''
75
- ):
76
- text = 'use error'
77
- else:
78
- text = text[0].lower() + text[1:]
79
-
80
- ## Value.
81
- if value != null:
82
- values = (value,) + values
83
-
84
- ### Name.
85
- from .rsys import get_name
86
- name = get_name(value, frame)
87
- names = (name,)
88
- if values != ():
89
- names_values = get_name(values)
90
- if names_values is not None:
91
- names += names_values
92
-
93
- ### Convert.
94
- match exception:
95
- case TypeError():
96
- values = [
97
- type(value)
98
- for value in values
99
- if value is not None
100
- ]
101
- case TimeoutError():
102
- values = [
103
- int(value)
104
- if value % 1 == 0
105
- else round(value, 3)
106
- for value in values
107
- if type(value) == float
108
- ]
109
- values = [
110
- repr(value)
111
- for value in values
112
- ]
113
-
114
- ### Join.
115
- if names == ():
116
- values_len = len(values)
117
- text_value = ', '.join(values)
118
- if values_len == 1:
119
- text_value = 'value is ' + text_value
120
- else:
121
- text_value = 'values is (%s)' % text_value
122
- else:
123
- names_values = zip(names, values)
124
- text_value = ', '.join(
125
- [
126
- 'parameter "%s" is %s' % (name, value)
127
- for name, value in names_values
128
- ]
129
- )
130
- text += ' %s.' % text_value
131
-
132
- # Throw exception.
133
- exception = exception(text)
134
- raise exception
135
-
136
-
137
- def warn(
138
- *infos: Any,
139
- exception: type[BaseException] = UserWarning,
140
- stacklevel: int = 3
141
- ) -> None:
142
- """
143
- Throw warning.
144
-
145
- Parameters
146
- ----------
147
- infos : Warn informations.
148
- exception : Exception type.
149
- stacklevel : Warning code location, number of recursions up the code level.
150
- """
151
-
152
- # Handle parameter.
153
- if infos == ():
154
- infos = 'Warning!'
155
- elif len(infos) == 1:
156
- if type(infos[0]) == str:
157
- infos = infos[0]
158
- else:
159
- infos = str(infos[0])
160
- else:
161
- infos = str(infos)
162
-
163
- # Throw warning.
164
- warnings_warn(infos, exception, stacklevel)
165
-
166
-
167
- def catch_exc(
168
- title: str | None = None
169
- ) -> tuple[str, type[BaseException], BaseException, TracebackType]:
170
- """
171
- Catch exception information and print, must used in `except` syntax.
172
-
173
- Parameters
174
- ----------
175
- title : Print title.
176
- - `None`: Not print.
177
- - `str`: Print and use this title.
178
-
179
- Returns
180
- -------
181
- Exception data.
182
- - `str`: Exception report text.
183
- - `type[BaseException]`: Exception type.
184
- - `BaseException`: Exception instance.
185
- - `TracebackType`: Exception traceback instance.
186
- """
187
-
188
- # Get parameter.
189
- exc_report = format_exc()
190
- exc_report = exc_report.strip()
191
- exc_type, exc_instance, exc_traceback = sys_exc_info()
192
-
193
- # Print.
194
- if title is not None:
195
-
196
- ## Import.
197
- from .rstdout import echo
198
-
199
- ## Execute.
200
- echo(exc_report, title=title, frame='half')
201
-
202
- return exc_report, exc_type, exc_instance, exc_traceback
203
-
204
-
205
- @overload
206
- def check_least_one(*values: None) -> NoReturn: ...
207
-
208
- @overload
209
- def check_least_one(*values: Any) -> None: ...
210
-
211
- def check_least_one(*values: Any) -> None:
212
- """
213
- Check that at least one of multiple values is not null, when check fail, then throw exception.
214
-
215
- Parameters
216
- ----------
217
- values : Check values.
218
- """
219
-
220
- # Check.
221
- for value in values:
222
- if value is not None:
223
- return
224
-
225
- # Throw exception.
226
- from .rsys import get_name
227
- vars_name = get_name(values)
228
- if vars_name is not None:
229
- vars_name_de_dup = list(set(vars_name))
230
- vars_name_de_dup.sort(key=vars_name.index)
231
- vars_name_str = ' ' + ' and '.join([f'"{var_name}"' for var_name in vars_name_de_dup])
232
- else:
233
- vars_name_str = ''
234
- raise TypeError(f'at least one of parameters{vars_name_str} is not None')
235
-
236
-
237
- def check_most_one(*values: Any) -> None:
238
- """
239
- Check that at most one of multiple values is not null, when check fail, then throw exception.
240
-
241
- Parameters
242
- ----------
243
- values : Check values.
244
- """
245
-
246
- # Check.
247
- exist = False
248
- for value in values:
249
- if value is not None:
250
- if exist is True:
251
-
252
- # Throw exception.
253
- from .rsys import get_name
254
- vars_name = get_name(values)
255
- if vars_name is not None:
256
- vars_name_de_dup = list(set(vars_name))
257
- vars_name_de_dup.sort(key=vars_name.index)
258
- vars_name_str = ' ' + ' and '.join([f'"{var_name}"' for var_name in vars_name_de_dup])
259
- else:
260
- vars_name_str = ''
261
- raise TypeError(f'at most one of parameters{vars_name_str} is not None')
262
-
263
- exist = True
264
-
265
-
266
- def check_file_found(path: str) -> None:
267
- """
268
- Check if file path found, if not, throw exception.
269
-
270
- Parameters
271
- ----------
272
- path : File path.
273
- """
274
-
275
- # Check.
276
- exist = os_exists(path)
277
-
278
- # Throw exception.
279
- if not exist:
280
- throw(FileNotFoundError, path)
281
-
282
-
283
- def check_file_exist(path: str) -> None:
284
- """
285
- Check if file path exist, if exist, throw exception.
286
-
287
- Parameters
288
- ----------
289
- path : File path.
290
- """
291
-
292
- # Check.
293
- exist = os_exists(path)
294
-
295
- # Throw exception.
296
- if exist:
297
- throw(FileExistsError, path)
298
-
299
-
300
- def check_response_code(
301
- code: int,
302
- range_: int | Iterable[int] | None = None
303
- ) -> bool:
304
- """
305
- Check if the response code is in range.
306
-
307
- Parameters
308
- ----------
309
- code : Response code.
310
- range_ : Pass the code range.
311
- - `None`: Check if is between 200 and 299.
312
- - `int`: Check if is this value.
313
- - `Iterable`: Check if is in sequence.
314
-
315
- Returns
316
- -------
317
- Check result.
318
- """
319
-
320
- # Check.
321
- match range_:
322
- case None:
323
- result = code // 100 == 2
324
- case int():
325
- result = code == range_
326
- case _ if hasattr(range_, '__contains__'):
327
- result = code in range_
328
- case _:
329
- throw(TypeError, range_)
330
-
331
- # Throw exception.
332
- if not result:
333
- throw(value=code)
334
-
335
- return result