reykit 1.1.14__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 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/rexception.py CHANGED
@@ -20,7 +20,7 @@
20
20
  """
21
21
 
22
22
 
23
- from typing import Any, NoReturn
23
+ from typing import Any, NoReturn, overload
24
24
  from types import TracebackType
25
25
  from collections.abc import Iterable
26
26
  from sys import exc_info as sys_exc_info
@@ -213,6 +213,12 @@ def catch_exc(
213
213
  return exc_report, exc_type, exc_instance, exc_traceback
214
214
 
215
215
 
216
+ @overload
217
+ def check_least_one(*values: None) -> NoReturn: ...
218
+
219
+ @overload
220
+ def check_least_one(*values: Any) -> None: ...
221
+
216
222
  def check_least_one(*values: Any) -> None:
217
223
  """
218
224
  Check that at least one of multiple values is not null, when check fail, then throw exception.
@@ -249,22 +255,23 @@ def check_most_one(*values: Any) -> None:
249
255
  """
250
256
 
251
257
  # Check.
252
- none_count = 0
258
+ exist = False
253
259
  for value in values:
254
260
  if value is not None:
255
- none_count += 1
256
-
257
- # Throw exception.
258
- if none_count > 1:
259
- from .rsystem import get_name
260
- vars_name = get_name(values)
261
- if vars_name is not None:
262
- vars_name_de_dup = list(set(vars_name))
263
- vars_name_de_dup.sort(key=vars_name.index)
264
- vars_name_str = ' ' + ' and '.join([f'"{var_name}"' for var_name in vars_name_de_dup])
265
- else:
266
- vars_name_str = ''
267
- raise TypeError(f'at most one of parameters{vars_name_str} is not None')
261
+ if exist is True:
262
+
263
+ # Throw exception.
264
+ from .rsystem import get_name
265
+ vars_name = get_name(values)
266
+ if vars_name is not None:
267
+ vars_name_de_dup = list(set(vars_name))
268
+ vars_name_de_dup.sort(key=vars_name.index)
269
+ vars_name_str = ' ' + ' and '.join([f'"{var_name}"' for var_name in vars_name_de_dup])
270
+ else:
271
+ vars_name_str = ''
272
+ raise TypeError(f'at most one of parameters{vars_name_str} is not None')
273
+
274
+ exist = True
268
275
 
269
276
 
270
277
  def check_file_found(path: str) -> None:
reykit/rimage.py CHANGED
@@ -32,7 +32,7 @@ __all__ = (
32
32
  'encode_qrcode',
33
33
  'decode_qrcode',
34
34
  'compress_image',
35
- 'to_pimage',
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 to_pimage(image: str | bytes) -> RImage:
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
- image : Image source data.
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 image.__class__ == str:
207
- pil_image = pil_open(image)
206
+ if source.__class__ == str:
207
+ pil_image = pil_open(source)
208
208
 
209
209
  # Bytes data.
210
- if image.__class__ in (bytes, bytearray):
211
- bytes_io = BytesIO(image)
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/rlog.py CHANGED
@@ -998,7 +998,7 @@ class RRecord(object):
998
998
  rfile(value, True)
999
999
 
1000
1000
 
1001
- def is_record(
1001
+ def is_recorded(
1002
1002
  self,
1003
1003
  value: Any
1004
1004
  ) -> bool:
@@ -1036,4 +1036,4 @@ class RRecord(object):
1036
1036
  __call__ = record
1037
1037
 
1038
1038
 
1039
- __contains__ = is_record
1039
+ __contains__ = is_recorded
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
- T = TypeVar('T')
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reykit
3
- Version: 1.1.14
3
+ Version: 1.1.16
4
4
  Summary: Rey's kit method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reykit/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -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=nCBZxD2fsDuFCDyfLLZZPYJPod4Xuv0aKplQDDUMvI8,8285
4
+ reykit/rdata.py,sha256=ZiWiYAS9fP1e-VEWbsQAuvfrSabrc8GKGD3ikNg8jVo,9989
5
5
  reykit/remail.py,sha256=rK_hbqGeZh04DnVPtjODLsm_YfdrZ5L-Z6SbjplrfUc,6736
6
- reykit/rexception.py,sha256=ftXVdEVkU0B0HXbKjQTiJRJVVGbvhorwWtMiplpN9Zk,8118
7
- reykit/rimage.py,sha256=fQpIHX6Go3Jk_MDgsSDnZx27EZHumyGdgI9xyjP5lYQ,6275
8
- reykit/rlog.py,sha256=qhmATMv3_bJRaiuN9mo8hSf_95HH5Lw838aJFio98sg,25760
9
- reykit/rmonkey.py,sha256=RqhmKXabl11s2RJaGizpm00Q1yEkul1Je5uxw8_thUk,7584
6
+ reykit/rexception.py,sha256=lxs3DWNsGn33YTpYHi6pm4rjjYFpqvYSKhkailxM638,8344
7
+ reykit/rimage.py,sha256=VXlQFCZBjx1Mu18Au0Qmth9-u8dlIz0h8u_X100ImxA,6287
8
+ reykit/rlog.py,sha256=EETnQNVADBvTyseVpL5uOKWL647ee6ZeAevBnTOOWF8,25764
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=h_G3MoJ7yuIdR4_O_GjNumDPDUAb5BAhfqO3o4GWFAQ,34791
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=hgZhDVqS86Di2DRzVdqyoT6BYob-P45IIFu-T35YYWE,2081
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.14.dist-info/METADATA,sha256=PB2A-2qKkg8JjOTft-UmK7BEdQrbwR_Zu9mxxCIR7Bs,1889
28
- reykit-1.1.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
- reykit-1.1.14.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
30
- reykit-1.1.14.dist-info/RECORD,,
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,,