diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-11-01 04:59:47 +0200 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-11-02 04:18:37 +0200 |
commit | 3a1f89810fedf98b66e1fae8b0c3f5862417730a (patch) | |
tree | bf88d45f95cdd2afdf57b3f91c64e4beb136856f /TOOLS/matroska.py | |
parent | 49096c7ae28bdaa350d6d184e741f0d48dac8fbb (diff) | |
download | mpv-3a1f89810fedf98b66e1fae8b0c3f5862417730a.tar.bz2 mpv-3a1f89810fedf98b66e1fae8b0c3f5862417730a.tar.xz |
TOOLS/matroska.py: stop cleanly at EOF of complete file when parsing
When using the script to parse a Matroska file, the script used to
exit with an exception at EOF. Change it to exit quietly instead if
the file was parsed successfully. Keep showing an exception if EOF is
encountered in the middle of an element (truncated file).
Diffstat (limited to 'TOOLS/matroska.py')
-rwxr-xr-x | TOOLS/matroska.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/TOOLS/matroska.py b/TOOLS/matroska.py index 24c962f53b..6b61bb3eef 100755 --- a/TOOLS/matroska.py +++ b/TOOLS/matroska.py @@ -183,6 +183,8 @@ from binascii import hexlify def byte2num(s): return int(hexlify(s), 16) +class EOF(Exception): pass + def camelcase_to_words(name): parts = [] start = 0 @@ -295,7 +297,7 @@ def generate_C_definitions(): def read(s, length): t = s.read(length) if len(t) != length: - raise IOError + raise EOF return t def read_id(s): @@ -411,4 +413,10 @@ elif sys.argv[1] == '--generate-definitions': else: s = open(sys.argv[1], "rb") while 1: - parse_toplevel(s) + start = s.tell() + try: + parse_toplevel(s) + except EOF: + if s.tell() != start: + raise Exception("Unexpected end of file") + break |