From 3a1f89810fedf98b66e1fae8b0c3f5862417730a Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Mon, 1 Nov 2010 04:59:47 +0200 Subject: 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). --- TOOLS/matroska.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'TOOLS/matroska.py') 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 -- cgit v1.2.3