"""本主题专属离线算法，仅读取同目录合成JSON，不联网、不控制设备。"""
import csv, json, math, re, struct
from pathlib import Path
from fractions import Fraction
BASE=Path(__file__).resolve().parent
data=json.loads((BASE/'input.json').read_text(encoding='utf-8'))['data']
import xml.etree.ElementTree as ET
text=data['xml'];raw=text.encode('utf-8');buffer=raw+bytes([0])
ET.fromstring(raw)
bad=raw[:len(text)];invalid=False
try:ET.fromstring(bad)
except (ET.ParseError,UnicodeDecodeError):invalid=True
assert len(raw)>len(text) and invalid
result={'characters':len(text),'utf8_bytes_without_nul':len(raw),'explicit_frame_length_with_nul':len(buffer),'hex_with_nul':buffer.hex(),'complete_XML_valid':True,'character_count_truncation_rejected':invalid,'labels_are_custom':True}
(BASE/'result.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
print(json.dumps(result,ensure_ascii=False))
