- 新增 python-client 模块,提供 ConfigClient 配置拉取、定时同步、变更监听 - 使用 pyaes 替代 cryptography 实现 AES 解密,避免编译问题 - 新增 python-client-demo Flask 示例应用 - .gitignore 添加 Python 相关忽略规则
23 lines
634 B
Python
23 lines
634 B
Python
import json
|
|
import os
|
|
|
|
CACHE_FILE = "config-cache.json"
|
|
|
|
|
|
class Cache:
|
|
def __init__(self, cache_dir: str = "."):
|
|
self.cache_dir = cache_dir
|
|
|
|
def write(self, data: dict) -> None:
|
|
path = os.path.join(self.cache_dir, CACHE_FILE)
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
json.dump(data, f, ensure_ascii=False)
|
|
|
|
def read(self) -> dict | None:
|
|
path = os.path.join(self.cache_dir, CACHE_FILE)
|
|
try:
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
except (FileNotFoundError, json.JSONDecodeError):
|
|
return None
|