-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathascii.py
30 lines (27 loc) · 1 KB
/
ascii.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /usr/bin/env python3
import altium
from sys import argv, stdout
from warnings import warn
def main(file):
with open(file, "rb") as file:
file = altium.OleFileIO(file)
for stream in ("FileHeader", "Storage", "Additional"):
if not file.exists(stream):
continue
stream = file.openstream(stream)
for [type, length] in altium.iter_records(stream):
if type != 0:
warn("Cannot handle record type " + format(type))
continue
record = stream.read(length - 1)
if b"\n" in record:
warn("Embedded newline in record")
stdout.buffer.write(record)
stdout.buffer.write(b"\n")
if stream.read(1) != b"\x00":
warn("Properties record not null-terminated")
if __name__ == "__main__":
try:
main(*argv[1:])
except (KeyboardInterrupt, ConnectionError):
raise SystemExit(1)