style: apply ruff format to OCR modules
This commit is contained in:
+10
-6
@@ -295,11 +295,15 @@ class OcrClient:
|
||||
await self._record_quietly(self._quota.mark_progress())
|
||||
self._feed_outcome(source.name, ok=True)
|
||||
latency_ms = int((self._now() - started) * 1000)
|
||||
await self._emit(kind, image, source, call_id, started, session_id, parent_call_id, result)
|
||||
await self._emit(
|
||||
kind, image, source, call_id, started, session_id, parent_call_id, result
|
||||
)
|
||||
return _AttemptOutcome(result, source, call_id, latency_ms)
|
||||
except (RequestRejectedError, ResultInvalidError) as exc:
|
||||
await self._gate_on_terminal(exc, entry)
|
||||
await self._emit(kind, image, source, call_id, started, session_id, parent_call_id, error=exc)
|
||||
await self._emit(
|
||||
kind, image, source, call_id, started, session_id, parent_call_id, error=exc
|
||||
)
|
||||
raise
|
||||
except asyncio.CancelledError:
|
||||
if entry.is_probe:
|
||||
@@ -314,7 +318,9 @@ class OcrClient:
|
||||
reasons[source.name] = reason
|
||||
await self._record_quietly(self._breaker.record_failure(entry, reason, dead))
|
||||
self._feed_outcome(source.name, ok=False)
|
||||
await self._emit(kind, image, source, call_id, started, session_id, parent_call_id, error=exc)
|
||||
await self._emit(
|
||||
kind, image, source, call_id, started, session_id, parent_call_id, error=exc
|
||||
)
|
||||
return _FailedAttempt(exc, immediate=dead)
|
||||
finally:
|
||||
await self._settle_and_release(permit)
|
||||
@@ -474,9 +480,7 @@ class OcrClient:
|
||||
# 严禁静默用 MonkeyOcrTransport 打别家端点(默认值掩盖错误)
|
||||
alien = sorted({s.provider for s in sources if s.provider != "monkey"})
|
||||
if alien:
|
||||
raise ValueError(
|
||||
f"OCR 装配仅支持 provider=monkey(D9 其余后端预留未实现): 发现 {alien}"
|
||||
)
|
||||
raise ValueError(f"OCR 装配仅支持 provider=monkey(D9 其余后端预留未实现): 发现 {alien}")
|
||||
return cls(
|
||||
scope=gw.scope,
|
||||
sources=sources,
|
||||
|
||||
@@ -75,7 +75,11 @@ def _classify_status(
|
||||
exc: httpx.HTTPStatusError, source_name: str, operation: str
|
||||
) -> TransientError | SourceDeadError | RequestRejectedError:
|
||||
status = exc.response.status_code
|
||||
ctx: dict[str, Any] = {"source_name": source_name, "status_code": status, "operation": operation}
|
||||
ctx: dict[str, Any] = {
|
||||
"source_name": source_name,
|
||||
"status_code": status,
|
||||
"operation": operation,
|
||||
}
|
||||
message = f"{source_name} OCR {operation} HTTP {status}"
|
||||
if status >= 500 or status == 429:
|
||||
return TransientError(message, **ctx)
|
||||
@@ -146,7 +150,9 @@ def _parse_pages(payload: object) -> tuple[list[OcrLayoutElement], list[tuple[fl
|
||||
return elements, page_sizes
|
||||
|
||||
|
||||
def _parse_middle_json(zip_bytes: bytes) -> tuple[list[OcrLayoutElement], list[tuple[float, float]]]:
|
||||
def _parse_middle_json(
|
||||
zip_bytes: bytes,
|
||||
) -> tuple[list[OcrLayoutElement], list[tuple[float, float]]]:
|
||||
"""ZIP → (elements, page_sizes);一切形态异常归 ResultInvalid(坏图≠坏服务)。
|
||||
|
||||
数值防御全量下沉自 CHS `_parse_table_result`(invokers.py:437-479),
|
||||
|
||||
Reference in New Issue
Block a user