f
This commit is contained in:
35
API/HTTP.py
35
API/HTTP.py
@@ -15,6 +15,7 @@ import time
|
||||
import traceback
|
||||
import re
|
||||
import os
|
||||
import json
|
||||
from typing import Optional, Dict, Any, Callable, List, Union
|
||||
from pathlib import Path
|
||||
from urllib.parse import unquote, urlparse, parse_qs
|
||||
@@ -464,14 +465,41 @@ class HTTPClient:
|
||||
|
||||
def _preview(value: Any, *, limit: int = 2000) -> str:
|
||||
if value is None:
|
||||
return "<null>"
|
||||
return "<not provided>"
|
||||
try:
|
||||
# File-like objects (uploads/streams) - show compact summary instead of raw contents
|
||||
if hasattr(value, "read") or hasattr(value, "fileno"):
|
||||
name = getattr(value, "name", None)
|
||||
total = getattr(value, "_total", None)
|
||||
label = getattr(value, "_label", None)
|
||||
try:
|
||||
pos = value.tell() if hasattr(value, "tell") else None
|
||||
except Exception:
|
||||
pos = None
|
||||
parts = []
|
||||
if name is not None:
|
||||
parts.append(f"name={name!r}")
|
||||
if total is not None:
|
||||
parts.append(f"total={total}")
|
||||
if label is not None:
|
||||
parts.append(f"label={label!r}")
|
||||
if pos is not None:
|
||||
parts.append(f"pos={pos}")
|
||||
summary = " ".join(parts) if parts else None
|
||||
return f"<file-like {summary}>" if summary else "<file-like>"
|
||||
|
||||
if isinstance(value, (dict, list, tuple)):
|
||||
text = json.dumps(value, ensure_ascii=False)
|
||||
# Use default=str to avoid failing on non-serializable objects (e.g., file-like)
|
||||
text = json.dumps(value, ensure_ascii=False, default=str)
|
||||
elif isinstance(value, (bytes, bytearray)):
|
||||
text = value.decode("utf-8", errors="replace")
|
||||
else:
|
||||
text = str(value)
|
||||
except Exception:
|
||||
text = repr(value)
|
||||
try:
|
||||
text = repr(value)
|
||||
except Exception:
|
||||
text = "<unprintable>"
|
||||
if len(text) > limit:
|
||||
return text[:limit] + "..."
|
||||
return text
|
||||
@@ -497,6 +525,7 @@ class HTTPClient:
|
||||
("data", _preview(kwargs.get("data"))),
|
||||
("json", _preview(kwargs.get("json"))),
|
||||
("content", _preview(kwargs.get("content"))),
|
||||
("files", _preview(kwargs.get("files"))),
|
||||
],
|
||||
)
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user