mirror of
https://github.com/mpv-player/mpv
synced 2024-10-02 16:25:33 +02:00
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:
parent
49096c7ae2
commit
3a1f89810f
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user