Skip to content

Commit

Permalink
v2.1.21: 增加client的域名配置方法以方便配置域名
Browse files Browse the repository at this point in the history
  • Loading branch information
hect0x7 committed Aug 29, 2023
1 parent de074f8 commit e3022fb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/jmcomic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# 被依赖方 <--- 使用方
# config <--- entity <--- toolkit <--- client <--- option <--- downloader

__version__ = '2.1.19'
__version__ = '2.1.21'

from .api import *
7 changes: 6 additions & 1 deletion src/jmcomic/jm_client_impl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .jm_client_interface import *


# noinspection PyAbstractClass
class AbstractJmClient(
JmcomicClient,
PostmanProxy,
Expand Down Expand Up @@ -139,6 +138,12 @@ def get_jmcomic_url(self, postman=None):
def get_jmcomic_domain_all(self, postman=None):
return JmModuleConfig.get_jmcomic_domain_all(postman or self.get_root_postman())

def get_domain_list(self):
return self.domain_list

def set_domain_list(self, domain_list: List[str]):
self.domain_list = domain_list

# noinspection PyUnusedLocal
def fallback(self, request, url, domain_index, retry_count, **kwargs):
msg = f"请求重试全部失败: [{url}], {self.domain_list}"
Expand Down
14 changes: 10 additions & 4 deletions src/jmcomic/jm_client_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,14 @@ class JmcomicClient(
JmUserClient,
Postman,
):
def get_jmcomic_url(self, postman=None):
return JmModuleConfig.get_jmcomic_url(postman or self)
def get_jmcomic_url(self):
return JmModuleConfig.get_jmcomic_url()

def get_jmcomic_domain_all(self, postman=None):
return JmModuleConfig.get_jmcomic_domain_all(postman or self)
def get_jmcomic_domain_all(self):
return JmModuleConfig.get_jmcomic_domain_all()

def get_domain_list(self) -> List[str]:
raise NotImplementedError

def set_domain_list(self, domain_list: List[str]):
raise NotImplementedError
6 changes: 3 additions & 3 deletions src/jmcomic/jm_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ def to_file(self, filepath=None):
"""

@field_cache("__jm_client_cache__")
def build_jm_client(self, **kwargs) -> JmcomicClient:
def build_jm_client(self, **kwargs):
"""
该方法会首次调用会创建JmcomicClient对象,
然后保存在self.__jm_client_cache__中,
多次调用`不会`创建新的JmcomicClient对象
"""
return self.new_jm_client(**kwargs)

def new_jm_client(self, **kwargs) -> JmcomicClient:
def new_jm_client(self, domain_list=None, **kwargs) -> JmcomicClient:
postman_conf: dict = self.client.postman.src_dict

# support kwargs overwrite meta_data
Expand All @@ -247,7 +247,7 @@ def new_jm_client(self, **kwargs) -> JmcomicClient:
postman = Postmans.create(data=postman_conf)

# domain_list
domain_list = self.client.domain
domain_list: List[str] = domain_list or self.client.domain
if len(domain_list) == 0:
domain_list = [JmModuleConfig.domain()]

Expand Down

0 comments on commit e3022fb

Please sign in to comment.