Added extra verbosity to show parsing error

This commit is contained in:
Rob McMullen 2016-10-01 18:42:39 -07:00
parent 7e51284cb1
commit 3a988495e8
3 changed files with 14 additions and 9 deletions

View File

@ -78,7 +78,7 @@ def run():
for mime in mime_parse_order:
if options.verbose:
print "Trying MIME type %s" % mime
parser = guess_parser_for_mime(mime, rawdata)
parser = guess_parser_for_mime(mime, rawdata, options.verbose)
if parser is None:
continue
if options.verbose:

View File

@ -179,14 +179,14 @@ class AtariDosFile(object):
first = False
continue
elif first:
raise InvalidBinaryFile
raise InvalidBinaryFile("Object file doesn't start with 0xffff")
log.debug("header parsing: header=0x%x" % header)
if len(b[pos:pos + 4]) < 4:
self.segments.append(ObjSegment(r[pos:pos + 4], 0, 0, 0, len(b[pos:pos + 4]), "Short Segment Header"))
break
start, end = b[pos:pos + 4].view(dtype='<u2')
if end < start:
raise InvalidBinaryFile
raise InvalidBinaryFile("Nonsensical start and end addresses")
count = end - start + 1
found = len(b[pos + 4:pos + 4 + count])
if found < count:

View File

@ -10,6 +10,9 @@ from mame import MameZipImage
from dos33 import Dos33DiskImage, ProdosDiskImage
from errors import *
import logging
log = logging.getLogger(__name__)
class SegmentParser(object):
menu_name = ""
@ -27,8 +30,8 @@ class SegmentParser(object):
self.image = self.get_image(r)
self.check_image()
self.image.parse_segments()
except AtrError:
raise InvalidSegmentParser
except AtrError, e:
raise InvalidSegmentParser(e)
self.segments.extend(self.image.segments)
def get_image(self, r):
@ -38,8 +41,8 @@ class SegmentParser(object):
if self.strict:
try:
self.image.strict_check()
except AtrError:
raise InvalidSegmentParser
except AtrError, e:
raise InvalidSegmentParser(e)
else:
self.image.relaxed_check()
@ -101,14 +104,16 @@ class ProdosSegmentParser(SegmentParser):
image_type = ProdosDiskImage
def guess_parser_for_mime(mime, r):
def guess_parser_for_mime(mime, r, verbose=False):
parsers = mime_parsers[mime]
found = None
for parser in parsers:
try:
found = parser(r, True)
break
except InvalidSegmentParser:
except InvalidSegmentParser, e:
if verbose:
log.info("parser isn't %s: %s" % (parser.__name__, str(e)))
pass
return found