reykit 1.1.25__py3-none-any.whl → 1.1.27__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/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 Null
21
-
22
-
23
- __all__ = (
24
- 'RError',
25
- 'RActiveError',
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 RError(Exception):
38
- """
39
- Rey `error` type.
40
- """
41
-
42
-
43
- class RActiveError(RError):
44
- """
45
- Rey's `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
reykit/rtype.py DELETED
@@ -1,130 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2025-06-13 02:05:46
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : Type methods.
9
- """
10
-
11
-
12
- from typing import Any, Self, TypeVar
13
- from collections.abc import Callable
14
-
15
-
16
- __all__ = (
17
- 'T',
18
- 'KT',
19
- 'VT',
20
- 'RBase',
21
- 'RStaticMeta',
22
- 'RConfigMeta',
23
- 'RSingleton',
24
- 'RNull',
25
- 'Null'
26
- )
27
-
28
-
29
- # Generic.
30
- T = TypeVar('T') # Any.
31
- KT = TypeVar('KT') # Any dictionary key.
32
- VT = TypeVar('VT') # Any dictionary value.
33
-
34
-
35
- class RBase(object):
36
- """
37
- Rey's `base` type.
38
- """
39
-
40
-
41
- class RStaticMeta(RBase, type):
42
- """
43
- Rey's `static meta` type.
44
- """
45
-
46
-
47
- def __call__(cls):
48
- """
49
- Call method.
50
- """
51
-
52
- # Throw exception.
53
- raise TypeError('static class, no instances allowed.')
54
-
55
-
56
- class RConfigMeta(RStaticMeta):
57
- """
58
- Rey's `config meta` type.
59
- """
60
-
61
-
62
- def __getitem__(cls, name: str) -> Any:
63
- """
64
- Get item.
65
-
66
- Parameters
67
- ----------
68
- name : Item name.
69
-
70
- Returns
71
- -------
72
- Item value.
73
- """
74
-
75
- # Get.
76
- item = getattr(cls, name)
77
-
78
- return item
79
-
80
-
81
- def __setitem__(cls, name: str, value: Any) -> None:
82
- """
83
- Set item.
84
-
85
- Parameters
86
- ----------
87
- name : Item name.
88
- """
89
-
90
- # Set.
91
- setattr(cls, name, value)
92
-
93
-
94
- class RSingleton(RBase):
95
- """
96
- Rey's `singleton` type.
97
- When instantiated, method `__singleton__` will be called only once, and will accept arguments.
98
-
99
- Attributes
100
- ----------
101
- _instance : Global singleton instance.
102
- """
103
-
104
- _instance: Self | None = None
105
-
106
-
107
- def __new__(self, *arg: Any, **kwargs: Any) -> Self:
108
- """
109
- Build `singleton` instance.
110
- """
111
-
112
- # Build.
113
- if self._instance is None:
114
- self._instance = super().__new__(self)
115
-
116
- ## Singleton method.
117
- if hasattr(self, "__singleton__"):
118
- __singleton__: Callable = getattr(self, "__singleton__")
119
- __singleton__(self, *arg, **kwargs)
120
-
121
- return self._instance
122
-
123
-
124
- class RNull(RSingleton):
125
- """
126
- Rey's `null` type.
127
- """
128
-
129
-
130
- Null = RNull()
@@ -1,29 +0,0 @@
1
- reykit/__init__.py,sha256=LdwdCXLzzPyteyYerrwfJH0LGj5jp_j-tamv2JEghTg,821
2
- reykit/rall.py,sha256=AEHa1iUCopuM5sPzO0vmSLWTmKeSjilUtzQ8f-jULHk,649
3
- reykit/rdata.py,sha256=a7aauSEjLiqDr-Adg3Aipri0gJrW-Mn-9hMQxRqKq9M,10006
4
- reykit/remail.py,sha256=PBY2lCCkJr8BZbeD944sXjOompW1F1-ihbOXNJX-Lak,6744
5
- reykit/rexc.py,sha256=yy4VGc7r0GC3ZBp6KMT99hpZ4-AbV1D-wgKuU0Blih4,8136
6
- reykit/rimage.py,sha256=fSPNxwfdN9_dMbbPn-LagNSIo_Z-ISLcXaOZgisUc24,6190
7
- reykit/rlog.py,sha256=7fGg9XldIntUFrcYVZWC2ChlJlnmbaaU1rB7yZw-IDM,25704
8
- reykit/rmonkey.py,sha256=pDXhfX0kyHWptM3OPLL6x3_hQqFd-n6H3TaQafgdXcs,8246
9
- reykit/rnet.py,sha256=Je-43L5-ELpy-mWe02jyj9bfcllVifM9KusBP4tkjME,15085
10
- reykit/rnum.py,sha256=9J6unM11dDTg9A8XigHzfut8VFHWaNRKu59vGQ-ISXo,3637
11
- reykit/ros.py,sha256=ORdUP72dPYWlRyOfcNw5FibxXMPk_Kv9im8h30MoGXc,40731
12
- reykit/rrand.py,sha256=5vjQ4wsHUZ84dUs1Arp54QG8ghZYlkusEXgpht19iVw,9237
13
- reykit/rre.py,sha256=0yYRiHhGg2OmuEVNf3zT92AcqQTdrvIJUltiFpjlYdM,6085
14
- reykit/rschedule.py,sha256=tWqsEiXgNo5zcJtf4-MR5ZMs0fbn3ymU4M8_X1sELEc,5822
15
- reykit/rstdout.py,sha256=zyGDk07X9WMTx06MBrg0Ki2tb_QsYLsd0ypU1fa1MVw,9920
16
- reykit/rsys.py,sha256=qtmmw_GDIx0KbLHAADLDjXuSd_tYCyFoG7evW0K6564,36402
17
- reykit/rtable.py,sha256=M0OOoxFlMJH91lhSGauzwEP7JA0q5-Odwzpff_X-b5g,12031
18
- reykit/rtask.py,sha256=gwerLHFnrju695JukYpwCITq0SrblVaSktSLYYpkcLs,23114
19
- reykit/rtext.py,sha256=KtK9d1y4NCsfydZTxrq5lnnyWvJfPi79ywy2qnauNew,11073
20
- reykit/rtime.py,sha256=YXUN-EQYsgDbZk636gyeXa9NifU2hYoUNvbkX6jmsN4,17096
21
- reykit/rtype.py,sha256=O7iI_sJ1Bfl_ZiP29IHqEE3v3PfJRpeA5M6ukEdZSMk,2317
22
- reykit/rwrap.py,sha256=r5FBxbgiRMRLdaK6L7Uls5c6E_yfzM9xvWRY2O85KbA,15339
23
- reykit/rzip.py,sha256=OEpRB2meW5copstZjeuKmarLD_co8I05WHBaKcLg0O8,3486
24
- reykit/rdll/__init__.py,sha256=tdKb-BOKLFn-diCvXjSLg9x71VuRKzkg2KtpOLGLTR4,679
25
- reykit/rdll/rdll_core.py,sha256=o6-rKcTQgxZQe0kD3GnwyNb3KL9IogzgCQNOmYLMm7A,5086
26
- reykit-1.1.25.dist-info/METADATA,sha256=PJdqvyQoLCx553RFzQLB1KHEvr-yIn9lHEePxUoBagE,1919
27
- reykit-1.1.25.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
28
- reykit-1.1.25.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
29
- reykit-1.1.25.dist-info/RECORD,,