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/rdata.py CHANGED
@@ -14,9 +14,7 @@ from collections import defaultdict as Defaultdict, ChainMap
14
14
  from collections.abc import Callable, Iterable, Generator
15
15
  from itertools import chain as IChain
16
16
 
17
- from .rexc import check_least_one, check_most_one
18
- from .rsys import is_iterable
19
- from .rtype import T, KT, VT, RBase, Null
17
+ from .rbase import T, KT, VT, Base, null, check_least_one, check_most_one, is_iterable
20
18
 
21
19
 
22
20
  __all__ = (
@@ -28,7 +26,7 @@ __all__ = (
28
26
  'objs_in',
29
27
  'chain',
30
28
  'default_dict',
31
- 'RGenerator'
29
+ 'FunctionGenerator'
32
30
  )
33
31
 
34
32
 
@@ -134,10 +132,10 @@ def flatten(data: Any, *, _flattern_data: list | None = None) -> list:
134
132
 
135
133
 
136
134
  @overload
137
- def split(data: Iterable[T], share: int = None, bin_size: None = None) -> list[list[T]]: ...
135
+ def split(data: Iterable[T], share: int) -> list[list[T]]: ...
138
136
 
139
137
  @overload
140
- def split(data: Iterable[T], share: None = None, bin_size: int = None) -> list[list[T]]: ...
138
+ def split(data: Iterable[T], *, bin_size: int) -> list[list[T]]: ...
141
139
 
142
140
  def split(data: Iterable[T], share: int | None = None, bin_size: int | None = None) -> list[list[T]]:
143
141
  """
@@ -320,14 +318,14 @@ def chain(*iterables: dict[KT, VT] | Iterable[T]) -> ChainMap[KT, VT] | IChain[T
320
318
  return data
321
319
 
322
320
 
323
- def default_dict(default: T = Null, data: dict[KT, VT] | None = None) -> Defaultdict[KT, VT | T]:
321
+ def default_dict(default: T = null, data: dict[KT, VT] | None = None) -> Defaultdict[KT, VT | T]:
324
322
  """
325
323
  Set `dict` instance, default value when key does not exist.
326
324
 
327
325
  Parameters
328
326
  ----------
329
327
  default : Default value.
330
- - `Literal[Null]`: Nest function self.
328
+ - `Literal[null]`: Nest function self.
331
329
  - `Callable`: Use call return value.
332
330
  data : `dict` instance.
333
331
  - `None`: Empty `dict`.
@@ -336,7 +334,7 @@ def default_dict(default: T = Null, data: dict[KT, VT] | None = None) -> Default
336
334
  # Handle parameter.
337
335
 
338
336
  ## Null.
339
- if default == Null:
337
+ if default == null:
340
338
  default_factory = default_dict
341
339
 
342
340
  ## Callable.
@@ -356,9 +354,18 @@ def default_dict(default: T = Null, data: dict[KT, VT] | None = None) -> Default
356
354
  return dict_set
357
355
 
358
356
 
359
- class RGenerator(RBase):
357
+ class FunctionGenerator(Base):
360
358
  """
361
- Rey's `generator` type.
359
+ Function generator type.
360
+
361
+ Examples
362
+ --------
363
+ >>> func = lambda arg1, arg2: arg1 + arg2
364
+ >>> fgenerator = FunctionGenerator(func, 10)
365
+ >>> fgenerator.add(1)
366
+ >>> fgenerator.add(2)
367
+ >>> list(fgenerator)
368
+ [11, 12]
362
369
  """
363
370
 
364
371
 
@@ -369,7 +376,7 @@ class RGenerator(RBase):
369
376
  **kwargs: Any
370
377
  ) -> None:
