From 5549b5da97b8a395cc8076a53386acd76e05d006 Mon Sep 17 00:00:00 2001 From: anor Date: Thu, 26 Mar 2026 02:56:21 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BA=D0=B8=D1=80=D0=B8=D0=BB=D0=BB?= =?UTF-8?q?=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B5=20=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20=D0=B2=20?= =?UTF-8?q?ZIP=20=E2=80=94=20cp437=E2=86=92utf-8=20decode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Python zipfile декодирует имена как CP437 если UTF-8 flag не установлен. Результат: ЛС → ╨¢╨í, regex не находит шифр → 0 обработано. Теперь re-encode cp437→utf-8 для каждого файла в архиве. Co-Authored-By: Claude Opus 4.6 (1M context) --- batch.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/batch.py b/batch.py index 2afb59b..ff819c9 100644 --- a/batch.py +++ b/batch.py @@ -115,9 +115,22 @@ def read_xlsx_xml(path: str, max_rows: int = 50) -> dict: def extract_zip(zip_path: str, dest_dir: str) -> list[str]: - """Extract zip and return list of xlsx files.""" + """Extract zip and return list of xlsx files. + + Handles Cyrillic filenames: Python's zipfile decodes names as CP437 + when the UTF-8 flag is not set. We detect and fix this. + """ with zipfile.ZipFile(zip_path) as z: - z.extractall(dest_dir) + for info in z.infolist(): + # Fix Cyrillic filenames: if flag bit 11 is not set, + # Python decodes as CP437 — re-encode and decode as UTF-8 + if not (info.flag_bits & 0x800): + try: + fixed = info.filename.encode('cp437').decode('utf-8') + info.filename = fixed + except (UnicodeDecodeError, UnicodeEncodeError): + pass # keep original if re-decode fails + z.extract(info, dest_dir) files = [] for f in Path(dest_dir).rglob('*.xlsx'): if not f.name.startswith('~$'):