- SixClient中引入异步请求方法try_get_url获取并验证备用主机地址 - 初始化__base_url时支持异步调用,提升启动时灵活性 - _do_post与相关异步请求方法改用异常抛出替代返回None规范错误处理 - 修正部分解码逻辑,确保签名等字段的正确Base64和URL解码 - 代码中添加日志和重试机制以提升异常处理和调试能力 - 删除june模块中遗留的单元测试代码 - 调整june模型中字段类型,支持可选字符串以增强健壮性 - apps/apple/clients/itunes中添加Field默认值,防止字段缺失错误 - itunes解析XML相关函数增强健壮性,避免空指针异常 - core.clients.http_client支持完整http路径调用,注释掉自动抛错逻辑以兼容特殊响应 - base.py中retry_backoff类型显式定义为float,提高代码类型安全性
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from xml.etree.ElementTree import Element, fromstring
|
|
|
|
|
|
def parse_xml(xml_str: str) -> dict:
|
|
root = fromstring(xml_str)
|
|
dict_data = {}
|
|
key = ""
|
|
dict_element = root.find("dict")
|
|
if dict_element is None:
|
|
return dict_data
|
|
for child in dict_element:
|
|
if child.tag == "key":
|
|
key = child.text or ""
|
|
else:
|
|
if child.tag == "integer":
|
|
dict_data[key] = int(child.text or "0")
|
|
elif child.tag == "string":
|
|
dict_data[key] = child.text if child.text else ""
|
|
elif child.tag == "true":
|
|
dict_data[key] = True
|
|
elif child.tag == "false":
|
|
dict_data[key] = False
|
|
elif child.tag == "array":
|
|
dict_data[key] = []
|
|
elif child.tag == "dict":
|
|
dict_data[key] = parse_xml_tree([x for x in child])
|
|
return dict_data
|
|
|
|
|
|
def parse_xml_tree(tree_list: list[Element]):
|
|
dict_data = {}
|
|
key = ""
|
|
for child in tree_list:
|
|
if child.tag == "key":
|
|
key = child.text or ""
|
|
else:
|
|
if child.tag == "string":
|
|
dict_data[key] = child.text if child.text else ""
|
|
if child.tag == "dict":
|
|
dict_data[key] = parse_xml_tree([x for x in child])
|
|
return dict_data
|