@@ -298,21 +298,27 @@ def build_jm_client(self, **kwargs):
298298 """
299299 return self .new_jm_client (** kwargs )
300300
301- def new_jm_client (self , domain_list = None , impl = None , ** kwargs ) -> JmcomicClient :
302- postman_conf : dict = self .client .postman .src_dict
303- impl = impl or self .client .impl
301+ def new_jm_client (self , domain = None , impl = None , ** kwargs ) -> JmcomicClient :
302+ # 所有需要用到的 self.client 配置项如下
303+ postman_conf : dict = self .client .postman .src_dict # postman dsl 配置
304+ impl : str = impl or self .client .impl # client_key
305+ retry_times : int = self .client .retry_times # 重试次数
306+ cache : str = self .client .cache # 启用缓存
304307
305- # domain_list
306- if domain_list is None :
307- domain_list = self .client .domain
308+ # domain
309+ def decide_domain ():
310+ domain_list : Union [List [str ], DictModel , dict ] = domain if domain is not None \
311+ else self .client .domain # 域名
308312
309- domain_list : Union [List [str ], DictModel ]
310- if not isinstance (domain_list , list ):
311- domain_list_dict : DictModel = domain_list
312- domain_list = domain_list_dict .get (impl , [])
313+ if not isinstance (domain_list , list ):
314+ domain_list = domain_list .get (impl , [])
313315
314- if len (domain_list ) == 0 :
315- domain_list = self .decide_client_domain (impl )
316+ if len (domain_list ) == 0 :
317+ domain_list = self .decide_client_domain (impl )
318+
319+ return domain_list
320+
321+ domain : List [str ] = decide_domain ()
316322
317323 # support kwargs overwrite meta_data
318324 if len (kwargs ) != 0 :
@@ -321,20 +327,23 @@ def new_jm_client(self, domain_list=None, impl=None, **kwargs) -> JmcomicClient:
321327 # headers
322328 meta_data = postman_conf ['meta_data' ]
323329 if meta_data ['headers' ] is None :
324- meta_data ['headers' ] = JmModuleConfig .headers (domain_list [0 ])
330+ meta_data ['headers' ] = JmModuleConfig .headers (domain [0 ])
325331
326332 # postman
327333 postman = Postmans .create (data = postman_conf )
328334
329335 # client
330- client = JmModuleConfig .client_impl_class (impl )(
336+ clazz = JmModuleConfig .client_impl_class (impl )
337+ if clazz == AbstractJmClient or not issubclass (clazz , AbstractJmClient ):
338+ raise NotImplementedError (clazz )
339+ client = clazz (
331340 postman ,
332- self . client . retry_times ,
333- fallback_domain_list = domain_list ,
341+ retry_times ,
342+ fallback_domain_list = decide_domain () ,
334343 )
335344
336345 # enable cache
337- if self . client . cache is True :
346+ if cache is True :
338347 client .enable_cache ()
339348
340349 return client
@@ -396,7 +405,7 @@ def call_all_plugin(self, group: str, **extra):
396405 # 保证 jm_plugin.py 被加载
397406 from .jm_plugin import JmOptionPlugin
398407
399- plugin_registry = JmModuleConfig .PLUGIN_REGISTRY
408+ plugin_registry = JmModuleConfig .REGISTRY_PLUGIN
400409 for pinfo in plugin_list :
401410 key , kwargs = pinfo ['plugin' ], pinfo ['kwargs' ]
402411 plugin_class : Optional [Type [JmOptionPlugin ]] = plugin_registry .get (key , None )
0 commit comments