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).
This commit is contained in:
Uoti Urpala 2010-11-01 04:59:47 +02:00
parent 49096c7ae2
commit 3a1f89810f
1 changed files with 10 additions and 2 deletions

View File

@ -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