reykit 1.1.25__py3-none-any.whl → 1.1.26__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
@@ -16,7 +16,7 @@ from itertools import chain as IChain
16
16
 
17
17
  from .rexc import check_least_one, check_most_one
18
18
  from .rsys import is_iterable
19
- from .rtype import T, KT, VT, RBase, Null
19
+ from .rtype import T, KT, VT, Base, null
20
20
 
21
21
 
22
22
  __all__ = (
@@ -28,7 +28,7 @@ __all__ = (
28
28
  'objs_in',
29
29
  'chain',
30
30
  'default_dict',
31
- 'RGenerator'
31
+ 'FunctionGenerator'
32
32
  )
33
33
 
34
34
 
@@ -320,14 +320,14 @@ def chain(*iterables: dict[KT, VT] | Iterable[T]) -> ChainMap[KT, VT] | IChain[T
320
320
  return data
321
321
 
322
322
 
323
- def default_dict(default: T = Null, data: dict[KT, VT] | None = None) -> Defaultdict[KT, VT | T]:
323
+ def default_dict(default: T = null, data: dict[KT, VT] | None = None) -> Defaultdict[KT, VT | T]:
324
324
  """
325
325
  Set `dict` instance, default value when key does not exist.
326
326
 
327
327
  Parameters
328
328
  ----------
329
329
  default : Default value.
330
- - `Literal[Null]`: Nest function self.
330
+ - `Literal[null]`: Nest function self.
331
331
  - `Callable`: Use call return value.
332
332
  data : `dict` instance.
333
333
  - `None`: Empty `dict`.
@@ -336,7 +336,7 @@ def default_dict(default: T = Null, data: dict[KT, VT] | None = None) -> Default
336
336
  # Handle parameter.
337
337
 
338
338
  ## Null.
339
- if default == Null:
339
+ if default == null:
340
340
  default_factory = default_dict
341
341
 
342
342
  ## Callable.
@@ -356,9 +356,18 @@ def default_dict(default: T = Null, data: dict[KT, VT] | None = None) -> Default
356
356
  return dict_set
357
357
 
358
358
 
359
- class RGenerator(RBase):
359
+ class FunctionGenerator(Base):
360
360
  """
361
- Rey's `generator` type.
361
+ Function generator type.
362
+
363
+ Examples
364
+ --------
365
+ >>> func = lambda arg1, arg2: arg1 + arg2
366
+ >>> fgenerator = FunctionGenerator(func, 10)
367
+ >>> fgenerator.add(1)
368
+ >>> fgenerator.add(2)
369
+ >>> list(fgenerator)
370
+ [11, 12]
362
371
  """
363
372
 
364
373
 
@@ -369,7 +378,7 @@ class RGenerator(RBase):
369
378
  **kwargs: Any
370
379
  ) -> None:
371
380
  """
372
- Build `generator` instance attributes.
381
+ Build instance attributes.
373
382
 
374
383
  Parameters
375
384
  ----------
reykit/remail.py CHANGED
@@ -17,17 +17,17 @@ from email.mime.application import MIMEApplication
17
17
  from .rdata import unique
18
18
  from .rexc import throw
19
19
  from .ros import FileBytes, get_file_bytes
20
- from .rtype import RBase
20
+ from .rtype import Base
21
21
 
22
22
 
23
23
  __all__ = (
24
- 'REmail',
24
+ 'Email',
25
25
  )
26
26
 
27
27
 
28
- class REmail(RBase):
28
+ class Email(Base):
29
29
  """
30
- Rey's `email` type.
30
+ Email type.
31
31
  """
32
32
 
33
33
 
@@ -37,7 +37,7 @@ class REmail(RBase):
37
37
  password: str
38
38
  ) -> None:
39
39
  """
40
- Build `email` instance attributes.
40
+ Build instance attributes.
41
41
 
42
42
  Parameters
43
43
  ----------
@@ -108,7 +108,7 @@ class REmail(RBase):
108
108
  show_cc: list[str] | None
109
109
  ) -> str:
110
110
  """
111
- create email content.
111
+ Create email content.
112
112
 
113
113
  Parameters
114
114
  ----------
reykit/rexc.py CHANGED
@@ -17,12 +17,12 @@ from os.path import exists as os_exists
17
17
  from traceback import format_exc
18
18
  from warnings import warn as warnings_warn
19
19
 
20
- from .rtype import Null
20
+ from .rtype import Base, null
21
21
 
22
22
 
23
23
  __all__ = (
24
- 'RError',
25
- 'RActiveError',
24
+ 'Error',
25
+ 'ActiveError',
26
26
  'throw',
27
27
  'warn',
28
28
  'catch_exc',
@@ -34,21 +34,21 @@ __all__ = (
34
34
  )
35
35
 
36
36
 
37
- class RError(Exception):
37
+ class Error(Base, Exception):
38
38
  """
39
- Rey `error` type.
39
+ Error type.
40
40
  """
41
41
 
42
42
 
43
- class RActiveError(RError):
43
+ class ActiveError(Error):
44
44
  """
45
- Rey's `active error` type.
45
+ Active error type.
46
46
  """
47
47
 
48
48
 
49
49
  def throw(
50
50
  exception: type[BaseException] = AssertionError,
51
- value: Any = Null,
51
+ value: Any = null,
52
52
  *values: Any,
53
53
  text: str | None = None,
54
54
  frame: int = 2
@@ -78,7 +78,7 @@ def throw(
78
78
  text = text[0].lower() + text[1:]
79
79
 
80
80
  ## Value.
81
- if value != Null:
81
+ if value != null:
82
82
  values = (value,) + values
83
83
 
84
84
  ### Name.
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',
@@ -33,7 +33,7 @@ __all__ = (
33
33
 
34
34
  # Monkey path.
35
35
  monkey_image_type = monkey_path_pil_image_get_bytes()
36
- RImage = monkey_image_type
36
+ Image = monkey_image_type
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
@@ -30,35 +30,35 @@ from logging.handlers import QueueHandler
30
30
  from concurrent_log_handler import ConcurrentRotatingFileHandler, ConcurrentTimedRotatingFileHandler
31
31
 
32
32
  from .rexc import throw, catch_exc
33
- from .ros import RFile
33
+ from .ros import File
34
34
  from .rre import search, sub
35
- from .rstdout import RConfigStdout, modify_print, reset_print
35
+ from .rstdout import ConfigStdout, modify_print, reset_print
36
36
  from .rsys import get_first_notnull, get_stack_param
37
37
  from .rtext import to_text
38
38
  from .rtime import now, time_to
39
- from .rtype import RBase, RConfigMeta
39
+ from .rtype import Base, ConfigMeta
40
40
  from .rwrap import wrap_thread
41
41
 
42
42
 
43
43
  __all__ = (
44
- 'RConfigLog',
45
- 'RLog',
46
- 'RRecord'
44
+ 'ConfigLog',
45
+ 'Log',
46
+ 'Record'
47
47
  )
48
48
 
49
49
 
50
- class RConfigLog(object, metaclass=RConfigMeta):
50
+ class ConfigLog(Base, metaclass=ConfigMeta):
51
51
  """
52
- Rey's `config log` type.
52
+ Config log type.
53
53
  """
54
54
 
55
55
  # Module path.
56
56
  path_rlog: Final[str] = os_abspath(__file__)
57
57
 
58
58
 
59
- class RLog(object):
59
+ class Log(Base):
60
60
  """
61
- Rey's `log` type.
61
+ Log type.
62
62
  """
63
63
 
64
64
  # Status.
@@ -90,7 +90,7 @@ class RLog(object):
90
90
  name: str = 'Log'
91
91
  ) -> None:
92
92
  """
93
- Build `log` instance attributes.
93
+ Build instance attributes.
94
94
 
95
95
  Parameters
96
96
  ----------
@@ -125,21 +125,21 @@ class RLog(object):
125
125
 
126
126
  ## Compatible '__call__'.
127
127
  if (
128
- stack_param['filename'] == RConfigLog.path_rlog
128
+ stack_param['filename'] == ConfigLog.path_rlog
129
129
  and stack_param['name'] in ('debug', 'info', 'warning', 'error', 'critical')
130
130
  ):
131
131
  stack_param = stack_params[-2]
132
132
 
133
133
  ## Compatible 'print'.
134
134
  if (
135
- stack_param['filename'] == RConfigLog.path_rlog
135
+ stack_param['filename'] == ConfigLog.path_rlog
136
136
  and stack_param['name'] == 'preprocess'
137
137
  ):
138
138
  stack_param = stack_params[-3]
139
139
 
140
140
  ## Compatible 'echo'.
141
141
  if (
142
- stack_param['filename'] == RConfigStdout._path_rstdout
142
+ stack_param['filename'] == ConfigStdout._path_rstdout
143
143
  and stack_param['name'] == 'echo'
144
144
  ):
145
145
  stack_param = stack_params[-4]
@@ -347,7 +347,7 @@ class RLog(object):
347
347
  def get_filter(
348
348
  self,
349
349
  method: Callable[[LogRecord], bool]
350
- ) -> Filter:
350
+ ):
351
351
  """
352
352
  Get filter.
353
353
 
@@ -362,9 +362,9 @@ class RLog(object):
362
362
 
363
363
 
364
364
  # Define.
365
- class RFilter(Filter):
365
+ class _Filter(Base, Filter):
366
366
  """
367
- Rey's filter type.
367
+ Filter type.
368
368
  """
369
369
 
370
370
 
@@ -389,7 +389,7 @@ class RLog(object):
389
389
  return result
390
390
 
391
391
 
392
- return RFilter
392
+ return _Filter
393
393
 
394
394
 
395
395
  def add_print(
@@ -938,9 +938,9 @@ class RLog(object):
938
938
  __call__ = log
939
939
 
940
940
 
941
- class RRecord(object):
941
+ class Record(Base):
942
942
  """
943
- Rey's `record` type.
943
+ Record type.
944
944
  """
945
945
 
946
946
 
@@ -949,7 +949,7 @@ class RRecord(object):
949
949
  path: str | None = '_rrecord'
950
950
  ) -> None:
951
951
  """
952
- Build `record` instance attributes.
952
+ Build instance attributes.
953
953
 
954
954
  Parameters
955
955
  ----------
@@ -982,7 +982,7 @@ class RRecord(object):
982
982
 
983
983
  # To file.
984
984
  else:
985
- rfile = RFile(self.path)
985
+ rfile = File(self.path)
986
986
 
987
987
  ## Convert.
988
988
  if type(value) != str:
@@ -1018,7 +1018,7 @@ class RRecord(object):
1018
1018
 
1019
1019
  # To file.
1020
1020
  else:
1021
- rfile = RFile(self.path)
1021
+ rfile = File(self.path)
1022
1022
 
1023
1023
  ## Convert.
1024
1024
  if type(value) != str:
reykit/rmonkey.py CHANGED
@@ -62,6 +62,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
62
62
  to_excel
63
63
  )
64
64
  from .rtime import time_to
65
+ from .rtype import Base
65
66
 
66
67
  # Fetch result as table in 'list[dict]' format.
67
68
  CursorResult.fetch_table = 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.rtype 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
@@ -31,9 +31,9 @@ from filetype import guess as filetype_guess
31
31
  from datetime import datetime
32
32
 
33
33
  from .rexc import throw, check_response_code
34
- from .ros import RFile
34
+ from .ros import File
35
35
  from .rre import search
36
- from .rtype import RBase
36
+ from .rtype import Base
37
37
 
38
38
 
39
39
  __all__ = (
@@ -46,7 +46,7 @@ __all__ = (
46
46
  'download',
47
47
  'compute_stream_time',
48
48
  'listen_socket',
49
- 'RRequestCache'
49
+ 'RequestCache'
50
50
  )
51
51
 
52
52
 
@@ -276,7 +276,7 @@ def request(
276
276
  method = 'post'
277
277
  if files is None:
278
278
  if type(data) == str:
279
- rfile = RFile(data)
279
+ rfile = File(data)
280
280
  data = rfile.bytes
281
281
  if 'Content-Disposition' not in headers:
282
282
  file_name = rfile.name_suffix
@@ -291,7 +291,7 @@ def request(
291
291
  else:
292
292
  item_data, item_headers = value, {}
293
293
  if type(item_data) == str:
294
- rfile = RFile(item_data)
294
+ rfile = File(item_data)
295
295
  data = rfile.bytes
296
296
  item_headers.setdefault('filename', rfile.name_suffix)
297
297
  if type(item_data) == bytes:
@@ -381,7 +381,7 @@ def download(url: str, path: str | None = None) -> str:
381
381
  path = os_abspath(file_name)
382
382
 
383
383
  # Save.
384
- rfile = RFile(path)
384
+ rfile = File(path)
385
385
  rfile(content)
386
386
 
387
387
  return path
@@ -410,7 +410,7 @@ def compute_stream_time(
410
410
  # Get parameter.
411
411
  match file:
412
412
  case str():
413
- rfile = RFile(file)
413
+ rfile = File(file)
414
414
  file_size = rfile.size
415
415
  case bytes() | bytearray():
416
416
  file_size = len(file)
@@ -456,9 +456,9 @@ def listen_socket(
456
456
  handler(data)
457
457
 
458
458
 
459
- class RRequestCache(RBase):
459
+ class RequestCache(Base):
460
460
  """
461
- Rey's `requests cache` type.
461
+ Requests cache type.
462
462
  """
463
463
 
464
464
 
@@ -471,7 +471,7 @@ class RRequestCache(RBase):
471
471
  judge: Callable[[Response | OriginalResponse | CachedResponse], bool] | None = None
472
472
  ) -> None:
473
473
  """
474
- Build `requests cache` instance attributes.
474
+ Build instance attributes.
475
475
 
476
476
  Parameters
477
477
  ----------