371
378
  """
372
- Build `generator` instance attributes.
379
+ Build instance attributes.
373
380
 
374
381
  Parameters
375
382
  ----------
reykit/remail.py CHANGED
@@ -14,20 +14,19 @@ from email.mime.multipart import MIMEMultipart
14
14
  from email.mime.text import MIMEText
15
15
  from email.mime.application import MIMEApplication
16
16
 
17
+ from .rbase import Base, throw
17
18
  from .rdata import unique
18
- from .rexc import throw
19
19
  from .ros import FileBytes, get_file_bytes
20
- from .rtype import RBase
21
20
 
22
21
 
23
22
  __all__ = (
24
- 'REmail',
23
+ 'Email',
25
24
  )
26
25
 
27
26
 
28
- class REmail(RBase):
27
+ class Email(Base):
29
28
  """
30
- Rey's `email` type.
29
+ Email type.
31
30
  """
32
31
 
33
32
 
@@ -37,7 +36,7 @@ class REmail(RBase):
37
36
  password: str
38
37
  ) -> None:
39
38
  """
40
- Build `email` instance attributes.
39
+ Build instance attributes.
41
40
 
42
41
  Parameters
43
42
  ----------
@@ -108,7 +107,7 @@ class REmail(RBase):
108
107
  show_cc: list[str] | None
109
108
  ) -> str:
110
109
  """
111
- create email content.
110
+ Create email content.
112
111
 
113
112
  Parameters
114
113
  ----------
reykit/rimage.py CHANGED
@@ -17,12 +17,12 @@ from PIL.Image import open as pil_open, LANCZOS
17
17
  from captcha.image import ImageCaptcha
18
18
 
19
19
  from .rmonkey import monkey_path_pil_image_get_bytes
20
- from .ros import RFile
20
+ from .ros import File
21
21
  from .rrand import randchar
22
22
 
23
23
 
24
24
  __all__ = (
25
- 'RImage',
25
+ 'Image',
26
26
  'encode_qrcode',
27
27
  'decode_qrcode',
28
28
  'compress_image',
@@ -32,8 +32,8 @@ __all__ = (
32
32
 
33
33
 
34
34
  # Monkey path.
35
- monkey_image_type = monkey_path_pil_image_get_bytes()
36
- RImage = monkey_image_type
35
+ Image_ = monkey_path_pil_image_get_bytes()
36
+ Image = Image_
37
37
 
38
38
 
39
39
  def encode_qrcode(text: str, path: str | None = None) -> bytes:
@@ -61,7 +61,7 @@ def encode_qrcode(text: str, path: str | None = None) -> bytes:
61
61
 
62
62
  # Save.
63
63
  if path is not None:
64
- rfile = RFile(path)
64
+ rfile = File(path)
65
65
  rfile.write(file_bytes)
66
66
 
67
67
  return file_bytes
@@ -139,7 +139,7 @@ def compress_image(
139
139
 
140
140
  # Handle parameter.
141
141
  if type(input_image) == str:
142
- rfile = RFile(input_image)
142
+ rfile = File(input_image)
143
143
  input_image = rfile.str
144
144
  now_size = len(input_image)
145
145
  if target_size < 1:
@@ -180,11 +180,11 @@ def compress_image(
180
180
 
181
181
  ## Save file and return path.
182
182
  else:
183
- rfile = RFile(ouput_image)
183
+ rfile = File(ouput_image)
184
184
  rfile(content)
185
185
 
186
186
 
187
- def to_pil_image(source: str | bytes) -> RImage:
187
+ def to_pil_image(source: str | bytes) -> Image:
188
188
  """
189
189
  Get `Image` instance of `PIL` package.
190
190
 
@@ -247,12 +247,12 @@ def generate_captcha_image(
247
247
  }
248
248
  default_kwargs.update(kwargs)
249
249
  icaptcha = ImageCaptcha(**default_kwargs)
250
- image: RImage = icaptcha.generate_image(text)
250
+ image: Image = icaptcha.generate_image(text)
251
251
  file_bytes = image.get_bytes()
252
252
 
253
253
  # Save.
254
254
  if path is not None:
255
- rfile = RFile(path)
255
+ rfile = File(path)
256
256
  rfile.write(file_bytes)
257
257
 
258
258
  return file_bytes
