ezKit 1.0.0b2__py3-none-any.whl → 1.0.0b4__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.
- ezKit/http.py +42 -17
- ezKit/utils.py +13 -0
- {ezKit-1.0.0b2.dist-info → ezKit-1.0.0b4.dist-info}/METADATA +1 -1
- {ezKit-1.0.0b2.dist-info → ezKit-1.0.0b4.dist-info}/RECORD +7 -7
- {ezKit-1.0.0b2.dist-info → ezKit-1.0.0b4.dist-info}/LICENSE +0 -0
- {ezKit-1.0.0b2.dist-info → ezKit-1.0.0b4.dist-info}/WHEEL +0 -0
- {ezKit-1.0.0b2.dist-info → ezKit-1.0.0b4.dist-info}/top_level.txt +0 -0
ezKit/http.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import json
|
2
|
+
from typing import Callable
|
2
3
|
|
3
4
|
import requests
|
4
5
|
from loguru import logger
|
@@ -6,25 +7,36 @@ from loguru import logger
|
|
6
7
|
from . import bottle, utils
|
7
8
|
|
8
9
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
def bottle_cors(fn: Callable):
|
11
|
+
"""
|
12
|
+
Bottle CORS
|
13
|
+
"""
|
14
|
+
"""
|
15
|
+
参考文档:
|
16
|
+
- https://stackoverflow.com/a/17262900
|
17
|
+
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
|
18
|
+
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
|
19
|
+
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
|
20
|
+
"""
|
21
|
+
def cors(*args, **kwargs):
|
20
22
|
bottle.response.headers['Access-Control-Allow-Headers'] = '*'
|
21
23
|
bottle.response.headers['Access-Control-Allow-Methods'] = '*'
|
22
24
|
bottle.response.headers['Access-Control-Allow-Origin'] = '*'
|
23
25
|
if bottle.request.method != 'OPTIONS':
|
24
26
|
return fn(*args, **kwargs)
|
25
|
-
return
|
27
|
+
return cors
|
28
|
+
|
26
29
|
|
27
|
-
def download(
|
30
|
+
def download(
|
31
|
+
request: dict,
|
32
|
+
file: dict,
|
33
|
+
chunks: bool = False,
|
34
|
+
iter_content: dict | None = None,
|
35
|
+
echo: bool = False,
|
36
|
+
info: str = None,
|
37
|
+
debug: bool = False
|
38
|
+
) -> bool:
|
39
|
+
"下载文件"
|
28
40
|
|
29
41
|
if utils.v_true(request, dict):
|
30
42
|
request_arguments = {'method': 'GET', 'stream': True, **request}
|
@@ -45,7 +57,7 @@ def download(request: dict, file: dict, chunks: bool = None, iter_content: dict
|
|
45
57
|
|
46
58
|
try:
|
47
59
|
|
48
|
-
logger.info(f'{info} ......') if echo
|
60
|
+
logger.info(f'{info} ......') if utils.v_true(echo, bool) else next
|
49
61
|
|
50
62
|
response = requests.request(**request_arguments)
|
51
63
|
|
@@ -57,11 +69,24 @@ def download(request: dict, file: dict, chunks: bool = None, iter_content: dict
|
|
57
69
|
else:
|
58
70
|
_file.write(response.content)
|
59
71
|
|
60
|
-
logger.success(f'{info} [成功]') if echo
|
72
|
+
logger.success(f'{info} [成功]') if utils.v_true(echo, bool) else next
|
61
73
|
|
62
74
|
return True
|
63
75
|
|
64
76
|
except Exception as e:
|
65
|
-
logger.exception(e)
|
66
|
-
logger.error(f'{info} [失败]') if echo
|
77
|
+
logger.exception(e) if debug is True else next
|
78
|
+
logger.error(f'{info} [失败]') if utils.v_true(echo, bool) else next
|
67
79
|
return False
|
80
|
+
|
81
|
+
|
82
|
+
def response_json(
|
83
|
+
data: any = None,
|
84
|
+
debug: bool = False,
|
85
|
+
**kwargs
|
86
|
+
) -> str:
|
87
|
+
"""解决字符编码问题: ensure_ascii=False"""
|
88
|
+
try:
|
89
|
+
return json.dumps(data, default=str, ensure_ascii=False, sort_keys=True, **kwargs)
|
90
|
+
except Exception as e:
|
91
|
+
logger.exception(e) if debug is True else next
|
92
|
+
return None
|
ezKit/utils.py
CHANGED
@@ -991,6 +991,19 @@ def json_sort(
|
|
991
991
|
logger.exception(e) if debug is True else next
|
992
992
|
return None
|
993
993
|
|
994
|
+
def json_to_file(
|
995
|
+
data: str = None,
|
996
|
+
file: str = None,
|
997
|
+
debug: bool = False,
|
998
|
+
**kwargs
|
999
|
+
) -> dict | None:
|
1000
|
+
try:
|
1001
|
+
json.dumps(data, file, indent=4, sort_keys=True, **kwargs)
|
1002
|
+
return True
|
1003
|
+
except Exception as e:
|
1004
|
+
logger.exception(e) if debug is True else next
|
1005
|
+
return False
|
1006
|
+
|
994
1007
|
|
995
1008
|
# --------------------------------------------------------------------------------------------------
|
996
1009
|
|
@@ -3,18 +3,18 @@ ezKit/bottle.py,sha256=iJVdWAfpOi2ksPZlyZtALczPj9aqqcNXrSXSClUCJwc,151993
|
|
3
3
|
ezKit/cipher.py,sha256=fDyc-ST8s9a9o07MUj_TeoXNHZhOOnL53LKHU3e49as,2820
|
4
4
|
ezKit/database.py,sha256=imOeBSU6kCIrVHei485HEROnmsr5UZtCcqwHk0vDzwY,6741
|
5
5
|
ezKit/files.py,sha256=GoNdai3Ul0lg4wTkJAQm5kys1Sv3NCTNLIZlzHQKuZQ,12714
|
6
|
-
ezKit/http.py,sha256=
|
6
|
+
ezKit/http.py,sha256=LFtZURWk1h5Mw3nkswP1tch0Fbop16A9dRFZpd9gTfc,2643
|
7
7
|
ezKit/mongo.py,sha256=c4i-kIasYrLL_aRMovhzsaLhkKWNietNSJ0l8uo2v0k,1844
|
8
8
|
ezKit/plots.py,sha256=QUtoVfZ49ZSNcY8gcQ2TYVkMjDDzoW-myMtqTi5WN2U,5322
|
9
9
|
ezKit/redis.py,sha256=pY4SPlcgQ7S8IeY2xoDpxy-xCZxzZQrQJNAoWRsC1dI,1773
|
10
10
|
ezKit/reports.py,sha256=dBBggggCCLuk5YD6SjdUPuxTr3wiJojP3lA7dQfg6Pk,8898
|
11
11
|
ezKit/sendemail.py,sha256=PItznLBcZ6Om8NU7rep69m3QNZ9YkmOovup7pPGyY58,4840
|
12
|
-
ezKit/utils.py,sha256=
|
12
|
+
ezKit/utils.py,sha256=r9rWu1DMvlIjqFeWSjnVTVnn1AYi4K7bFvWt48WJ8eg,38083
|
13
13
|
ezKit/weixin.py,sha256=Sxm_yNEvcztFNCZyjZetVwqxoGoL2PJHlQABIWkd1pk,5075
|
14
14
|
ezKit/xftp.py,sha256=qbCqFcGe22TDBSisj0Zoz78tnydDWoOfvywWpXdfaGw,6982
|
15
15
|
ezKit/zabbix.py,sha256=EF0-tQ1FTMBqawXKf3JEoPYoAJmYENXXIm9T5ICSdHM,32345
|
16
|
-
ezKit-1.0.
|
17
|
-
ezKit-1.0.
|
18
|
-
ezKit-1.0.
|
19
|
-
ezKit-1.0.
|
20
|
-
ezKit-1.0.
|
16
|
+
ezKit-1.0.0b4.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
17
|
+
ezKit-1.0.0b4.dist-info/METADATA,sha256=Bu5k5kfIpAjKl9MJq7eJsN0HWQ_FXIloILQYvE5PiQA,196
|
18
|
+
ezKit-1.0.0b4.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
19
|
+
ezKit-1.0.0b4.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
|
20
|
+
ezKit-1.0.0b4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|