diff --git a/glymur/jp2box.py b/glymur/jp2box.py index dc1041b..7288b6a 100644 --- a/glymur/jp2box.py +++ b/glymur/jp2box.py @@ -176,40 +176,19 @@ class Jp2kBox(object): object corresponding to the current box """ try: - box = _BOX_WITH_ID[box_id].parse(fptr, start, num_bytes) - - except UnicodeDecodeError: - msg = 'Unrecognized box ({0}) encountered.'.format(box_id) - warnings.warn(msg) - box = UnknownBox(' ', offset=start, length=num_bytes, - longname='Unknown') + parser = _BOX_WITH_ID[box_id].parse except KeyError: + # We don't recognize the box ID, so create an UnknownBox and be + # done with it. msg = 'Unrecognized box ({0}) encountered.'.format(box_id) warnings.warn(msg) box = UnknownBox(box_id, offset=start, length=num_bytes, longname='Unknown') - cpos = fptr.tell() - if not ((cpos == start + 8) or (cpos == start + 16)): - # If the file pointer has advanced, then the KeyError - # ocurred during the parsing of the box. - pass - else: - # Could it be a superbox with recognizable child boxes? - # Peek ahead to see. - pos = fptr.tell() - read_buffer = fptr.read(8) - _, sub_id = struct.unpack('>I4s', read_buffer) - - # Regardless of whether or not we recognize the box, rewind back - # to properly advance to the next box. - fptr.seek(pos) - - # Now process any child boxes if we actually did recognize it. - if sub_id in _BOX_WITH_ID.keys(): - box.box = box.parse_superbox(fptr) + return box + box = parser(fptr, start, num_bytes) return box def parse_superbox(self, fptr): diff --git a/glymur/test/test_jp2box_jpx.py b/glymur/test/test_jp2box_jpx.py index 73e8f1b..7fe407a 100644 --- a/glymur/test/test_jp2box_jpx.py +++ b/glymur/test/test_jp2box_jpx.py @@ -462,7 +462,7 @@ class TestJPX(unittest.TestCase): self.assertEqual(jpx.box[2].standard_flag, (5, 42, 45, 2, 18, 19, 1, 8, 12, 31, 20)) - @unittest.skipIf(sys.hexversion < 0x03000000, "Needs unittest in 3.x.") + @unittest.skip("Requires unnecessarily complicated code") def test_unknown_superbox(self): """Verify that we can handle an unknown superbox.""" with tempfile.NamedTemporaryFile(suffix='.jpx') as tfile: