reykit 1.1.24__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/__init__.py CHANGED
@@ -10,23 +10,23 @@
10
10
  Modules
11
11
  -------
12
12
  rall : All methods.
13
- rcomm : Network communication methods.
14
13
  rdata : Data methods.
15
14
  rdll : DLL file methods.
16
15
  remail : E-mail methods.
17
- rexception : Exception methods.
16
+ rexc : Exception methods.
18
17
  rimage : Image methods.
19
18
  rlog : Log methods.
20
19
  rmonkey : Monkey patch methods.
21
- rmultitask : Multi task methods.
22
- rnumber : Number methods.
20
+ rnet : Network methods.
21
+ rnum : Number methods.
23
22
  ros: Operation system methods.
24
- rrandom : Random methods.
25
- rregex : Regular expression methods.
23
+ rrand : Random methods.
24
+ rre : Regular expression methods.
26
25
  rschedule : Schedule methods.
27
- rstdout : Standard output methods.
28
- rsystem : Interpreter system methods.
26
+ rstdout : Standard output and input methods.
27
+ rsys : Interpreter system methods.
29
28
  rtable : Table methods.
29
+ rtask : Multi task methods.
30
30
  rtext : Text methods.
31
31
  rtime : Time methods.
32
32
  rtype : Type methods.
reykit/rall.py CHANGED
@@ -9,23 +9,23 @@
9
9
  """
10
10
 
11
11
 
12
- from .rcomm import *
13
12
  from .rdata import *
14
13
  from .rdll import *
15
14
  from .remail import *
16
- from .rexception import *
15
+ from .rexc import *
17
16
  from .rimage import *
18
17
  from .rlog import *
19
18
  from .rmonkey import *
20
- from .rmultitask import *
21
- from .rnumber import *
19
+ from .rnet import *
20
+ from .rnum import *
22
21
  from .ros import *
23
- from .rrandom import *
24
- from .rregex import *
22
+ from .rrand import *
23
+ from .rre import *
25
24
  from .rschedule import *
26
25
  from .rstdout import *
27
- from .rsystem import *
26
+ from .rsys import *
28
27
  from .rtable import *
28
+ from .rtask import *
29
29
  from .rtext import *
30
30
  from .rtime import *
31
31
  from .rtype import *
reykit/rdata.py CHANGED
@@ -14,9 +14,9 @@ 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 .rexception import check_least_one, check_most_one
18
- from .rsystem import is_iterable
19
- from .rtype import T, KT, VT, RBase, Null
17
+ from .rexc import check_least_one, check_most_one
18
+ from .rsys import is_iterable
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/rdll/__init__.py CHANGED
@@ -9,9 +9,37 @@
9
9
 
10
10
  Modules
11
11
  -------
12
- rdll_inject_core : DLL file inject method code.
13
- rdll_inject : DLL file inject method.
12
+ rdll_core : DLL file code methods.
14
13
  """
15
14
 
16
15
 
17
- from .rdll_inject import *
16
+ from ctypes import create_string_buffer
17
+
18
+ from .rdll_core import InjectDLL
19
+
20
+
21
+ __all__ = (
22
+ 'inject_dll',
23
+ )
24
+
25
+
26
+ def inject_dll(
27
+ id_: int,
28
+ path: str
29
+ ) -> None:
30
+ """
31
+ Inject DLL file.
32
+
33
+ Parameters
34
+ ----------
35
+ id_ : Process ID.
36
+ path : DLL file path.
37
+ """
38
+
39
+
40
+ # Get parameter.
41
+ path_bytes = path.encode()
42
+ buffer = create_string_buffer(path_bytes)
43
+
44
+ # Inject.
45
+ InjectDLL(id_, buffer)
@@ -5,7 +5,7 @@
5
5
  @Time : 2023-12-06 16:17:04
6
6
  @Author : Rey
7
7
  @Contact : reyxbo@163.com
