Skip to content

Commit bf42f56

Browse files
committed
v2.2: 统一 normalize_zh 默认为 None,捕获 ImportError 给出友好提示
1 parent 3b1c7e7 commit bf42f56

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/jmcomic/jm_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,14 @@ def new_postman(cls, session=False, **kwargs):
404404
# option 相关的默认配置
405405
# 一般情况下,建议使用option配置文件来定制配置
406406
# 而如果只想修改几个简单常用的配置,也可以下方的DEFAULT_XXX属性
407-
JM_OPTION_VER = '2.1'
407+
JM_OPTION_VER = '2.2'
408408
DEFAULT_CLIENT_IMPL = 'api' # 默认Client实现类型为网页端
409409
DEFAULT_CLIENT_CACHE = None # 默认关闭Client缓存。缓存的配置详见 CacheRegistry
410410
DEFAULT_PROXIES = ProxyBuilder.system_proxy() # 默认使用系统代理
411411

412412
DEFAULT_OPTION_DICT: dict = {
413413
'log': None,
414-
'dir_rule': {'rule': 'Bd_Pname', 'base_dir': None, 'normalize_zh': ''},
414+
'dir_rule': {'rule': 'Bd_Pname', 'base_dir': None, 'normalize_zh': None},
415415
'download': {
416416
'cache': True,
417417
'image': {'decode': True, 'suffix': None},

src/jmcomic/jm_toolkit.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,23 @@ def to_zh(cls, s, target=None):
349349

350350
try:
351351
import zhconv
352+
<<<<<<< HEAD
352353
return zhconv.convert(s, target)
353354
except Exception as e:
354-
# 如果 zhconv 不可用或转换失败,则回退原字符串
355+
if target is None:
356+
=======
357+
return zhconv.convert(s, t)
358+
t = str(target).strip().lower()
359+
if t in ('none', ''):
360+
return s
361+
362+
try:
363+
import zhconv
364+
return zhconv.convert(s, t)
365+
return s
366+
except Exception as e:
367+
# 如果 zhconv 可用但转换失败,则记录错误并回退原字符串
368+
>>>>>>> ac91a56 (v2.2: 统一 normalize_zh 默认为 None捕获 ImportError 给出友好提示)
355369
jm_log('zhconv.error', f'error: [{e}], s: [{s}]')
356370
return s
357371

0 commit comments

Comments
 (0)