Compare commits

..

8 Commits

Author SHA1 Message Date
ad17b905c4 修复ToolFile中SaveAsJson的一些问题 2025-11-23 20:03:44 +08:00
4ba5bfdfee 新增函数泛型注解 2025-11-06 20:37:30 +08:00
8121899d32 修复ToolFile中文件枚举函数的错误 2025-11-06 10:54:53 +08:00
a79ba69443 修复无依赖时Architecture注册的错误 2025-11-05 17:49:31 +08:00
3fa432a2bb 修复一个继承错误 2025-11-05 16:05:42 +08:00
d102ed124c 放弃打包流程, 退化目录 2025-11-05 11:15:49 +08:00
e07d604d12 增强ToolURL 2025-11-04 17:15:22 +08:00
e56d78a757 Add PrettyFace 2025-10-30 20:59:01 +08:00
17 changed files with 95 additions and 46 deletions

View File

View File

@@ -1,3 +0,0 @@
include LICENSE
include README.md
global-exclude *.meta

View File

@@ -10,7 +10,7 @@ class IModel(ABC):
pass pass
class IDataModel(ABC, IModel): class IDataModel(IModel):
@abstractmethod @abstractmethod
def Save(self) -> str: def Save(self) -> str:
pass pass
@@ -131,15 +131,16 @@ class Architecture:
if slot in cls._RegisteringRuntime: if slot in cls._RegisteringRuntime:
raise InvalidOperationError("Illegal duplicate registrations") raise InvalidOperationError("Illegal duplicate registrations")
cls._RegisteringRuntime[slot] = Architecture.Registering(slot, target, DependenceModel(Architecture.TypeQuery(dependence) for dependence in dependences), action) cls._RegisteringRuntime[slot] = Architecture.Registering(slot, target, DependenceModel(Architecture.TypeQuery(dependence) for dependence in dependences), action)
dependences = cls._RegisteringRuntime[slot].dependences
cls._InternalRegisteringComplete() cls._InternalRegisteringComplete()
return cls._RegisteringRuntime[slot].dependences return dependences
@classmethod @classmethod
def Contains(cls, type_:type) -> bool: def Contains(cls, type_:type) -> bool:
return type_ in cls._RegisteredObjects return type_ in cls._RegisteredObjects
@classmethod @classmethod
def Get(cls, type_:type) -> Any: def Get[T](cls, type_:Typen[T]) -> T:
return cls._RegisteredObjects[type_] return cls._RegisteredObjects[type_]
@classmethod @classmethod

View File

@@ -417,6 +417,22 @@ class PlatformIndicator:
IsPlatformX64 : bool = True IsPlatformX64 : bool = True
CompanyName : str = "DefaultCompany" CompanyName : str = "DefaultCompany"
ProductName : str = "DefaultProject" ProductName : str = "DefaultProject"
PrettyFace : str = r"""
""".strip()
@staticmethod @staticmethod
def GetFileSeparator(is_not_this_platform:bool = False) -> str: def GetFileSeparator(is_not_this_platform:bool = False) -> str:

View File

@@ -327,7 +327,7 @@ class ToolFile(BaseModel):
except: except:
pass pass
with open(self.OriginFullPath, 'w', encoding='utf-8') as f: with open(self.OriginFullPath, 'w', encoding='utf-8') as f:
json.dump(json_data, f, indent=4) json.dump(json_data, f, indent=4, ensure_ascii=False)
return self return self
def SaveAsCsv(self, csv_data:"pd.DataFrame"): def SaveAsCsv(self, csv_data:"pd.DataFrame"):
''' '''
@@ -504,12 +504,11 @@ class ToolFile(BaseModel):
return result return result
def DirWalk( def DirWalk(
self, self,
top,
topdown: bool = True, topdown: bool = True,
onerror: Optional[Callable] = None, onerror: Optional[Callable] = None,
followlinks: bool = False followlinks: bool = False
) -> Iterator[tuple[dir_name_type, list[dir_name_type], list[file_name_type]]]: ) -> Iterator[tuple[dir_name_type, list[dir_name_type], list[file_name_type]]]:
return os.walk(self.OriginFullPath, top=top, topdown=topdown, onerror=onerror, followlinks=followlinks) return os.walk(self.OriginFullPath, topdown=topdown, onerror=onerror, followlinks=followlinks)
def bool(self): def bool(self):

View File

@@ -228,7 +228,7 @@ class GlobalConfig:
return self return self
# 配置查找 # 配置查找
def FindItem(self, key: str, default: Any = None) -> Any: def FindItem[T](self, key: str, default: Optional[T] = None) -> Optional[T]:
"""查找配置项,支持默认值""" """查找配置项,支持默认值"""
if key in self._data_pair: if key in self._data_pair:
return self._data_pair[key] return self._data_pair[key]

View File

@@ -264,6 +264,78 @@ class ToolURL(BaseModel):
callback(None) callback(None)
return False return False
def PostJson(self, callback: Callable[[Optional[Any]], None],
json_data: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, str]] = None) -> bool:
"""
同步JSON POST请求
Args:
callback: 响应回调函数成功时接收响应对象失败时接收None
json_data: JSON数据字典
headers: 自定义请求头字典
Returns:
是否请求成功
"""
if not self.IsValid:
callback(None)
return False
try:
data = None
if json_data:
data = json.dumps(json_data).encode('utf-8')
req = urllib.request.Request(self.url, data=data, method='POST')
# 设置默认请求头
req.add_header('Content-Type', 'application/json')
# 添加自定义请求头
if headers:
for key, value in headers.items():
req.add_header(key, value)
with urllib.request.urlopen(req) as response:
callback(response)
return True
except Exception as e:
callback(None)
return False
async def PostJsonAsync(self, callback: Callable[[Optional[Any]], None],
json_data: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, str]] = None) -> bool:
"""
异步JSON POST请求
Args:
callback: 响应回调函数成功时接收响应对象失败时接收None
json_data: JSON数据字典
headers: 自定义请求头字典
Returns:
是否请求成功
"""
if not self.IsValid:
callback(None)
return False
try:
# 准备请求头
request_headers = {'Content-Type': 'application/json'}
if headers:
request_headers.update(headers)
async with aiohttp.ClientSession() as session:
async with session.post(self.url, json=json_data, headers=request_headers) as response:
callback(response)
return True
except Exception as e:
callback(None)
return False
# 内容加载方法 # 内容加载方法
def LoadAsText(self) -> str: def LoadAsText(self) -> str:
""" """

View File

@@ -1,9 +0,0 @@
import sys
import os
from time import sleep
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from Convention.Runtime.Config import *
PrintColorful(ConsoleFrontColor.RED, "Hello, World!")

View File

@@ -1,27 +0,0 @@
from setuptools import setup, find_packages
import io
setup(
name="Convention",
version="0.1.0",
author="LiuBai",
description="A python version code repository for implementing the agreements and implementations in the Convention-Template.",
long_description=io.open("README.md", encoding="utf-8").read(),
long_description_content_type="text/markdown",
url="https://github.com/NINEMINEsigma/Convention-Python",
packages=find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires=">=3.12",
install_requires=[
"colorama",
"pydantic",
"python-docx",
"Pillow",
"pydub"
],
exclude_package_data={"": ["*.meta"]},
)