8
- @Explain : DLL file inject method code.
8
+ @Explain : DLL file code methods.
9
9
  """
10
10
 
11
11
 
reykit/remail.py CHANGED
@@ -15,19 +15,19 @@ from email.mime.text import MIMEText
15
15
  from email.mime.application import MIMEApplication
16
16
 
17
17
  from .rdata import unique
18
- from .rexception import throw
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
  ----------
@@ -9,17 +9,6 @@
9
9
  """
10
10
 
11
11
 
12
- # !/usr/bin/env python
13
- # -*- coding: utf-8 -*-
14
-
15
- """
16
- @Time : 2022-12-05 14:09:42
17
- @Author : Rey
18
- @Contact : reyxbo@163.com
19
- @Explain : Interpreter system methods.
20
- """
21
-
22
-
23
12
  from typing import Any, NoReturn, overload
24
13
  from types import TracebackType
25
14
  from collections.abc import Iterable
@@ -28,12 +17,12 @@ from os.path import exists as os_exists
28
17
  from traceback import format_exc
29
18
  from warnings import warn as warnings_warn
30
19
 
31
- from .rtype import Null
20
+ from .rtype import Base, null
32
21
 
33
22
 
34
23
  __all__ = (
35
- 'RError',
36
- 'RActiveError',
24
+ 'Error',
25
+ 'ActiveError',
37
26
  'throw',
38
27
  'warn',
39
28
  'catch_exc',
@@ -45,21 +34,21 @@ __all__ = (
45
34
  )
46
35
 
47
36
 
48
- class RError(Exception):
37
+ class Error(Base, Exception):
49
38
  """
50
- Rey `error` type.
39
+ Error type.
51
40
  """
52
41
 
53
42
 
54
- class RActiveError(RError):
43
+ class ActiveError(Error):
55
44
  """
56
- Rey's `active error` type.
45
+ Active error type.
57
46
  """
58
47
 
59
48
 
60
49
  def throw(
61
50
  exception: type[BaseException] = AssertionError,
62
- value: Any = Null,
51
+ value: Any = null,
63
52
  *values: Any,
64
53
  text: str | None = None,
65
54
  frame: int = 2
@@ -89,11 +78,11 @@ def throw(
89
78
  text = text[0].lower() + text[1:]
90
79
 
91
80
  ## Value.
92
- if value != Null:
81
+ if value != null:
93
82
  values = (value,) + values
94
83
 
95
84
  ### Name.
96
- from .rsystem import get_name
85
+ from .rsys import get_name
97
86
  name = get_name(value, frame)
98
87
  names = (name,)
99
88
  if values != ():
@@ -234,7 +223,7 @@ def check_least_one(*values: Any) -> None:
234
223
  return
235
224
 
236
225
  # Throw exception.
237
- from .rsystem import get_name
226
+ from .rsys import get_name
238
227
  vars_name = get_name(values)
239
228
  if vars_name is not None:
240
229
  vars_name_de_dup = list(set(vars_name))
@@ -261,7 +250,7 @@ def check_most_one(*values: Any) -> None:
261
250
  if exist is True:
262
251
 
263
252
  # Throw exception.
264
- from .rsystem import get_name
253
+ from .rsys import get_name
265
254
  vars_name = get_name(values)
266
255
  if vars_name is not None:
267
256
  vars_name_de_dup = list(set(vars_name))
reykit/rimage.py CHANGED
@@ -16,19 +16,13 @@ from qrcode.image.pil import PilImage
16
16
  from PIL.Image import open as pil_open, LANCZOS
17
17
  from captcha.image import ImageCaptcha
18
18
 
19
- from .rexception import catch_exc
20
19
  from .rmonkey import monkey_path_pil_image_get_bytes
21
- from .ros import RFile
22
- from .rrandom import randchar
23
-
24
- try:
25
- from pyzbar.pyzbar import decode as pyzbar_decode
26
- except:
27
- *_, pyzbar_decode, _ = catch_exc()
20
+ from .ros import File
21
+ from .rrand import randchar
28
22
 
29
23
 
30
24
  __all__ = (
31
- 'RImage',
25
+ 'Image',
32
26
  'encode_qrcode',
33
27
  'decode_qrcode',
34
28
  'compress_image',
@@ -39,7 +33,7 @@ __all__ = (
39
33
 
40
34
  # Monkey path.
41
35
  monkey_image_type = monkey_path_pil_image_get_bytes()
42
- RImage = monkey_image_type
36
+ Image = monkey_image_type
43
37
 
44
38
 
45
39
  def encode_qrcode(text: str, path: str | None = None) -> bytes:
@@ -67,7 +61,7 @@ def encode_qrcode(text: str, path: str | None = None) -> bytes:
67
61
 
68
62
  # Save.
69
63
  if path is not None:
70
- rfile = RFile(path)
64
+ rfile = File(path)
71
65
  rfile.write(file_bytes)
72
66
 
73
67
  return file_bytes
@@ -86,6 +80,9 @@ def decode_qrcode(image: str | bytes) -> list[str]:
86
80
  QR code or bar code text list.
87
81
  """
88
82
 
83
+ # Import.
84
+ from pyzbar.pyzbar import decode as pyzbar_decode
85
+
89
86
  # Check.
90
87
  if isinstance(pyzbar_decode, BaseException):
91
88
  raise pyzbar_decode
@@ -142,7 +139,7 @@ def compress_image(
142
139
 
143
140
  # Handle parameter.
144
141
  if type(input_image) == str:
145
- rfile = RFile(input_image)
142
+ rfile = File(input_image)
146
143
  input_image = rfile.str
147
144
  now_size = len(input_image)
148
145
  if target_size < 1:
@@ -183,11 +180,11 @@ def compress_image(
183
180
 
184
181
  ## Save file and return path.
185
182
  else:
186
- rfile = RFile(ouput_image)
183
+ rfile = File(ouput_image)
187
184
  rfile(content)
188
185
 
189
186
 
190
- def to_pil_image(source: str | bytes) -> RImage:
187
+ def to_pil_image(source: str | bytes) -> Image:
191
188
  """
192
189
  Get `Image` instance of `PIL` package.
193
190
 
@@ -250,12 +247,12 @@ def generate_captcha_image(
250
247
  }
251
248
  default_kwargs.update(kwargs)
252
249
  icaptcha = ImageCaptcha(**default_kwargs)
253
- image: RImage = icaptcha.generate_image(text)
250
+ image: Image = icaptcha.generate_image(text)
254
251
  file_bytes = image.get_bytes()
255
252
 
256
253
  # Save.
257
254
  if path is not None:
258
- rfile = RFile(path)
255
+ rfile = File(path)
259
256
  rfile.write(file_bytes)
260
257
 
261
258
  return file_bytes
reykit/rlog.py CHANGED
@@ -9,7 +9,6 @@
9
9
  """
10
10
 
11
11
 
12
- from __future__ import annotations
13
12
  from typing import Any, Literal, Final, overload
14
13
  from collections.abc import Callable
15
14
  from queue import Queue
@@ -30,36 +29,36 @@ from logging import (
30
29
  from logging.handlers import QueueHandler
31
30
  from concurrent_log_handler import ConcurrentRotatingFileHandler, ConcurrentTimedRotatingFileHandler
32
31
 
33
- from .rexception import throw, catch_exc
34
- from .ros import RFile
35
- from .rregex import search, sub
36
- from .rstdout import RConfigStdout, modify_print, reset_print
37
- from .rsystem import get_first_notnull, get_stack_param
32
+ from .rexc import throw, catch_exc
33
+ from .ros import File
34
+ from .rre import search, sub
35
+ from .rstdout import ConfigStdout, modify_print, reset_print
36
+ from .rsys import get_first_notnull, get_stack_param
38
37
  from .rtext import to_text
39
38
  from .rtime import now, time_to
40
- from .rtype import RBase, RConfigMeta
39
+ from .rtype import Base, ConfigMeta
41
40
  from .rwrap import wrap_thread
42
41
 
43
42
 
44
43
  __all__ = (
45
- 'RConfigLog',
46
- 'RLog',
47
- 'RRecord'
44
+ 'ConfigLog',
45
+ 'Log',
46
+ 'Record'
48
47
  )
49
48
 
50
49
 
51
- class RConfigLog(object, metaclass=RConfigMeta):
50
+ class ConfigLog(Base, metaclass=ConfigMeta):
52
51
  """
53
- Rey's `config log` type.
52
+ Config log type.
54
53
  """
55
54
 
56
55
  # Module path.
57
56
  path_rlog: Final[str] = os_abspath(__file__)
58
57
 
59
58
 
60
- class RLog(object):
59
+ class Log(Base):
61
60
  """
62
- Rey's `log` type.
61
+ Log type.
63
62
  """
64
63
 
65
64
  # Status.
@@ -91,7 +90,7 @@ class RLog(object):
91
90
  name: str = 'Log'
92
91
  ) -> None:
93
92
  """
94
- Build `log` instance attributes.
93
+ Build instance attributes.
95
94
 
96
95
  Parameters
97
96
  ----------
@@ -126,21 +125,21 @@ class RLog(object):
126
125
 
127
126
  ## Compatible '__call__'.
128
127
  if (
129
- stack_param['filename'] == RConfigLog.path_rlog
128
+ stack_param['filename'] == ConfigLog.path_rlog
130
129
  and stack_param['name'] in ('debug', 'info', 'warning', 'error', 'critical')
131
130
  ):
132
131
  stack_param = stack_params[-2]
133
132
 
134
133
  ## Compatible 'print'.
135
134
  if (
136
- stack_param['filename'] == RConfigLog.path_rlog
135
+ stack_param['filename'] == ConfigLog.path_rlog
137
136
  and stack_param['name'] == 'preprocess'
138
137
  ):
139
138
  stack_param = stack_params[-3]
140
139
 
141
140
  ## Compatible 'echo'.
142
141
  if (
143
- stack_param['filename'] == RConfigStdout._path_rstdout
142
+ stack_param['filename'] == ConfigStdout._path_rstdout
144
143
  and stack_param['name'] == 'echo'
145
144
  ):
146
145
  stack_param = stack_params[-4]
@@ -348,7 +347,7 @@ class RLog(object):
348
347
  def get_filter(
349
348
  self,
350
349
  method: Callable[[LogRecord], bool]
351
- ) -> Filter:
350
+ ):
352
351
  """
353
352
  Get filter.
354
353
 
@@ -363,9 +362,9 @@ class RLog(object):
363
362
 
364
363
 
365
364
  # Define.
366
- class RFilter(Filter):
365
+ class _Filter(Base, Filter):
367
366
  """
368
- Rey's filter type.
367
+ Filter type.
369
368
  """
370
369
 
371
370
 
@@ -390,7 +389,7 @@ class RLog(object):
390
389
  return result
391
390
 
392
391
 
393
- return RFilter
392
+ return _Filter
394
393
 
395
394
 
396
395
  def add_print(
@@ -939,9 +938,9 @@ class RLog(object):
939
938
  __call__ = log
940
939
 
941
940
 
942
- class RRecord(object):
941
+ class Record(Base):
943
942
  """
944
- Rey's `record` type.
943
+ Record type.
945
944
  """
946
945
 
947
946
 
@@ -950,7 +949,7 @@ class RRecord(object):
950
949
  path: str | None = '_rrecord'
951
950
  ) -> None:
952
951
  """
953
- Build `record` instance attributes.
952
+ Build instance attributes.
954
953
 
955
954
  Parameters
956
955
  ----------
@@ -983,7 +982,7 @@ class RRecord(object):
983
982
 
984
983
  # To file.
985
984
  else:
986
- rfile = RFile(self.path)
985
+ rfile = File(self.path)
987
986
 
988
987
  ## Convert.
989
988
  if type(value) != str:
@@ -1019,7 +1018,7 @@ class RRecord(object):
1019
1018
 
1020
1019
  # To file.
1021
1020
  else:
1022
- rfile = RFile(self.path)
1021
+ rfile = File(self.path)
1023
1022
 
1024
1023
  ## Convert.
1025
1024
  if type(value) != str:
reykit/rmonkey.py CHANGED
@@ -45,10 +45,9 @@ def monkey_patch_sqlalchemy_result_more_fetch():
45
45
  >>> result.empty
46
46
  """
47
47
 
48
-
48
+ # Import.
49
49
  from sqlalchemy.engine.cursor import CursorResult
50
50
  from pandas import DataFrame, NA, concat
51
-
52
51
  from .rstdout import echo
53
52
  from .rtable import (
54
53
  to_table,
@@ -63,7 +62,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
63
62
  to_excel
64
63
  )
65
64
  from .rtime import time_to
66
-
65
+ from .rtype import Base
67
66
 
68
67
  # Fetch result as table in 'list[dict]' format.
69
68
  CursorResult.fetch_table = to_table
@@ -97,7 +96,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
97
96
 
98
97
 
99
98
  # Print result.
100
- def method_show(self: RResult, limit: int | None = None) -> None:
99
+ def method_show(self: Result, limit: int | None = None) -> None:
101
100
  """
102
101
  Print result.
103
102
 
@@ -151,7 +150,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
151
150
 
152
151
  # Whether is exist.
153
152
  @property
154
- def method_exist(self: RResult) -> bool:
153
+ def method_exist(self: Result) -> bool:
155
154
  """
156
155
  Judge whether is exist row.
157
156
 
@@ -171,7 +170,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
171
170
 
172
171
  # Whether is empty.
173
172
  @property
174
- def method_empty(self: RResult) -> bool:
173
+ def method_empty(self: Result) -> bool:
175
174
  """
176
175
  Judge whether is empty row.
177
176
 
@@ -190,7 +189,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
190
189
 
191
190
 
192
191
  # Update annotations.
193
- class RResult(CursorResult):
192
+ class Result(Base, CursorResult):
194
193
  """
195
194
  Update based on `CursorResult` object, for annotation return value.
196
195
  """
@@ -214,7 +213,7 @@ def monkey_patch_sqlalchemy_result_more_fetch():
214
213
  empty = method_empty
215
214
 
216
215
 
217
- return RResult
216
+ return Result
218
217
 
219
218
 
220
219
  def monkey_patch_sqlalchemy_row_index_field():
@@ -228,11 +227,10 @@ def monkey_patch_sqlalchemy_row_index_field():
228
227
  ... row['field']
229
228
  """
230
229
 
231
-
230
+ # Import.
232
231
  from typing import Any, overload
233
232
  from sqlalchemy.engine.row import Row
234
233
 
235
-
236
234
  # Define.
237
235
  @overload
238
236
  def __getitem__(self, index: str | int) -> Any: ...
@@ -271,17 +269,15 @@ def monkey_patch_pprint_modify_width_judgment() -> None:
271
269
  Monkey patch of package `pprint`, modify the chinese width judgment.
272
270
  """
273
271
 
274
-
272
+ # Import.
275
273
  from pprint import PrettyPrinter, _recursion
276
274
 
277
275
 
278
- # New method.
276
+ # Define.
279
277
  def _format(_self, obj, stream, indent, allowance, context, level):
280
278
 
281
-
282
279
  from .rtext import get_width
283
280
 
284
-
285
281
  objid = id(obj)
286
282
  if objid in context:
287
283
  stream.write(_recursion(obj))
@@ -325,9 +321,9 @@ def monkey_path_pil_image_get_bytes():
325
321
  >>> image.get_bytes()
326
322
  """
327
323
 
328
-
329
324
  from PIL.Image import Image
330
325
  from io import BytesIO
326
+ from reykit.rtype import Base
331
327
 
332
328
 
333
329
  # Define.
@@ -353,7 +349,7 @@ def monkey_path_pil_image_get_bytes():
353
349
 
354
350
 
355
351
  # Update annotations.
356
- class RImage(Image):
352
+ class Image(Base, Image):
357
353
  """
358
354
  Update based on `Image` object, for annotation return value.
359
355
  """
@@ -365,4 +361,4 @@ def monkey_path_pil_image_get_bytes():
365
361
  get_bytes = method_get_bytes
366
362
 
367
363
 
368
- return RImage
364
+ return Image