reykit/rlog.py CHANGED
@@ -29,36 +29,34 @@ from logging import (
29
29
  from logging.handlers import QueueHandler
30
30
  from concurrent_log_handler import ConcurrentRotatingFileHandler, ConcurrentTimedRotatingFileHandler
31
31
 
32
- from .rexc import throw, catch_exc
33
- from .ros import RFile
32
+ from .rbase import Base, ConfigMeta, throw, catch_exc, get_first_notnone, get_stack_param
33
+ from .ros import File
34
34
  from .rre import search, sub
35
- from .rstdout import RConfigStdout, modify_print, reset_print
36
- from .rsys import get_first_notnull, get_stack_param
35
+ from .rstdout import ConfigStdout, modify_print, reset_print
37
36
  from .rtext import to_text
38
37
  from .rtime import now, time_to
39
- from .rtype import RBase, RConfigMeta
40
38
  from .rwrap import wrap_thread
41
39
 
42
40
 
43
41
  __all__ = (
44
- 'RConfigLog',
45
- 'RLog',
46
- 'RRecord'
42
+ 'ConfigLog',
43
+ 'Log',
44
+ 'Record'
47
45
  )
48
46
 
49
47
 
50
- class RConfigLog(object, metaclass=RConfigMeta):
48
+ class ConfigLog(Base, metaclass=ConfigMeta):
51
49
  """
52
- Rey's `config log` type.
50
+ Config log type.
53
51
  """
54
52
 
55
53
  # Module path.
56
54
  path_rlog: Final[str] = os_abspath(__file__)
57
55
 
58
56
 
59
- class RLog(object):
57
+ class Log(Base):
60
58
  """
61
- Rey's `log` type.
59
+ Log type.
62
60
  """
63
61
 
64
62
  # Status.
@@ -90,7 +88,7 @@ class RLog(object):
90
88
  name: str = 'Log'
91
89
  ) -> None:
92
90
  """
93
- Build `log` instance attributes.
91
+ Build instance attributes.
94
92
 
95
93
  Parameters
96
94
  ----------
@@ -125,21 +123,21 @@ class RLog(object):
125
123
 
126
124
  ## Compatible '__call__'.
127
125
  if (
128
- stack_param['filename'] == RConfigLog.path_rlog
126
+ stack_param['filename'] == ConfigLog.path_rlog
129
127
  and stack_param['name'] in ('debug', 'info', 'warning', 'error', 'critical')
130
128
  ):
131
129
  stack_param = stack_params[-2]
132
130
 
133
131
  ## Compatible 'print'.
134
132
  if (
135
- stack_param['filename'] == RConfigLog.path_rlog
133
+ stack_param['filename'] == ConfigLog.path_rlog
136
134
  and stack_param['name'] == 'preprocess'
137
135
  ):
138
136
  stack_param = stack_params[-3]
139
137
 
140
138
  ## Compatible 'echo'.
141
139
  if (
142
- stack_param['filename'] == RConfigStdout._path_rstdout
140
+ stack_param['filename'] == ConfigStdout._path_rstdout
143
141
  and stack_param['name'] == 'echo'
144
142
  ):
145
143
  stack_param = stack_params[-4]
@@ -347,7 +345,7 @@ class RLog(object):
347
345
  def get_filter(
348
346
  self,
349
347
  method: Callable[[LogRecord], bool]
350
- ) -> Filter:
348
+ ):
351
349
  """
352
350
  Get filter.
353
351
 
@@ -362,9 +360,9 @@ class RLog(object):
362
360
 
363
361
 
364
362
  # Define.
365
- class RFilter(Filter):
363
+ class _Filter(Base, Filter):
366
364
  """
367
- Rey's filter type.
365
+ Filter type.
368
366
  """
369
367
 
370
368
 
@@ -389,7 +387,7 @@ class RLog(object):
389
387
  return result
390
388
 
391
389
 
392
- return RFilter
390
+ return _Filter
393
391
 
394
392
 
