feat(operit): 增强转译层并接入 5 个 Operit 市场插件
operit_loader.py: - OkHttp 新增 newClient()(真实市场插件普遍使用,而非 newBuilder) - OkHttpRequest.execute() 改为 async,与 Operit 运行时异步语义对齐 - OkHttpResponse 新增 json() 与 statusMessage()(基于 http.HTTPStatus) operit_translate.py(新增): - Operit .ts 插件 -> xiaoli-cli .py 脚手架生成器 - 自动提取 METADATA、生成 exports 胶水,原 TS 作参考注释保留 plugins/operit_scripts/ 新增 5 个已跑通的真实插件: - market_time 时间查询/格式化 - market_duckduckgo 网页内容抓取与清洗 - market_crossref Crossref 学术文献检索 - market_network_test HTTP 连通性测试 - market_reader 本地代码递归搜索 注: 工具需注册为 async 包装函数,同步 lambda 会导致 complete() 不执行的假阳性
This commit is contained in:
1 parent
f7f7033e57
commit
388ac493af
7 files changed
+868
-1
No files matched your search
@@ -26,6 +26,7 @@ import time
|
||||
import shutil
|
||||
import base64
|
||||
import hashlib
|
||||
import http
|
||||
import platform
|
||||
import subprocess
|
||||
import tempfile
|
||||
@@ -145,10 +146,18 @@ class OkHttpResponse:
|
||||
self.statusCode = status_code
|
||||
self.content = content
|
||||
self._headers = headers or {}
|
||||
try:
|
||||
self.statusMessage = http.HTTPStatus(status_code).phrase
|
||||
except Exception:
|
||||
self.statusMessage = ""
|
||||
|
||||
def isSuccessful(self) -> bool:
|
||||
return 200 <= self.statusCode < 300
|
||||
|
||||
def json(self):
|
||||
import json as _json
|
||||
return _json.loads(self.content)
|
||||
|
||||
def headers(self) -> dict:
|
||||
return self._headers
|
||||
|
||||
@@ -185,7 +194,7 @@ class OkHttpRequest:
|
||||
def build(self) -> "OkHttpRequest":
|
||||
return self
|
||||
|
||||
def execute(self) -> OkHttpResponse:
|
||||
async def execute(self) -> OkHttpResponse:
|
||||
if requests is None and httpx is None:
|
||||
raise RuntimeError("需要安装 requests 或 httpx: pip install requests")
|
||||
lib = requests or httpx
|
||||
@@ -231,6 +240,11 @@ class _OkHttp:
|
||||
def newBuilder() -> OkHttpBuilder:
|
||||
return OkHttpBuilder()
|
||||
|
||||
@staticmethod
|
||||
def newClient() -> OkHttpClient:
|
||||
# 真实 Operit 插件用 OkHttp.newClient() 而非 newBuilder().build()
|
||||
return OkHttpClient()
|
||||
|
||||
|
||||
OkHttp = _OkHttp()
|
||||
|
||||
|
||||
Reference in new issue
Block a user