# -*- coding: utf-8 -*- # t10-fixcrlf.py — 修复 t10-apply.py save() 的双 CR bug(\r\n 被写成 \r\r\n) # 仅处理含 \r\r\n 的 .bru(原本不含,必然是本次 apply 引入),还原为 \r\n。 import os, sys sys.stdout = __import__('io').TextIOWrapper(sys.stdout.buffer, encoding='utf-8') DOCS = r'E:\code\crm-api-docs' fixed = [] for root, dirs, files in os.walk(DOCS): if '.git' in root: continue for fn in files: if not fn.endswith('.bru'): continue p = os.path.join(root, fn) raw = open(p, 'rb').read() if b'\r\r\n' in raw: n = raw.count(b'\r\r\n') open(p, 'wb').write(raw.replace(b'\r\r\n', b'\r\n')) fixed.append((os.path.relpath(p, DOCS), n)) for rel, n in fixed: print('FIX %4d lines %s' % (n, rel)) print('fixed files:', len(fixed))