ezKit 3.0.63__tar.gz → 3.0.65__tar.gz
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-3.0.63/ezKit.egg-info → ezkit-3.0.65}/PKG-INFO +1 -1
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit/utils.py +42 -6
- {ezkit-3.0.63 → ezkit-3.0.65/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-3.0.63 → ezkit-3.0.65}/setup.py +1 -1
- {ezkit-3.0.63 → ezkit-3.0.65}/LICENSE +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/MANIFEST.in +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/README.md +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit/__init__.py +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit/bandwagon.py +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit/cipher.py +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit/database.py +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit/fastapix.py +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit/http.py +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit/markdown_to_html.template +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit/markdownx.py +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit/sendemail.py +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit/stock.py +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit.egg-info/SOURCES.txt +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/pyproject.toml +0 -0
- {ezkit-3.0.63 → ezkit-3.0.65}/setup.cfg +0 -0
|
@@ -10,6 +10,7 @@ from decimal import Decimal
|
|
|
10
10
|
from functools import wraps
|
|
11
11
|
from ipaddress import IPv4Address, IPv6Address
|
|
12
12
|
from itertools import islice
|
|
13
|
+
from operator import itemgetter
|
|
13
14
|
from os import environ
|
|
14
15
|
from pathlib import Path
|
|
15
16
|
from secrets import choice
|
|
@@ -174,6 +175,10 @@ def check_path_type(path_object: str | Path, path_type: str) -> bool:
|
|
|
174
175
|
|
|
175
176
|
_path_object: Path = Path(path_object) if not isinstance(path_object, Path) else path_object
|
|
176
177
|
|
|
178
|
+
# is_symlink 不跟随目标, 断开的符号链接也应被识别
|
|
179
|
+
# if path_type == "symlink":
|
|
180
|
+
# return _path_object.is_symlink()
|
|
181
|
+
|
|
177
182
|
# 文件不存在的情况
|
|
178
183
|
if not _path_object.exists():
|
|
179
184
|
return False
|
|
@@ -400,6 +405,10 @@ def list_split(data: list, number: int, equally: bool = False) -> list | None:
|
|
|
400
405
|
|
|
401
406
|
try:
|
|
402
407
|
|
|
408
|
+
# 检查 number 是否为正整数
|
|
409
|
+
if not isinstance(number, int) or isinstance(number, bool) or number < 1:
|
|
410
|
+
raise ValueError("number must be a positive integer")
|
|
411
|
+
|
|
403
412
|
# 要将列表平均分成 n 个子列表
|
|
404
413
|
if equally:
|
|
405
414
|
it = iter(data)
|
|
@@ -425,6 +434,9 @@ def list_print_by_step(data: list, step: int, separator: str = " ") -> bool:
|
|
|
425
434
|
|
|
426
435
|
try:
|
|
427
436
|
|
|
437
|
+
if not isinstance(step, int) or isinstance(step, bool) or step < 1:
|
|
438
|
+
raise ValueError("step must be a positive integer")
|
|
439
|
+
|
|
428
440
|
# 打印
|
|
429
441
|
for i, v in enumerate(data):
|
|
430
442
|
|
|
@@ -529,7 +541,7 @@ def parallelism(
|
|
|
529
541
|
workers: int = 2,
|
|
530
542
|
thread: bool = False,
|
|
531
543
|
**kwargs,
|
|
532
|
-
) ->
|
|
544
|
+
) -> list | bool:
|
|
533
545
|
"""multi-processing or multi-threading"""
|
|
534
546
|
|
|
535
547
|
# :param func: 处理函数
|
|
@@ -557,6 +569,14 @@ def parallelism(
|
|
|
557
569
|
|
|
558
570
|
try:
|
|
559
571
|
|
|
572
|
+
# 确保数据不为空
|
|
573
|
+
if not data:
|
|
574
|
+
raise ValueError("data is empty")
|
|
575
|
+
|
|
576
|
+
# 检查 workers 是否为正整数
|
|
577
|
+
if not isinstance(workers, int) or isinstance(workers, bool) or workers < 1:
|
|
578
|
+
raise ValueError("workers must be a positive integer")
|
|
579
|
+
|
|
560
580
|
# 确保并行数不超过数据量
|
|
561
581
|
workers = min(len(data), workers)
|
|
562
582
|
data_chunks = list_split(data, workers, equally=True) if workers > 1 else [data]
|
|
@@ -565,10 +585,10 @@ def parallelism(
|
|
|
565
585
|
logger.info(f"{info} | data chunks error")
|
|
566
586
|
return False
|
|
567
587
|
|
|
568
|
-
#
|
|
588
|
+
# 在上下文管理器内获取结果, 确保任务异常由此处捕获
|
|
569
589
|
pool = ThreadPoolExecutor if thread else ProcessPoolExecutor
|
|
570
590
|
with pool(workers, **kwargs) as executor:
|
|
571
|
-
return executor.map(func, data_chunks)
|
|
591
|
+
return list(executor.map(func, data_chunks))
|
|
572
592
|
|
|
573
593
|
except Exception as e:
|
|
574
594
|
|
|
@@ -624,11 +644,15 @@ def shell(
|
|
|
624
644
|
|
|
625
645
|
try:
|
|
626
646
|
|
|
627
|
-
|
|
647
|
+
options = dict(kwargs)
|
|
628
648
|
|
|
629
|
-
|
|
649
|
+
if not serialize:
|
|
650
|
+
return subprocess.run(args, check=options.pop("check", False), **options)
|
|
630
651
|
|
|
631
|
-
|
|
652
|
+
# 序列化模式强制使用文本输出, 同时避免重复关键字参数
|
|
653
|
+
options.pop("check", None)
|
|
654
|
+
options.update(capture_output=True, text=True)
|
|
655
|
+
result = subprocess.run(args, check=False, **options)
|
|
632
656
|
|
|
633
657
|
return {
|
|
634
658
|
"returncode": result.returncode,
|
|
@@ -702,3 +726,15 @@ def split_dict(data: dict, keys: list) -> tuple[dict[Any, Any], dict[Any, Any]]
|
|
|
702
726
|
logger.error(e)
|
|
703
727
|
|
|
704
728
|
return None
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
def sort_dicts(dicts: list[dict], key: str, *, reverse: bool = False) -> list[dict] | None:
|
|
732
|
+
"""字典列表排序"""
|
|
733
|
+
try:
|
|
734
|
+
return sorted(dicts, key=itemgetter(key), reverse=reverse)
|
|
735
|
+
except Exception as e:
|
|
736
|
+
if DEBUG:
|
|
737
|
+
logger.exception(e)
|
|
738
|
+
else:
|
|
739
|
+
logger.error(e)
|
|
740
|
+
return None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|