395
393
  def add_print(
@@ -421,7 +419,7 @@ class RLog(object):
421
419
  """
422
420
 
423
421
  # Get parameter.
424
- format_ = get_first_notnull(format_, self.default_format, default='exception')
422
+ format_ = get_first_notnone(format_, self.default_format)
425
423
  filter_ = filter_ or self.get_default_filter_method(format_, 'print')
426
424
 
427
425
  # Create handler.
@@ -443,7 +441,7 @@ class RLog(object):
443
441
  self,
444
442
  path: str | None = None,
445
443
  mb: float | None = None,
446
- time: None = None,
444
+ *,
447
445
  level: int = DEBUG,
448
446
  format_: str | None = None,
449
447
  filter_: Callable[[LogRecord], bool] | None = None
@@ -453,7 +451,7 @@ class RLog(object):
453
451
  def add_file(
454
452
  self,
455
453
  path: str | None = None,
456
- mb: None = None,
454
+ *,
457
455
  time: float | Literal['m', 'w0', 'w1', 'w2', 'w3', 'w4', 'w5', 'w6'] = None,
458
456
  level: int = DEBUG,
459
457
  format_: str | None = None,
@@ -500,7 +498,7 @@ class RLog(object):
500
498
  """
501
499
 
502
500
  # Get parameter.
503
- format_ = get_first_notnull(format_, self.default_format, default='exception')
501
+ format_ = get_first_notnone(format_, self.default_format)
504
502
  path = path or self.name
505
503
  filter_ = filter_ or self.get_default_filter_method(format_, 'file')
506
504
 
@@ -938,9 +936,9 @@ class RLog(object):
938
936
  __call__ = log
939
937
 
940
938
 
941
- class RRecord(object):
939
+ class Record(Base):
942
940
  """
943
- Rey's `record` type.
941
+ Record type.
944
942
  """
945
943
 
946
944
 
@@ -949,7 +947,7 @@ class RRecord(object):
949
947
  path: str | None = '_rrecord'
950
948
  ) -> None:
951
949
  """
952
- Build `record` instance attributes.
950
+ Build instance attributes.
953
951
 
954
952
  Parameters
955
953
  ----------
@@ -982,7 +980,7 @@ class RRecord(object):
982
980
 
983
981
  # To file.
984
982
  else:
985
- rfile = RFile(self.path)
983
+ rfile = File(self.path)
986
984
 
987
985
  ## Convert.
988
986
  if type(value) != str:
@@ -1018,7 +1016,7 @@ class RRecord(object):
1018
1016
 
1019
1017
  # To file.
1020
1018
  else:
1021
- rfile = RFile(self.path)
1019
+ rfile = File(self.path)
1022
1020
 
1023
1021
  ## Convert.
1024
1022
  if type(value) != str:
reykit/rmonkey.py CHANGED
@@ -48,6 +48,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
48
48
  # Import.
49
49
  from sqlalchemy.engine.cursor import CursorResult
50
50
  from pandas import DataFrame, NA, concat
51
+ from .rbase import Base
51
52
  from .rstdout import echo
52
53
  from .rtable import (
53
54
  to_table,
@@ -95,7 +96,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
95
96
 
96
97
 
97
98
  # Print result.
98
- def method_show(self: RResult, limit: int | None = None) -> None:
99
+ def method_show(self: Result, limit: int | None = None) -> None:
99
100
  """
100
101
  Print result.
101
102
 
@@ -149,7 +150,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
149
150
 
150
151
  # Whether is exist.
151
152
  @property
152
- def method_exist(self: RResult) -> bool:
153
+ def method_exist(self: Result) -> bool:
153
154
  """
154
155
  Judge whether is exist row.
155
156
 
@@ -169,7 +170,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
169
170
 
170
171
  # Whether is empty.
171
172
  @property
172
- def method_empty(self: RResult) -> bool:
173
+ def method_empty(self: Result) -> bool:
173
174
  """
174
175
  Judge whether is empty row.
175
176
 
@@ -188,7 +189,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
188
189
 
189
190
 
190
191
  # Update annotations.
191
- class RResult(CursorResult):
192
+ class Result(Base, CursorResult):
192
193
  """
193
194
  Update based on `CursorResult` object, for annotation return value.
194
195
  """
@@ -212,7 +213,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
212
213
  empty = method_empty
213
214
 
214
215
 
215
- return RResult
216
+ return Result
216
217
 
