reykit 1.1.20__py3-none-any.whl → 1.1.21__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/rcomm.py +146 -2
- reykit/rdata.py +1 -1
- reykit/remail.py +1 -1
- reykit/rlog.py +6 -6
- reykit/rmultitask.py +2 -2
- reykit/ros.py +4 -4
- reykit/rrandom.py +1 -1
- reykit/rschedule.py +1 -1
- reykit/rtime.py +1 -1
- {reykit-1.1.20.dist-info → reykit-1.1.21.dist-info}/METADATA +2 -1
- {reykit-1.1.20.dist-info → reykit-1.1.21.dist-info}/RECORD +13 -13
- {reykit-1.1.20.dist-info → reykit-1.1.21.dist-info}/WHEEL +0 -0
- {reykit-1.1.20.dist-info → reykit-1.1.21.dist-info}/licenses/LICENSE +0 -0
reykit/rcomm.py
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
-
from typing import Any, Literal
|
12
|
+
from typing import Any, Literal, TypedDict, NotRequired
|
13
13
|
from collections.abc import Callable, Iterable
|
14
14
|
from warnings import filterwarnings
|
15
15
|
from os.path import abspath as os_abspath, isfile as os_isfile
|
@@ -17,12 +17,23 @@ from socket import socket as Socket
|
|
17
17
|
from urllib.parse import urlsplit as urllib_urlsplit, quote as urllib_quote, unquote as urllib_unquote
|
18
18
|
from requests.api import request as requests_request
|
19
19
|
from requests.models import Response
|
20
|
+
from requests_cache import (
|
21
|
+
ALL_METHODS,
|
22
|
+
OriginalResponse,
|
23
|
+
CachedResponse,
|
24
|
+
install_cache as requests_cache_install_cache,
|
25
|
+
uninstall_cache as requests_cache_uninstall_cache,
|
26
|
+
is_installed as requests_cache_is_installed,
|
27
|
+
clear as requests_cache_clear
|
28
|
+
)
|
20
29
|
from mimetypes import guess_type
|
21
30
|
from filetype import guess as filetype_guess
|
31
|
+
from datetime import datetime
|
22
32
|
|
23
33
|
from .rexception import throw, check_response_code
|
24
34
|
from .ros import RFile
|
25
35
|
from .rregex import search
|
36
|
+
from .rtype import RBase
|
26
37
|
|
27
38
|
|
28
39
|
__all__ = (
|
@@ -34,7 +45,21 @@ __all__ = (
|
|
34
45
|
'request',
|
35
46
|
'download',
|
36
47
|
'get_file_stream_time',
|
37
|
-
'listen_socket'
|
48
|
+
'listen_socket',
|
49
|
+
'RRequestCache'
|
50
|
+
)
|
51
|
+
|
52
|
+
|
53
|
+
RequestCacheParameters = TypedDict(
|
54
|
+
'RequestCacheParameters',
|
55
|
+
{
|
56
|
+
'cache_name': str,
|
57
|
+
'backend': Literal['sqllite', 'memory'],
|
58
|
+
'expire_after': NotRequired[float | datetime],
|
59
|
+
'code': Iterable[int],
|
60
|
+
'method': Iterable[str],
|
61
|
+
'judge': NotRequired[Callable[[Response], bool]]
|
62
|
+
}
|
38
63
|
)
|
39
64
|
|
40
65
|
|
@@ -429,3 +454,122 @@ def listen_socket(
|
|
429
454
|
socket_conn, _ = socket.accept()
|
430
455
|
data = socket_conn.recv(rece_size)
|
431
456
|
handler(data)
|
457
|
+
|
458
|
+
|
459
|
+
class RRequestCache(RBase):
|
460
|
+
"""
|
461
|
+
Rey's `requests cache` type.
|
462
|
+
"""
|
463
|
+
|
464
|
+
|
465
|
+
def __init__(
|
466
|
+
self,
|
467
|
+
path: str | None = 'cache.sqlite',
|
468
|
+
timeout: float | datetime | None = None,
|
469
|
+
codes: Iterable[int] | None = (200,),
|
470
|
+
methods: Iterable[str] | None = ('get', 'head'),
|
471
|
+
judge: Callable[[Response | OriginalResponse | CachedResponse], bool] | None = None
|
472
|
+
) -> None:
|
473
|
+
"""
|
474
|
+
Build `requests cache` instance attributes.
|
475
|
+
|
476
|
+
Parameters
|
477
|
+
----------
|
478
|
+
path : Cache file path.
|
479
|
+
- `None`: Use memory cache.
|
480
|
+
- `str`: Use SQLite cache.
|
481
|
+
timeout : Cache timeout.
|
482
|
+
- `None`: Not timeout.
|
483
|
+
- `float`: Timeout seconds.
|
484
|
+
- `datetime`: Timeout threshold time.
|
485
|
+
codes : Cache response code range.
|
486
|
+
- `None`: All.
|
487
|
+
methods : Cache request method range.
|
488
|
+
- `None`: All.
|
489
|
+
judge : Judge function, `True` cache, `False` not cache.
|
490
|
+
- `None`: Not judgment.
|
491
|
+
"""
|
492
|
+
|
493
|
+
# Build.
|
494
|
+
self.path = path
|
495
|
+
self.timeout = timeout
|
496
|
+
self.codes = codes
|
497
|
+
self.methods = methods
|
498
|
+
self.judge = judge
|
499
|
+
|
500
|
+
|
501
|
+
@property
|
502
|
+
def _start_params(self) -> RequestCacheParameters:
|
503
|
+
"""
|
504
|
+
Get cache start parameters.
|
505
|
+
|
506
|
+
Returns
|
507
|
+
-------
|
508
|
+
Cache start parameters.
|
509
|
+
"""
|
510
|
+
|
511
|
+
# Generate.
|
512
|
+
params = {}
|
513
|
+
if self.path is None:
|
514
|
+
params['cache_name'] = 'cache'
|
515
|
+
params['backend'] = 'memory'
|
516
|
+
else:
|
517
|
+
params['cache_name'] = self.path
|
518
|
+
params['backend'] = 'sqlite'
|
519
|
+
if self.timeout is not None:
|
520
|
+
params['expire_after'] = self.timeout
|
521
|
+
if self.codes is None:
|
522
|
+
params['allowable_codes'] = tuple(range(100, 600))
|
523
|
+
else:
|
524
|
+
params['allowable_codes'] = self.codes
|
525
|
+
if self.methods is None:
|
526
|
+
params['allowable_methods'] = ALL_METHODS
|
527
|
+
else:
|
528
|
+
params['allowable_methods'] = tuple([method.upper() for method in self.methods])
|
529
|
+
if self.judge is not None:
|
530
|
+
params['filter_fn'] = self.judge
|
531
|
+
|
532
|
+
return params
|
533
|
+
|
534
|
+
|
535
|
+
def start(self) -> None:
|
536
|
+
"""
|
537
|
+
Start cache.
|
538
|
+
"""
|
539
|
+
|
540
|
+
# Start.
|
541
|
+
requests_cache_install_cache(**self._start_params)
|
542
|
+
|
543
|
+
|
544
|
+
def stop(self) -> None:
|
545
|
+
"""
|
546
|
+
Stop cache.
|
547
|
+
"""
|
548
|
+
|
549
|
+
# Stop.
|
550
|
+
requests_cache_uninstall_cache()
|
551
|
+
|
552
|
+
|
553
|
+
@property
|
554
|
+
def started(self) -> bool:
|
555
|
+
"""
|
556
|
+
Whether started.
|
557
|
+
|
558
|
+
Returns
|
559
|
+
-------
|
560
|
+
Result.
|
561
|
+
"""
|
562
|
+
|
563
|
+
# Get.
|
564
|
+
result = requests_cache_is_installed()
|
565
|
+
|
566
|
+
return result
|
567
|
+
|
568
|
+
|
569
|
+
def clear(self) -> None:
|
570
|
+
"""
|
571
|
+
Clear cache.
|
572
|
+
"""
|
573
|
+
|
574
|
+
# Clear.
|
575
|
+
requests_cache_clear()
|
reykit/rdata.py
CHANGED
reykit/remail.py
CHANGED
reykit/rlog.py
CHANGED
@@ -91,7 +91,7 @@ class RLog(object):
|
|
91
91
|
name: str = 'Log'
|
92
92
|
) -> None:
|
93
93
|
"""
|
94
|
-
Build `log` attributes.
|
94
|
+
Build `log` instance attributes.
|
95
95
|
|
96
96
|
Parameters
|
97
97
|
----------
|
@@ -901,9 +901,9 @@ class RLog(object):
|
|
901
901
|
self.log(*messages, level=self.CRITICAL, **params)
|
902
902
|
|
903
903
|
|
904
|
-
def
|
904
|
+
def pause(self) -> None:
|
905
905
|
"""
|
906
|
-
|
906
|
+
Pause record.
|
907
907
|
"""
|
908
908
|
|
909
909
|
# Set level.
|
@@ -913,9 +913,9 @@ class RLog(object):
|
|
913
913
|
self.stoped = True
|
914
914
|
|
915
915
|
|
916
|
-
def
|
916
|
+
def resume(self) -> None:
|
917
917
|
"""
|
918
|
-
|
918
|
+
Resume record.
|
919
919
|
"""
|
920
920
|
|
921
921
|
# Set level.
|
@@ -951,7 +951,7 @@ class RRecord(object):
|
|
951
951
|
path: str | None = '_rrecord'
|
952
952
|
) -> None:
|
953
953
|
"""
|
954
|
-
Build `record` attributes.
|
954
|
+
Build `record` instance attributes.
|
955
955
|
|
956
956
|
Parameters
|
957
957
|
----------
|
reykit/rmultitask.py
CHANGED
@@ -69,7 +69,7 @@ class RThreadPool(RBase):
|
|
69
69
|
**kwargs: Any
|
70
70
|
) -> None:
|
71
71
|
"""
|
72
|
-
Build `thread pool` attributes.
|
72
|
+
Build `thread pool` instance attributes.
|
73
73
|
|
74
74
|
Parameters
|
75
75
|
----------
|
@@ -691,7 +691,7 @@ class RAsyncPool(RBase):
|
|
691
691
|
**kwargs: Any
|
692
692
|
) -> None:
|
693
693
|
"""
|
694
|
-
Build `asynchronous pool` attributes.
|
694
|
+
Build `asynchronous pool` instance attributes.
|
695
695
|
|
696
696
|
Parameters
|
697
697
|
----------
|
reykit/ros.py
CHANGED
@@ -311,7 +311,7 @@ class RFile(RBase):
|
|
311
311
|
path: str
|
312
312
|
) -> None:
|
313
313
|
"""
|
314
|
-
Build `file` attributes.
|
314
|
+
Build `file` instance attributes.
|
315
315
|
|
316
316
|
Parameters
|
317
317
|
----------
|
@@ -857,7 +857,7 @@ class RFolder(RBase):
|
|
857
857
|
path: str | None = None
|
858
858
|
) -> None:
|
859
859
|
"""
|
860
|
-
Build `folder` attributes.
|
860
|
+
Build `folder` instance attributes.
|
861
861
|
|
862
862
|
Parameters
|
863
863
|
----------
|
@@ -1233,7 +1233,7 @@ class RTempFile(RBase):
|
|
1233
1233
|
type_: Literal['str', 'bytes'] = 'bytes'
|
1234
1234
|
) -> None:
|
1235
1235
|
"""
|
1236
|
-
Build `temporary file` attributes.
|
1236
|
+
Build `temporary file` instance attributes.
|
1237
1237
|
|
1238
1238
|
Parameters
|
1239
1239
|
----------
|
@@ -1516,7 +1516,7 @@ class RTempFolder(RBase):
|
|
1516
1516
|
dir_: str | None = None
|
1517
1517
|
) -> None:
|
1518
1518
|
"""
|
1519
|
-
Build `temporary folder` attributes.
|
1519
|
+
Build `temporary folder` instance attributes.
|
1520
1520
|
|
1521
1521
|
Parameters
|
1522
1522
|
----------
|
reykit/rrandom.py
CHANGED
reykit/rschedule.py
CHANGED
reykit/rtime.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: reykit
|
3
|
-
Version: 1.1.
|
3
|
+
Version: 1.1.21
|
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>
|
@@ -28,6 +28,7 @@ Requires-Dist: python-docx
|
|
28
28
|
Requires-Dist: pyzbar
|
29
29
|
Requires-Dist: qrcode
|
30
30
|
Requires-Dist: requests
|
31
|
+
Requires-Dist: requests-cache
|
31
32
|
Requires-Dist: tqdm
|
32
33
|
Requires-Dist: urwid
|
33
34
|
Requires-Dist: varname
|
@@ -1,30 +1,30 @@
|
|
1
1
|
reykit/__init__.py,sha256=QwnhdUDSXgjXJQ4ClaeP9oKXUXyQOPj5sApwGCDrILc,848
|
2
2
|
reykit/rall.py,sha256=mOFwHXZ4-BOkJ5Ptbm6lQc2zwNf_VqcqM6AYYnYPfoo,672
|
3
|
-
reykit/rcomm.py,sha256=
|
4
|
-
reykit/rdata.py,sha256=
|
5
|
-
reykit/remail.py,sha256=
|
3
|
+
reykit/rcomm.py,sha256=nFe9YKVB8BeR9PWOdjZfRX6KTSN6rp90OmS_YoUXcwM,15138
|
4
|
+
reykit/rdata.py,sha256=Kn_YoH3Rv6yBUmnIRmyZzjwChRvUIgeyKF8hGRo2pas,10005
|
5
|
+
reykit/remail.py,sha256=K8ueN0oP9iBJuFHYbFwyTn4AKoQm2Sf1lvmLpQYXoBQ,6770
|
6
6
|
reykit/rexception.py,sha256=X56Ma9PtywVYAc38PmmMTlIxORYFy8Sz9e2bmm3j32M,8337
|
7
7
|
reykit/rimage.py,sha256=VXlQFCZBjx1Mu18Au0Qmth9-u8dlIz0h8u_X100ImxA,6287
|
8
|
-
reykit/rlog.py,sha256=
|
8
|
+
reykit/rlog.py,sha256=LijFdEqHX_HH1FAVLPJlR_SldAPeQ1_S8DmroWOiYyU,25793
|
9
9
|
reykit/rmonkey.py,sha256=OAlLVvMszMDzersroVC9NjbD2GPnoPgWF4AHZ3v3-fk,8232
|
10
|
-
reykit/rmultitask.py,sha256=
|
10
|
+
reykit/rmultitask.py,sha256=IMQGP_sDquptigjdEpzf2P-wfXSESsF2yjbEEo_2NN4,23156
|
11
11
|
reykit/rnumber.py,sha256=6x4FuRB-MTJheo6wbTUEaBarnew15jomlrneo3_Q2wg,3646
|
12
|
-
reykit/ros.py,sha256=
|
13
|
-
reykit/rrandom.py,sha256=
|
12
|
+
reykit/ros.py,sha256=udTroOHAQ0cNu7Ksepyj3iPCSj8lE42RMq02qqTzbbg,40740
|
13
|
+
reykit/rrandom.py,sha256=4lTBL3IMhcurFeMOXaML_W7Q4xU4_HOW-si-13IrV3A,9246
|
14
14
|
reykit/rregex.py,sha256=XTlnDLior8yyncFdrTr9FsVlBcqMXvsWRfpmvQS-BR8,6089
|
15
|
-
reykit/rschedule.py,sha256=
|
15
|
+
reykit/rschedule.py,sha256=XkQ6xNxcJQjomNvbfTTMyo0KIbk0y3Dp0xq_HOCScJQ,5834
|
16
16
|
reykit/rstdout.py,sha256=E6wyze9fGcR1wEatD5gIcsPF_qsJ1SG5VkKWKSns944,9927
|
17
17
|
reykit/rsystem.py,sha256=PpzB2oppZODh5YUUDV_8Ap3eJWa2cRU9tRBcSxlTiyw,35370
|
18
18
|
reykit/rtable.py,sha256=gXszf_9DE_5SMdNcxMX-xd4IpHGQVjGsN3NQIm7wVGY,12055
|
19
19
|
reykit/rtext.py,sha256=whaKpVkd36yYVtCmZ1ptp_TVRL1v3f7Jab0vPXC8wXY,11089
|
20
|
-
reykit/rtime.py,sha256=
|
20
|
+
reykit/rtime.py,sha256=1FC7JU-9t9dORUBUEzeVEvS73h7LDL9W8qTm9PZDscU,17110
|
21
21
|
reykit/rtype.py,sha256=O7iI_sJ1Bfl_ZiP29IHqEE3v3PfJRpeA5M6ukEdZSMk,2317
|
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.21.dist-info/METADATA,sha256=2BWrKZ6PCEYzHRYsJnBpZrjvJXVaTY_ieVJn--8CzF0,1919
|
28
|
+
reykit-1.1.21.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
29
|
+
reykit-1.1.21.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
30
|
+
reykit-1.1.21.dist-info/RECORD,,
|
File without changes
|
File without changes
|