ArgonCodeKits 0.3.0__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.
@@ -0,0 +1,3 @@
1
+ from .hash import * # noqa: F403
2
+ from .os import * # noqa: F403
3
+ from .pyplus import * # noqa: F403
@@ -0,0 +1,46 @@
1
+ import hashlib
2
+
3
+ def md5(s: str) -> str:
4
+ """计算字符串的 MD5 哈希值
5
+
6
+ Args:
7
+ s (str): 输入字符串
8
+
9
+ Returns:
10
+ str: 字符串的 MD5 哈希值(32 位十六进制字符串)
11
+ """
12
+
13
+ return hashlib.md5(s.encode()).hexdigest()
14
+
15
+ def sha1(s: str) -> str:
16
+ """计算字符串的 SHA-1 哈希值
17
+
18
+ Args:
19
+ s (str): 输入字符串
20
+
21
+ Returns:
22
+ str: 字符串的 SHA-1 哈希值(40 位十六进制字符串)
23
+ """
24
+ return hashlib.sha1(s.encode()).hexdigest()
25
+
26
+ def sha256(s: str) -> str:
27
+ """计算字符串的 SHA-256 哈希值
28
+
29
+ Args:
30
+ s (str): 输入字符串
31
+
32
+ Returns:
33
+ str: 字符串的 SHA-256 哈希值(64 位十六进制字符串)
34
+ """
35
+ return hashlib.sha256(s.encode()).hexdigest()
36
+
37
+ def sha512(s: str) -> str:
38
+ """计算字符串的 SHA-512 哈希值
39
+
40
+ Args:
41
+ s (str): 输入字符串
42
+
43
+ Returns:
44
+ str: 字符串的 SHA-512 哈希值(128 位十六进制字符串)
45
+ """
46
+ return hashlib.sha512(s.encode()).hexdigest()
@@ -0,0 +1,45 @@
1
+ import os
2
+
3
+
4
+ def get_folder_size(folder: str) -> int:
5
+ """获取文件夹大小
6
+
7
+ Args:
8
+ folder (str): 要计算大小的文件夹路径
9
+
10
+ Returns:
11
+ int: 文件夹的总大小(字节)
12
+ """
13
+ total = 0
14
+ for entry in os.scandir(folder):
15
+ if entry.is_file():
16
+ total += entry.stat().st_size
17
+ elif entry.is_dir():
18
+ total += get_folder_size(entry.path) # 递归子文件夹(如果需要)
19
+ return total
20
+
21
+
22
+ def filter_windows_invalid_chars(s: str, o: str = "[x]") -> str:
23
+ r"""将字符串中的 Windows 非法字符(\ / : * ? " < > |)全部替换为 指定内容
24
+
25
+ Args:
26
+ s (str): 输入字符串
27
+ o (str, optional): 替换内容,默认为 "[x]"
28
+ Returns:
29
+ str: 替换后的字符串
30
+ """
31
+ invalid_chars = set(r'\/:*?"<>|')
32
+ return "".join(o if c in invalid_chars else c for c in s)
33
+
34
+ def check_working_directory() -> str:
35
+ """切换目录到脚本位置
36
+
37
+ Returns:
38
+ str: 脚本所在目录的路径
39
+ """
40
+ script_dir = os.path.normcase(os.getcwd())
41
+ current_dir = os.path.normcase(os.path.dirname(os.path.abspath(__file__)))
42
+
43
+ if script_dir != current_dir:
44
+ os.chdir(current_dir)
45
+ return current_dir
@@ -0,0 +1,87 @@
1
+ import logging
2
+ import random
3
+ import base64
4
+
5
+ space = " " * 100
6
+
7
+ def input(prompt: str, level: str = "info") -> str:
8
+ """显示提示信息并记录日志,然后获取用户输入并记录。
9
+
10
+ Args:
11
+ prompt (str): 提示信息
12
+ level (str): 日志等级,可选值:debug, info, warning, error, critical
13
+
14
+ Returns:
15
+ str: 用户输入的文本
16
+ """
17
+ level_map = {
18
+ "debug": logging.DEBUG,
19
+ "info": logging.INFO,
20
+ "warning": logging.WARNING,
21
+ "error": logging.ERROR,
22
+ "critical": logging.CRITICAL,
23
+ }
24
+
25
+ log_level = level_map.get(level.lower(), logging.INFO)
26
+
27
+ # 记录提示信息(纯文本,不含控制字符)
28
+ logging.log(log_level, f"提示信息:{prompt}")
29
+
30
+ # 获取用户输入
31
+ user_input = __builtins__.input(prompt)
32
+
33
+ # 记录用户输入
34
+ logging.log(log_level, f"用户输入:{user_input}")
35
+
36
+ return user_input
37
+
38
+
39
+ def encrypt(text: str, password: str, rounds: int = 10) -> bytes:
40
+ """混淆:文本 -> 多次base64 + 打乱
41
+
42
+ Args:
43
+ text (str): 需要加密的文本
44
+ password (str): 用于生成随机种子的密码
45
+ rounds (int): 加密轮数
46
+
47
+ Returns:
48
+ str: 加密后的数据
49
+ """
50
+ data = text.encode('utf-8')
51
+ for i in range(rounds):
52
+ # 每轮使用独立的随机生成器,种子 = 密码 + 轮次
53
+ r = random.Random(password + str(i))
54
+ # base64编码
55
+ data = base64.b64encode(data)
56
+ # 转列表打乱
57
+ chars = list(data)
58
+ r.shuffle(chars)
59
+ data = bytes(chars)
60
+ return data
61
+
62
+
63
+ def decrypt(ciphertext: bytes, password: str, rounds: int = 10) -> str:
64
+ """反混淆:恢复打乱顺序 + base64解码
65
+ Args:
66
+ ciphertext (bytes): 加密后的数据
67
+ password (str): 用于生成随机种子的密码
68
+ rounds (int): 加密轮数
69
+
70
+ Returns:
71
+ str: 解密后的文本
72
+ """
73
+ data = ciphertext
74
+ for i in range(rounds - 1, -1, -1): # 从最后一轮逆向操作
75
+ # 使用与加密时相同的独立随机生成器
76
+ r = random.Random(password + str(i))
77
+ # 获取这轮的乱序索引(和加密时完全一样)
78
+ indices = list(range(len(data)))
79
+ r.shuffle(indices)
80
+ # 恢复原始顺序
81
+ chars = [None] * len(data)
82
+ for new_pos, old_pos in enumerate(indices):
83
+ chars[old_pos] = data[new_pos]
84
+ data = bytes(chars)
85
+ # base64解码
86
+ data = base64.b64decode(data)
87
+ return data.decode('utf-8')
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: ArgonCodeKits
3
+ Version: 0.3.0
4
+ Summary: Argon的代码库,包含一些实用的工具函数,旨在提高开发效率和代码精简度。
5
+ Author-email: Argon <smmomm@126.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/mifongjvav/ArgonCodeKits
8
+ Project-URL: Repository, https://github.com/mifongjvav/ArgonCodeKits
9
+ Project-URL: BugTracker, https://github.com/mifongjvav/ArgonCodeKits/issues
10
+ Keywords: utils,hash,md5,sha256,filesystem,encryption
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.6
15
+ Classifier: Programming Language :: Python :: 3.7
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Operating System :: OS Independent
24
+ Classifier: Topic :: Utilities
25
+ Classifier: Topic :: Security :: Cryptography
26
+ Requires-Python: >=3.6
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Dynamic: license-file
30
+
31
+ # Argon Code Kits
32
+
33
+ Argon的代码库,包含一些实用的工具函数,旨在提高开发效率和代码精简度。
34
+
35
+ ## 功能模块
36
+
37
+ ### hash - 哈希计算
38
+
39
+ - `md5(s)` - 计算字符串的 MD5 哈希值
40
+ - `sha1(s)` - 计算字符串的 SHA-1 哈希值
41
+ - `sha256(s)` - 计算字符串的 SHA-256 哈希值
42
+ - `sha512(s)` - 计算字符串的 SHA-512 哈希值
43
+
44
+ ### os - 操作系统工具
45
+
46
+ - `get_folder_size(folder)` - 获取文件夹大小
47
+ - `filter_windows_invalid_chars(s, o="[x]")` - 过滤 Windows 文件名非法字符
48
+ - `check_working_directory()` - 切换目录到脚本位置
49
+
50
+ ### pyplus - Python 增强功能
51
+
52
+ - `input(prompt, level="info")` - 带日志记录的输入函数
53
+ - `encrypt(text, password, rounds=10)` - 文本加密(基于 base64 和混淆)
54
+ - `decrypt(ciphertext, password, rounds=10)` - 解密
55
+
56
+ ## 安装
57
+
58
+ ```bash
59
+ pip install ArgonCodeKits
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ ArgonCodeKits/__init__.py
5
+ ArgonCodeKits/hash.py
6
+ ArgonCodeKits/os.py
7
+ ArgonCodeKits/pyplus.py
8
+ ArgonCodeKits.egg-info/PKG-INFO
9
+ ArgonCodeKits.egg-info/SOURCES.txt
10
+ ArgonCodeKits.egg-info/dependency_links.txt
11
+ ArgonCodeKits.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ ArgonCodeKits
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Argon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: ArgonCodeKits
3
+ Version: 0.3.0
4
+ Summary: Argon的代码库,包含一些实用的工具函数,旨在提高开发效率和代码精简度。
5
+ Author-email: Argon <smmomm@126.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/mifongjvav/ArgonCodeKits
8
+ Project-URL: Repository, https://github.com/mifongjvav/ArgonCodeKits
9
+ Project-URL: BugTracker, https://github.com/mifongjvav/ArgonCodeKits/issues
10
+ Keywords: utils,hash,md5,sha256,filesystem,encryption
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.6
15
+ Classifier: Programming Language :: Python :: 3.7
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Operating System :: OS Independent
24
+ Classifier: Topic :: Utilities
25
+ Classifier: Topic :: Security :: Cryptography
26
+ Requires-Python: >=3.6
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Dynamic: license-file
30
+
31
+ # Argon Code Kits
32
+
33
+ Argon的代码库,包含一些实用的工具函数,旨在提高开发效率和代码精简度。
34
+
35
+ ## 功能模块
36
+
37
+ ### hash - 哈希计算
38
+
39
+ - `md5(s)` - 计算字符串的 MD5 哈希值
40
+ - `sha1(s)` - 计算字符串的 SHA-1 哈希值
41
+ - `sha256(s)` - 计算字符串的 SHA-256 哈希值
42
+ - `sha512(s)` - 计算字符串的 SHA-512 哈希值
43
+
44
+ ### os - 操作系统工具
45
+
46
+ - `get_folder_size(folder)` - 获取文件夹大小
47
+ - `filter_windows_invalid_chars(s, o="[x]")` - 过滤 Windows 文件名非法字符
48
+ - `check_working_directory()` - 切换目录到脚本位置
49
+
50
+ ### pyplus - Python 增强功能
51
+
52
+ - `input(prompt, level="info")` - 带日志记录的输入函数
53
+ - `encrypt(text, password, rounds=10)` - 文本加密(基于 base64 和混淆)
54
+ - `decrypt(ciphertext, password, rounds=10)` - 解密
55
+
56
+ ## 安装
57
+
58
+ ```bash
59
+ pip install ArgonCodeKits
@@ -0,0 +1,29 @@
1
+ # Argon Code Kits
2
+
3
+ Argon的代码库,包含一些实用的工具函数,旨在提高开发效率和代码精简度。
4
+
5
+ ## 功能模块
6
+
7
+ ### hash - 哈希计算
8
+
9
+ - `md5(s)` - 计算字符串的 MD5 哈希值
10
+ - `sha1(s)` - 计算字符串的 SHA-1 哈希值
11
+ - `sha256(s)` - 计算字符串的 SHA-256 哈希值
12
+ - `sha512(s)` - 计算字符串的 SHA-512 哈希值
13
+
14
+ ### os - 操作系统工具
15
+
16
+ - `get_folder_size(folder)` - 获取文件夹大小
17
+ - `filter_windows_invalid_chars(s, o="[x]")` - 过滤 Windows 文件名非法字符
18
+ - `check_working_directory()` - 切换目录到脚本位置
19
+
20
+ ### pyplus - Python 增强功能
21
+
22
+ - `input(prompt, level="info")` - 带日志记录的输入函数
23
+ - `encrypt(text, password, rounds=10)` - 文本加密(基于 base64 和混淆)
24
+ - `decrypt(ciphertext, password, rounds=10)` - 解密
25
+
26
+ ## 安装
27
+
28
+ ```bash
29
+ pip install ArgonCodeKits
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ArgonCodeKits"
7
+ version = "0.3.0"
8
+ description = "Argon的代码库,包含一些实用的工具函数,旨在提高开发效率和代码精简度。"
9
+ readme = "README.md"
10
+ authors = [
11
+ {name = "Argon", email = "smmomm@126.com"}
12
+ ]
13
+ license = "MIT"
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.6",
19
+ "Programming Language :: Python :: 3.7",
20
+ "Programming Language :: Python :: 3.8",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Programming Language :: Python :: 3.14",
27
+ "Operating System :: OS Independent",
28
+ "Topic :: Utilities",
29
+ "Topic :: Security :: Cryptography",
30
+ ]
31
+ keywords = ["utils", "hash", "md5", "sha256", "filesystem", "encryption"]
32
+ requires-python = ">=3.6"
33
+ dependencies = []
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/mifongjvav/ArgonCodeKits"
37
+ Repository = "https://github.com/mifongjvav/ArgonCodeKits"
38
+ BugTracker = "https://github.com/mifongjvav/ArgonCodeKits/issues"
39
+
40
+ [tool.setuptools]
41
+ packages = ["ArgonCodeKits"] # 直接指定包名
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+