217
218
 
218
219
  def monkey_patch_sqlalchemy_row_index_field():
@@ -322,6 +323,7 @@ def monkey_path_pil_image_get_bytes():
322
323
 
323
324
  from PIL.Image import Image
324
325
  from io import BytesIO
326
+ from reykit.rbase import Base
325
327
 
326
328
 
327
329
  # Define.
@@ -347,7 +349,7 @@ def monkey_path_pil_image_get_bytes():
347
349
 
348
350
 
349
351
  # Update annotations.
350
- class RImage(Image):
352
+ class Image(Base, Image):
351
353
  """
352
354
  Update based on `Image` object, for annotation return value.
353
355
  """
@@ -359,4 +361,4 @@ def monkey_path_pil_image_get_bytes():
359
361
  get_bytes = method_get_bytes
360
362
 
361
363
 
362
- return RImage
364
+ return Image
reykit/rnet.py CHANGED
@@ -30,10 +30,9 @@ from mimetypes import guess_type
30
30
  from filetype import guess as filetype_guess
31
31
  from datetime import datetime
32
32
 
33
- from .rexc import throw, check_response_code
34
- from .ros import RFile
33
+ from .rbase import Base, throw, check_response_code
34
+ from .ros import File
35
35
  from .rre import search
36
- from .rtype import RBase
37
36
 
38
37
 
39
38
  __all__ = (
@@ -46,7 +45,7 @@ __all__ = (
46
45
  'download',
47
46
  'compute_stream_time',
48
47
  'listen_socket',
49
- 'RRequestCache'
48
+ 'RequestCache'
50
49
  )
51
50
 
52
51
 
@@ -276,7 +275,7 @@ def request(
276
275
  method = 'post'
277
276
  if files is None:
278
277
  if type(data) == str:
279
- rfile = RFile(data)
278
+ rfile = File(data)
280
279
  data = rfile.bytes
281
280
  if 'Content-Disposition' not in headers:
282
281
  file_name = rfile.name_suffix
@@ -291,7 +290,7 @@ def request(
291
290
  else:
292
291
  item_data, item_headers = value, {}
293
292
  if type(item_data) == str:
294
- rfile = RFile(item_data)
293
+ rfile = File(item_data)
295
294
  data = rfile.bytes
296
295
  item_headers.setdefault('filename', rfile.name_suffix)
297
296
  if type(item_data) == bytes:
@@ -381,7 +380,7 @@ def download(url: str, path: str | None = None) -> str:
381
380
  path = os_abspath(file_name)
382
381
 
383
382
  # Save.
384
- rfile = RFile(path)
383
+ rfile = File(path)
385
384
  rfile(content)
386
385
 
387
386
  return path
@@ -410,7 +409,7 @@ def compute_stream_time(
410
409
  # Get parameter.
411
410
  match file:
412
411
  case str():
413
- rfile = RFile(file)
412
+ rfile = File(file)
414
413
  file_size = rfile.size
415
414
  case bytes() | bytearray():
416
415
  file_size = len(file)
@@ -456,9 +455,9 @@ def listen_socket(
456
455
  handler(data)
457
456
 
458
457
 
459
- class RRequestCache(RBase):
458
+ class RequestCache(Base):
460
459
  """
461
- Rey's `requests cache` type.
460
+ Requests cache type.
462
461
  """
463
462
 
464
463
 
@@ -471,7 +470,7 @@ class RRequestCache(RBase):
471
470
  judge: Callable[[Response | OriginalResponse | CachedResponse], bool] | None = None
472
471
  ) -> None:
473
472
  """
474
- Build `requests cache` instance attributes.
473
+ Build instance attributes.
475
474
 
476
475
  Parameters
477
476
  ----------
reykit/rnum.py CHANGED
@@ -11,10 +11,11 @@
11
11
 
12
12
  from typing import Any
13
13
 
14
- from .rexc import throw
14
+ from .rbase import throw
15
15
 
16
16
 
17
17
  __all__ = (
18
+ 'is_int',
18
19
  'digits',
19
20
  'to_number',
20
21
  'number_ch'