reykit 1.1.15__py3-none-any.whl → 1.1.16__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/rdata.py +78 -1
- reykit/rimage.py +7 -7
- reykit/rmonkey.py +28 -0
- reykit/rsystem.py +40 -0
- reykit/rtype.py +6 -1
- {reykit-1.1.15.dist-info → reykit-1.1.16.dist-info}/METADATA +1 -1
- {reykit-1.1.15.dist-info → reykit-1.1.16.dist-info}/RECORD +9 -9
- {reykit-1.1.15.dist-info → reykit-1.1.16.dist-info}/WHEEL +0 -0
- {reykit-1.1.15.dist-info → reykit-1.1.16.dist-info}/licenses/LICENSE +0 -0
reykit/rdata.py
CHANGED
@@ -10,11 +10,13 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
from typing import Any, TypedDict, Literal, overload
|
13
|
+
from collections import defaultdict as Defaultdict, ChainMap
|
13
14
|
from collections.abc import Callable, Iterable, Generator
|
15
|
+
from itertools import chain as IChain
|
14
16
|
|
15
17
|
from .rexception import check_least_one, check_most_one
|
16
18
|
from .rsystem import is_iterable
|
17
|
-
from .rtype import T
|
19
|
+
from .rtype import T, KT, VT, RNull
|
18
20
|
|
19
21
|
|
20
22
|
__all__ = (
|
@@ -24,6 +26,8 @@ __all__ = (
|
|
24
26
|
'unique',
|
25
27
|
'in_arrs',
|
26
28
|
'objs_in',
|
29
|
+
'chain',
|
30
|
+
'default_dict',
|
27
31
|
'RGenerator'
|
28
32
|
)
|
29
33
|
|
@@ -279,6 +283,79 @@ def objs_in(arr: Iterable, *objs: Any, mode: Literal['or', 'and'] = 'or') -> boo
|
|
279
283
|
return True
|
280
284
|
|
281
285
|
|
286
|
+
@overload
|
287
|
+
def chain(*iterables: dict[KT, VT]) -> ChainMap[KT, VT]: ...
|
288
|
+
|
289
|
+
@overload
|
290
|
+
def chain(*iterables: Iterable[T]) -> IChain[T]: ...
|
291
|
+
|
292
|
+
def chain(*iterables: dict[KT, VT] | Iterable[T]) -> ChainMap[KT, VT] | IChain[T]:
|
293
|
+
"""
|
294
|
+
Connect multiple iterables.
|
295
|
+
|
296
|
+
Parameters
|
297
|
+
----------
|
298
|
+
iterables : Multiple iterables.
|
299
|
+
- `dict`: Connect to chain mapping.
|
300
|
+
- `Iterable`: Connect to chain.
|
301
|
+
|
302
|
+
Returns
|
303
|
+
-------
|
304
|
+
Chain instance.
|
305
|
+
"""
|
306
|
+
|
307
|
+
# Dict.
|
308
|
+
if all(
|
309
|
+
[
|
310
|
+
isinstance(iterable, dict)
|
311
|
+
for iterable in iterables
|
312
|
+
]
|
313
|
+
):
|
314
|
+
data = ChainMap(*iterables)
|
315
|
+
|
316
|
+
# Other.
|
317
|
+
else:
|
318
|
+
data = IChain(*iterables)
|
319
|
+
|
320
|
+
return data
|
321
|
+
|
322
|
+
|
323
|
+
def default_dict(default: Any = RNull, data: dict[KT, VT] | None = None) -> Defaultdict[KT, VT]:
|
324
|
+
"""
|
325
|
+
Set `dict` instance, default value when key does not exist.
|
326
|
+
|
327
|
+
Parameters
|
328
|
+
----------
|
329
|
+
default : Default value.
|
330
|
+
- `Type[RNull]`: Nest function self.
|
331
|
+
- `Callable`: Use call return value.
|
332
|
+
data : `dict` instance.
|
333
|
+
- `None`: Empty `dict`.
|
334
|
+
"""
|
335
|
+
|
336
|
+
# Handle parameter.
|
337
|
+
|
338
|
+
## Null.
|
339
|
+
if default == RNull:
|
340
|
+
default_factory = default_dict
|
341
|
+
|
342
|
+
## Callable.
|
343
|
+
elif callable(default):
|
344
|
+
default_factory = default
|
345
|
+
|
346
|
+
## Not callable.
|
347
|
+
else:
|
348
|
+
default_factory = lambda : default
|
349
|
+
|
350
|
+
if data is None:
|
351
|
+
data = {}
|
352
|
+
|
353
|
+
# Instance.
|
354
|
+
dict_set = Defaultdict(default_factory, data)
|
355
|
+
|
356
|
+
return dict_set
|
357
|
+
|
358
|
+
|
282
359
|
class RGenerator(object):
|
283
360
|
"""
|
284
361
|
Rey's `generator` type.
|
reykit/rimage.py
CHANGED
@@ -32,7 +32,7 @@ __all__ = (
|
|
32
32
|
'encode_qrcode',
|
33
33
|
'decode_qrcode',
|
34
34
|
'compress_image',
|
35
|
-
'
|
35
|
+
'to_pil_image',
|
36
36
|
'generate_captcha_image'
|
37
37
|
)
|
38
38
|
|
@@ -187,13 +187,13 @@ def compress_image(
|
|
187
187
|
rfile(content)
|
188
188
|
|
189
189
|
|
190
|
-
def
|
190
|
+
def to_pil_image(source: str | bytes) -> RImage:
|
191
191
|
"""
|
192
192
|
Get `Image` instance of `PIL` package.
|
193
193
|
|
194
194
|
Parameters
|
195
195
|
----------
|
196
|
-
|
196
|
+
source : Image source data.
|
197
197
|
- `str`: Image file path.
|
198
198
|
- `bytes`: Image bytes data.
|
199
199
|
|
@@ -203,12 +203,12 @@ def to_pimage(image: str | bytes) -> RImage:
|
|
203
203
|
"""
|
204
204
|
|
205
205
|
# File path.
|
206
|
-
if
|
207
|
-
pil_image = pil_open(
|
206
|
+
if source.__class__ == str:
|
207
|
+
pil_image = pil_open(source)
|
208
208
|
|
209
209
|
# Bytes data.
|
210
|
-
if
|
211
|
-
bytes_io = BytesIO(
|
210
|
+
if source.__class__ in (bytes, bytearray):
|
211
|
+
bytes_io = BytesIO(source)
|
212
212
|
pil_image = pil_open(bytes_io)
|
213
213
|
|
214
214
|
return pil_image
|
reykit/rmonkey.py
CHANGED
@@ -26,6 +26,23 @@ def monkey_patch_sqlalchemy_result_more_fetch():
|
|
26
26
|
Returns
|
27
27
|
-------
|
28
28
|
Modified type.
|
29
|
+
|
30
|
+
Examples
|
31
|
+
--------
|
32
|
+
>>> result = connection.execute(sql)
|
33
|
+
>>> result.fetch_table()
|
34
|
+
>>> result.fetch_dict()
|
35
|
+
>>> result.fetch_list()
|
36
|
+
>>> result.fetch_df()
|
37
|
+
>>> result.fetch_json()
|
38
|
+
>>> result.fetch_text()
|
39
|
+
>>> result.fetch_sql()
|
40
|
+
>>> result.fetch_html()
|
41
|
+
>>> result.fetch_csv()
|
42
|
+
>>> result.fetch_excel()
|
43
|
+
>>> result.show()
|
44
|
+
>>> result.exist
|
45
|
+
>>> result.empty
|
29
46
|
"""
|
30
47
|
|
31
48
|
|
@@ -203,6 +220,12 @@ def monkey_patch_sqlalchemy_result_more_fetch():
|
|
203
220
|
def monkey_patch_sqlalchemy_row_index_field():
|
204
221
|
"""
|
205
222
|
Monkey patch of package `sqlalchemy`, add index by field method to `Row` object.
|
223
|
+
|
224
|
+
Examples
|
225
|
+
--------
|
226
|
+
>>> result = connection.execute(sql)
|
227
|
+
>>> for row in result:
|
228
|
+
... row['field']
|
206
229
|
"""
|
207
230
|
|
208
231
|
|
@@ -295,6 +318,11 @@ def monkey_path_pil_image_get_bytes():
|
|
295
318
|
Returns
|
296
319
|
-------
|
297
320
|
Image object.
|
321
|
+
|
322
|
+
Examples
|
323
|
+
--------
|
324
|
+
>>> image = to_pil_image(source)
|
325
|
+
>>> image.get_bytes()
|
298
326
|
"""
|
299
327
|
|
300
328
|
|
reykit/rsystem.py
CHANGED
@@ -67,6 +67,8 @@ __all__ = (
|
|
67
67
|
'dos_command',
|
68
68
|
'dos_command_var',
|
69
69
|
'block',
|
70
|
+
'is_class',
|
71
|
+
'is_instance',
|
70
72
|
'is_iterable',
|
71
73
|
'is_table',
|
72
74
|
'is_number_str',
|
@@ -357,6 +359,44 @@ def block() -> None:
|
|
357
359
|
continue
|
358
360
|
|
359
361
|
|
362
|
+
def is_class(obj: Any) -> bool:
|
363
|
+
"""
|
364
|
+
Judge whether it is class.
|
365
|
+
|
366
|
+
Parameters
|
367
|
+
----------
|
368
|
+
obj : Judge object.
|
369
|
+
|
370
|
+
Returns
|
371
|
+
-------
|
372
|
+
Judgment result.
|
373
|
+
"""
|
374
|
+
|
375
|
+
# Judge.
|
376
|
+
judge = isinstance(obj, type)
|
377
|
+
|
378
|
+
return judge
|
379
|
+
|
380
|
+
|
381
|
+
def is_instance(obj: Any) -> bool:
|
382
|
+
"""
|
383
|
+
Judge whether it is instance.
|
384
|
+
|
385
|
+
Parameters
|
386
|
+
----------
|
387
|
+
obj : Judge object.
|
388
|
+
|
389
|
+
Returns
|
390
|
+
-------
|
391
|
+
Judgment result.
|
392
|
+
"""
|
393
|
+
|
394
|
+
# judge.
|
395
|
+
judge = not is_class(obj)
|
396
|
+
|
397
|
+
return judge
|
398
|
+
|
399
|
+
|
360
400
|
def is_iterable(
|
361
401
|
obj: Any,
|
362
402
|
exclude_types: Iterable[type] = [str, bytes]
|
reykit/rtype.py
CHANGED
@@ -15,6 +15,8 @@ from collections.abc import Callable
|
|
15
15
|
|
16
16
|
__all__ = (
|
17
17
|
'T',
|
18
|
+
'KT',
|
19
|
+
'VT',
|
18
20
|
'RStaticMeta',
|
19
21
|
'RConfigMeta',
|
20
22
|
'RNull',
|
@@ -22,7 +24,10 @@ __all__ = (
|
|
22
24
|
)
|
23
25
|
|
24
26
|
|
25
|
-
|
27
|
+
# Generic.
|
28
|
+
T = TypeVar('T') # Any.
|
29
|
+
KT = TypeVar('KT') # Any dictionary key.
|
30
|
+
VT = TypeVar('VT') # Any dictionary value.
|
26
31
|
|
27
32
|
|
28
33
|
class RStaticMeta(type):
|
@@ -1,12 +1,12 @@
|
|
1
1
|
reykit/__init__.py,sha256=QwnhdUDSXgjXJQ4ClaeP9oKXUXyQOPj5sApwGCDrILc,848
|
2
2
|
reykit/rall.py,sha256=mOFwHXZ4-BOkJ5Ptbm6lQc2zwNf_VqcqM6AYYnYPfoo,672
|
3
3
|
reykit/rcomm.py,sha256=LgSLrpUokOgdRMYwuZj6JNvxDyvENwsiOd6ZHo67HBg,11444
|
4
|
-
reykit/rdata.py,sha256=
|
4
|
+
reykit/rdata.py,sha256=ZiWiYAS9fP1e-VEWbsQAuvfrSabrc8GKGD3ikNg8jVo,9989
|
5
5
|
reykit/remail.py,sha256=rK_hbqGeZh04DnVPtjODLsm_YfdrZ5L-Z6SbjplrfUc,6736
|
6
6
|
reykit/rexception.py,sha256=lxs3DWNsGn33YTpYHi6pm4rjjYFpqvYSKhkailxM638,8344
|
7
|
-
reykit/rimage.py,sha256=
|
7
|
+
reykit/rimage.py,sha256=VXlQFCZBjx1Mu18Au0Qmth9-u8dlIz0h8u_X100ImxA,6287
|
8
8
|
reykit/rlog.py,sha256=EETnQNVADBvTyseVpL5uOKWL647ee6ZeAevBnTOOWF8,25764
|
9
|
-
reykit/rmonkey.py,sha256=
|
9
|
+
reykit/rmonkey.py,sha256=OAlLVvMszMDzersroVC9NjbD2GPnoPgWF4AHZ3v3-fk,8232
|
10
10
|
reykit/rmultitask.py,sha256=vey2UiPcwP7XI8LiobcpRqA0FGUg_jAzBR9FmcuSHEk,23133
|
11
11
|
reykit/rnumber.py,sha256=6x4FuRB-MTJheo6wbTUEaBarnew15jomlrneo3_Q2wg,3646
|
12
12
|
reykit/ros.py,sha256=vrQw4WC2YebK1fucgyLk1PmoPBtgD_ONRzsSgIEJx8c,40682
|
@@ -14,17 +14,17 @@ reykit/rrandom.py,sha256=Av-neLmX3DXYPq-qzYY95CfXvOTvXcvtXr9Lrqd1wSU,9232
|
|
14
14
|
reykit/rregex.py,sha256=XTlnDLior8yyncFdrTr9FsVlBcqMXvsWRfpmvQS-BR8,6089
|
15
15
|
reykit/rschedule.py,sha256=pYZq8gFOY46_ayRpW2gXsfybMZ7ULTNikLSwMuT_11M,5798
|
16
16
|
reykit/rstdout.py,sha256=O-78in-_mQ-FJP869UikdHICefiF3Yb2M0fOBJ07wwk,9921
|
17
|
-
reykit/rsystem.py,sha256=
|
17
|
+
reykit/rsystem.py,sha256=xEgcse_4XbYB50USsVoh6yy3C5rHlnE1jKQdLdNOcPw,35364
|
18
18
|
reykit/rtable.py,sha256=gXszf_9DE_5SMdNcxMX-xd4IpHGQVjGsN3NQIm7wVGY,12055
|
19
19
|
reykit/rtext.py,sha256=whaKpVkd36yYVtCmZ1ptp_TVRL1v3f7Jab0vPXC8wXY,11089
|
20
20
|
reykit/rtime.py,sha256=WYPmpz4ZyrqWVU0YrXAiZWLYbMZeZTX3XqTGwt-EE3g,17101
|
21
|
-
reykit/rtype.py,sha256=
|
21
|
+
reykit/rtype.py,sha256=bwo7cn-Z3qSYOop-ijPPJBGIUtzNV2pak37xTvrI3-Q,2208
|
22
22
|
reykit/rwrap.py,sha256=AJBYTDLHLGlMSiGIKoVkCsQk-Y4nDHWWFVCdnz5Bwdk,15222
|
23
23
|
reykit/rzip.py,sha256=i6KkmeSWCnq025d-O1mbuCYezNRUhyY9OGVK0CRlNAM,3522
|
24
24
|
reykit/rdll/__init__.py,sha256=vM9V7wSNno-WH9RrxgHTIgCkQm8LmBFoLFO8z7qovNo,306
|
25
25
|
reykit/rdll/rdll_inject.py,sha256=bETl8tywtN1OiQudbA21u6GwBM_bqVX7jbiisNj_JBg,645
|
26
26
|
reykit/rdll/rdll_inject_core.py,sha256=Trgh_pdJs_Lw-Y-0Kkn8kHr4BnilM9dBKnHnX25T_pM,5092
|
27
|
-
reykit-1.1.
|
28
|
-
reykit-1.1.
|
29
|
-
reykit-1.1.
|
30
|
-
reykit-1.1.
|
27
|
+
reykit-1.1.16.dist-info/METADATA,sha256=8eNvWo1IWjKKeob4ohB86MZWsjTQc8G-93smLGe2GoY,1889
|
28
|
+
reykit-1.1.16.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
29
|
+
reykit-1.1.16.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
30
|
+
reykit-1.1.16.dist-info/RECORD,,
|
File without changes
|
File without changes
|