From ef43072848ca560f1e311b16c6f0d7e7a64a9cb3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Jul 2026 22:59:03 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- studio/backend/core/inference/tools.py | 15 ++++++++------- .../backend/tests/test_web_fetch_binary_guard.py | 6 ++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/studio/backend/core/inference/tools.py b/studio/backend/core/inference/tools.py index 63ade9ed06..93826bf2af 100644 --- a/studio/backend/core/inference/tools.py +++ b/studio/backend/core/inference/tools.py @@ -1393,16 +1393,16 @@ _BINARY_CHAR_DIVISOR = 8 # text/*; matched by signature because their replacement-char density alone can # be low (e.g. a PDF whose first chunk is mostly ASCII object/xref syntax). _BINARY_MAGIC = ( - b"%PDF-", # PDF - b"PK\x03\x04", # zip / docx / xlsx / pptx / epub / jar + b"%PDF-", # PDF + b"PK\x03\x04", # zip / docx / xlsx / pptx / epub / jar b"\x89PNG\r\n\x1a\n", # PNG - b"\xff\xd8\xff", # JPEG + b"\xff\xd8\xff", # JPEG b"GIF87a", b"GIF89a", - b"\x1f\x8b", # gzip - b"BZh", # bzip2 - b"\xfd7zXZ\x00", # xz - b"\x28\xb5\x2f\xfd", # zstd + b"\x1f\x8b", # gzip + b"BZh", # bzip2 + b"\xfd7zXZ\x00", # xz + b"\x28\xb5\x2f\xfd", # zstd ) @@ -1413,6 +1413,7 @@ def _looks_binary(text: str) -> bool: _MIN_BINARY_CHARS, len(text) // _BINARY_CHAR_DIVISOR ) + _USER_AGENTS = ( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", diff --git a/studio/backend/tests/test_web_fetch_binary_guard.py b/studio/backend/tests/test_web_fetch_binary_guard.py index 62231eeff9..92dd9411be 100644 --- a/studio/backend/tests/test_web_fetch_binary_guard.py +++ b/studio/backend/tests/test_web_fetch_binary_guard.py @@ -148,8 +148,10 @@ def test_compression_mislabeled_as_text_caught_by_magic(monkeypatch, magic): def test_latin1_text_without_charset_kept(monkeypatch): # Accent-dense cp1252 text with no declared charset decodes to many U+FFFD as # UTF-8; the cp1252 retry must keep it instead of dropping it as binary. - body = ("Muller lauft uber die Strasse: schoene, groesse. MARKERWORD ".replace("ue", "ü") - + "äöüß éèà ") * 30 + body = ( + "Muller lauft uber die Strasse: schoene, groesse. MARKERWORD ".replace("ue", "ü") + + "äöüß éèà " + ) * 30 out = _fetch_with(monkeypatch, body.encode("cp1252"), "text/plain") assert "binary content" not in out assert "MARKERWORD" in out