Metadata-Version: 2.4
Name: darren_utils
Version: 0.2.1.304
Summary: 一个功能丰富的工具包
Author-email: Darren <2775856@qq.com>
License: MIT
Project-URL: Homepage, https://github.com/Darren5211314
Project-URL: Repository, https://github.com/Darren5211314
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: cryptography
Requires-Dist: gmssl
Requires-Dist: httpx[http2]
Requires-Dist: redis
Requires-Dist: pyperclip
Requires-Dist: send2trash
Requires-Dist: loguru
Requires-Dist: socksio
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: send2trash; extra == "dev"
Requires-Dist: pyperclip; extra == "dev"
Requires-Dist: pillow; extra == "dev"
Requires-Dist: psutil; extra == "dev"
Requires-Dist: pyarmor>=9.0; extra == "dev"

# pip_darren

[![Python](https://img.shields.io/badge/python-%3E%3D3.9-blue)](https://www.python.org/)
[![HTTP](https://img.shields.io/badge/http-httpx-success)](https://www.python-httpx.org/)
[![Crypto](https://img.shields.io/badge/crypto-AES%20%7C%20RSA%20%7C%20SMx-informational)](#主要模块)

一个面向爬虫与自动化场景的 Python 工具库，提供：

- 常见加密能力（AES / DES / 3DES / RC4 / RSA / SM2 / SM3 / SM4）
- 哈希与签名（HASH / HMAC）
- HTTP 请求封装（`httpx`，支持 Session 与非 Session）
- 代理池工具（自动拉取、验证、获取代理）
- 字符串与时间工具
- 设备信息采集（OS/CPU/GPU/BIOS/主板/磁盘/MAC/UUID）

## 目录

- [安装](#安装)
- [快速开始](#快速开始)
- [主要模块](#主要模块)
- [测试](#测试)
- [版本更新](#版本更新)
- [FAQ](#faq)
- [注意事项](#注意事项)

---

## 安装

### 方式 A：requirements

```bash
pip install -r requirements.txt
```

### 方式 B：本地开发安装

```bash
pip install -e .
```

---

## 快速开始

```python
import darren
```

### AES 示例

```python
cipher = darren.aes.encry("cbc", "hello", "1234567890abcdef", "abcdef1234567890", "pkcs7")
plain = darren.aes.decry("cbc", cipher, "1234567890abcdef", "abcdef1234567890", "pkcs7")
print(cipher, plain)
```

### HASH / HMAC

```python
print(darren.hash.sha256("hello"))
sign = darren.hmac.sha256("hello", "my-key")
print(darren.hmac.verify("sha256", "hello", "my-key", sign, "hex"))
```

### HTTP（httpx-only）

#### 非 Session（一次性请求）

```python
r = darren.http.get("https://example.com", timeout=10, max_retries=1)
print(None if r is None else r.status_code)
if r:
    print(r.text_trunc(120))
    print(r.ok_json(default={}))
```

#### Session（Client）模式

```python
session = darren.http.Session(enable_detailed_logging=True, http2=False)
try:
    r = session.get("https://example.com", cookies="a=1; b=2", task_id="demo")
    print(None if r is None else r.status_code)
finally:
    session.close()
```

#### 下载文件

```python
ok = darren.http.download(
    url="https://example.com",
    save_path="http_logs/example_download.html",
    timeout=10,
    max_retries=0,
    task_id="download_demo",
)
print(ok)
```

### 代理工具

```python
# 手动塞入一个代理（测试用）
darren.proxy.add_proxy("127.0.0.1:8080")

# 获取 requests/httpx 可直接使用的代理字典
proxy_dict = darren.proxy.get_one_proxy(timeout=0)
print(proxy_dict)
```

### 设备信息

```python
info = darren.device.get_device_info()
print(info["os"])
print(info["cpu"])
print(info["bios"])
print(info["uuid"])
```

---

## 主要模块

- `darren.aes`：AES 加解密（支持模式/填充/多输出格式）
- `darren.des` / `darren.triple_des`：DES / 3DES
- `darren.rc4`：RC4
- `darren.rsa`：RSA 密钥生成、加解密、签名验签
- `darren.sm2` / `darren.sm3` / `darren.sm4`：国密算法
- `darren.hash` / `darren.hmac`：摘要与 HMAC
- `darren.http`：httpx 封装（Session/非 Session、下载、安全 JSON、文本截断）
- `darren.proxy`：代理管理（添加、获取、动态切换配置）
- `darren.string`：字符串工具
- `darren.time`：时间工具
- `darren.device`：设备信息采集

---

## 测试

项目内置了一个非 pytest 的冒烟脚本：

```bash
python Test.py
```

会打印各模块调用结果与基础断言状态。

---

## 版本更新

### v0.1.x（当前）

- 统一加密模块能力（AES / DES / 3DES / RC4 / RSA / SMx）
- HTTP 封装迁移到 `httpx`（移除 requests 运行时依赖）
- 代理模块内部请求改为 `httpx`
- 新增 `DeviceUtils`（含 BIOS / 主板 / UUID / 硬盘等原始字段）
- 完善 `Test.py`，支持一键冒烟验证

---

## FAQ

### 1）为什么有些设备字段为空？

不同系统、权限和硬件厂商对序列号暴露程度不同，字段为空是正常现象。建议你组合多个字段做机器指纹。

### 2）`HTTPX download ok = False` 是 bug 吗？

不一定。通常是目标 URL 不支持下载、被重定向策略限制、网络环境受限等导致。返回 `False` 代表下载失败但流程安全退出。

### 3）代理必须用 Redis 吗？

不是。默认是内存模式。需要 Redis 时可在 `ProxyConfig` 中显式启用。

---

## 注意事项

- 部分设备字段（如磁盘序列号、BIOS 序列号）在不同系统/权限下可能为空，这是正常现象。
- 国密相关需要 `gmssl`。
- 如需 `socks5://` 代理，请确保环境包含 `socksio`（httpx 对应依赖）。

