From 645de137f2d8371a8c513350a4fcbecea4662e96 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 8 May 2025 14:26:47 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=8F=92=E4=BB=B6=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/plugin.py | 14 +++++++++----- app/utils/object.py | 15 +++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/core/plugin.py b/app/core/plugin.py index 6d39fe21..d0bd95eb 100644 --- a/app/core/plugin.py +++ b/app/core/plugin.py @@ -465,13 +465,15 @@ class PluginManager(metaclass=Singleton): }] """ ret_apis = [] - for plugin_id, plugin in self._running_plugins.items(): + if pid: + plugins = {pid: self._running_plugins.get(pid)} + else: + plugins = self._running_plugins + for plugin_id, plugin in plugins.items(): if pid and pid != plugin_id: continue if hasattr(plugin, "get_api") and ObjectUtils.check_method(plugin.get_api): try: - if not plugin.get_state(): - continue apis = plugin.get_api() or [] for api in apis: api["path"] = f"/{plugin_id}{api['path']}" @@ -831,7 +833,8 @@ class PluginManager(metaclass=Singleton): logger.debug(f"获取插件是否在本地包中存在失败,{e}") return False - def get_plugins_from_market(self, market: str, package_version: Optional[str] = None) -> Optional[List[schemas.Plugin]]: + def get_plugins_from_market(self, market: str, package_version: Optional[str] = None) -> Optional[ + List[schemas.Plugin]]: """ 从指定的市场获取插件信息 :param market: 市场的 URL 或标识 @@ -845,7 +848,8 @@ class PluginManager(metaclass=Singleton): # 获取在线插件 online_plugins = self.pluginhelper.get_plugins(market, package_version) if online_plugins is None: - logger.warning(f"获取{package_version if package_version else ''}插件库失败:{market},请检查 GitHub 网络连接") + logger.warning( + f"获取{package_version if package_version else ''}插件库失败:{market},请检查 GitHub 网络连接") return [] ret_plugins = [] add_time = len(online_plugins) diff --git a/app/utils/object.py b/app/utils/object.py index 08bcc07f..559e31ff 100644 --- a/app/utils/object.py +++ b/app/utils/object.py @@ -52,21 +52,28 @@ class ObjectUtils: # 跳过空行 if not line: continue - # 处理多行注释 + # 处理"""单行注释 + if line.startswith(('"""', "'''")) and line.endswith(('"""', "'''")): + continue + # 处理"""多行注释 if line.startswith(('"""', "'''")): in_comment = not in_comment continue # 在注释中则跳过 if in_comment: continue - # 跳过注释、pass语句、装饰器、函数定义行 - if line.startswith('#') or line == "pass" or line.startswith('@') or line.startswith('def '): + # 跳过#注释、pass语句、装饰器、函数定义行 + if (line.startswith('#') + or line == "pass" + or line.startswith('@') + or line.startswith('def ')): continue # 发现有效代码行 return True # 没有有效代码行 return False - except Exception: + except Exception as err: + print(err) # 源代码分析失败时,进行字节码分析 code_obj = func.__code__ instructions = list(dis.get_instructions(code_obj))