Code simplification

pull/581/head
Serguei E. Leontiev 2 years ago
parent 7bc007c2fd
commit 53b57f8abb

@ -230,21 +230,16 @@ def _read_yaml_unicode(f: io.IOBase) -> str:
elif bs.startswith(b'+/v8'): elif bs.startswith(b'+/v8'):
f.reconfigure(encoding='utf-7', errors='strict') f.reconfigure(encoding='utf-7', errors='strict')
else: else:
if len(bs) >= 4: if len(bs) >= 4 and bs[:3] == b'\x00\x00\x00' and bs[3]:
if bs[:3] == b'\x00\x00\x00' and bs[3]: f.reconfigure(encoding='utf-32be', errors='strict')
f.reconfigure(encoding='utf-32be', errors='strict') elif len(bs) >= 4 and bs[0] and bs[1:4] == b'\x00\x00\x00':
return (f.read(), False) f.reconfigure(encoding='utf-32le', errors='strict')
if bs[0] and bs[1:4] == b'\x00\x00\x00': elif len(bs) >= 2 and bs[0] == 0 and bs[1]:
f.reconfigure(encoding='utf-32le', errors='strict') f.reconfigure(encoding='utf-16be', errors='strict')
return (f.read(), False) elif len(bs) >= 2 and bs[0] and bs[1] == 0:
if len(bs) >= 2: f.reconfigure(encoding='utf-16le', errors='strict')
if bs[0] == 0 and bs[1]: else:
f.reconfigure(encoding='utf-16be', errors='strict') f.reconfigure(encoding='utf-8', errors='strict')
return (f.read(), False)
if bs[0] and bs[1] == 0:
f.reconfigure(encoding='utf-16le', errors='strict')
return (f.read(), False)
f.reconfigure(encoding='utf-8', errors='strict')
return (f.read(), False) return (f.read(), False)
initial_bom = f.read(1) initial_bom = f.read(1)
assert initial_bom == '\uFEFF' assert initial_bom == '\uFEFF'

Loading…
Cancel
Save