jmcomic 2.7.7__tar.gz → 2.7.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {jmcomic-2.7.7/src/jmcomic.egg-info → jmcomic-2.7.8}/PKG-INFO +1 -1
  2. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/__init__.py +1 -1
  3. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_async_client.py +8 -10
  4. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_client_impl.py +8 -14
  5. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_toolkit.py +1 -1
  6. {jmcomic-2.7.7 → jmcomic-2.7.8/src/jmcomic.egg-info}/PKG-INFO +1 -1
  7. {jmcomic-2.7.7 → jmcomic-2.7.8}/LICENSE +0 -0
  8. {jmcomic-2.7.7 → jmcomic-2.7.8}/README.md +0 -0
  9. {jmcomic-2.7.7 → jmcomic-2.7.8}/pyproject.toml +0 -0
  10. {jmcomic-2.7.7 → jmcomic-2.7.8}/setup.cfg +0 -0
  11. {jmcomic-2.7.7 → jmcomic-2.7.8}/setup.py +0 -0
  12. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/api.py +0 -0
  13. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/cli.py +0 -0
  14. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_async_downloader.py +0 -0
  15. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_client_interface.py +0 -0
  16. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_config.py +0 -0
  17. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_downloader.py +0 -0
  18. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_entity.py +0 -0
  19. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_exception.py +0 -0
  20. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_feature.py +0 -0
  21. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_option.py +0 -0
  22. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_plugin.py +0 -0
  23. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic/jm_task_context.py +0 -0
  24. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic.egg-info/SOURCES.txt +0 -0
  25. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic.egg-info/dependency_links.txt +0 -0
  26. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic.egg-info/entry_points.txt +0 -0
  27. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic.egg-info/requires.txt +0 -0
  28. {jmcomic-2.7.7 → jmcomic-2.7.8}/src/jmcomic.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jmcomic
3
- Version: 2.7.7
3
+ Version: 2.7.8
4
4
  Summary: Python API For JMComic (禁漫天堂)
5
5
  Home-page: https://github.com/hect0x7/JMComic-Crawler-Python
6
6
  Author: hect0x7
@@ -2,7 +2,7 @@
2
2
  # 被依赖方 <--- 使用方
3
3
  # config <--- entity <--- toolkit <--- client <--- option <--- downloader
4
4
 
5
- __version__ = '2.7.7'
5
+ __version__ = '2.7.8'
6
6
 
7
7
  from .jm_task_context import *
8
8
  from .api import *
@@ -337,16 +337,14 @@ class AsyncJmApiClient(AsyncJmcomicClient):
337
337
  # /chapter_view_template 这个接口不是返回json数据,不做检查
338
338
  return
339
339
 
340
- # 检查响应的第一个有效字符是否为 '{'(JSON 格式)
341
- text = resp.text
342
- for char in text:
343
- if char not in (' ', '\n', '\t'):
344
- ExceptionTool.require_true(
345
- char == '{',
346
- f'请求不是json格式,强制重试!响应文本: [{JmcomicText.limit_text(text, 200)}]'
347
- )
348
- return
349
- ExceptionTool.raises_resp(f'响应无数据!', resp)
340
+ try:
341
+ JmcomicText.try_parse_json_object(getattr(resp, 'text', ''))
342
+ except Exception:
343
+ text = getattr(resp, 'text', '')
344
+ ExceptionTool.raises_resp(
345
+ f'请求不是json格式,强制重试!响应文本: [{JmcomicText.limit_text(text, 200)}]',
346
+ resp,
347
+ )
350
348
 
351
349
  @staticmethod
352
350
  def _require_resp_success(resp: JmApiResp):
@@ -1244,9 +1244,6 @@ class JmApiClient(AbstractJmClient):
1244
1244
  """
1245
1245
  该方法会判断resp返回值是否是json格式,
1246
1246
  如果不是,大概率是禁漫内部异常,需要进行重试
1247
-
1248
- 由于完整的json格式校验会有性能开销,所以只做简单的检查,
1249
- 只校验第一个有效字符是不是 '{',如果不是,就认为异常数据,需要重试
1250
1247
  """
1251
1248
  resp = super().raise_if_resp_should_retry(resp, is_image)
1252
1249
 
@@ -1266,17 +1263,14 @@ class JmApiClient(AbstractJmClient):
1266
1263
  # /chapter_view_template 这个接口不是返回json数据,不做检查
1267
1264
  return resp
1268
1265
 
1269
- text = resp.text
1270
- for char in text:
1271
- if char not in (' ', '\n', '\t'):
1272
- # 找到第一个有效字符
1273
- ExceptionTool.require_true(
1274
- char == '{',
1275
- f'请求不是json格式,强制重试!响应文本: [{JmcomicText.limit_text(text, 200)}]'
1276
- )
1277
- return resp
1278
-
1279
- ExceptionTool.raises_resp(f'响应无数据!request_url=[{url}]', resp)
1266
+ try:
1267
+ JmcomicText.try_parse_json_object(resp.text)
1268
+ return resp
1269
+ except Exception:
1270
+ ExceptionTool.raises_resp(
1271
+ f'请求不是json格式,强制重试!响应文本: [{JmcomicText.limit_text(resp.text, 200)}]',
1272
+ resp,
1273
+ )
1280
1274
 
1281
1275
  def after_init(self):
1282
1276
  # 自动更新禁漫API域名
@@ -408,7 +408,7 @@ class JmcomicText:
408
408
  @classmethod
409
409
  def try_parse_json_object(cls, resp_text: str) -> dict:
410
410
  import json
411
- text = resp_text.strip()
411
+ text = resp_text.strip().lstrip('\ufeff')
412
412
  if text.startswith('{') and text.endswith('}'):
413
413
  # fast case
414
414
  return json.loads(text)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jmcomic
3
- Version: 2.7.7
3
+ Version: 2.7.8
4
4
  Summary: Python API For JMComic (禁漫天堂)
5
5
  Home-page: https://github.com/hect0x7/JMComic-Crawler-Python
6
6
  Author: hect0x7
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes