Added UUIDBox and ContiguousCodeStreamBox repr support. Closes #133
This commit is contained in:
parent
9caf5c9f08
commit
5e5bff39c3
2 changed files with 47 additions and 1 deletions
|
|
@ -773,6 +773,10 @@ class ContiguousCodestreamBox(Jp2kBox):
|
|||
self.length = length
|
||||
self.offset = offset
|
||||
|
||||
def __repr__(self):
|
||||
msg = "glymur.jp2box.ContiguousCodeStreamBox(main_header={0})"
|
||||
return msg.format(repr(self.main_header))
|
||||
|
||||
def __str__(self):
|
||||
msg = Jp2kBox.__str__(self)
|
||||
msg += '\n Main header:'
|
||||
|
|
@ -978,7 +982,6 @@ class ImageHeaderBox(Jp2kBox):
|
|||
return msg
|
||||
|
||||
def __str__(self):
|
||||
msg = Jp2kBox.__str__(self)
|
||||
msg = "{0}"
|
||||
msg += '\n Size: [{1} {2} {3}]'
|
||||
msg += '\n Bitdepth: {4}'
|
||||
|
|
@ -2238,6 +2241,7 @@ class UUIDBox(Jp2kBox):
|
|||
"""
|
||||
Jp2kBox.__init__(self, box_id='uuid', longname='UUID')
|
||||
self.uuid = the_uuid
|
||||
self.raw_data = raw_data
|
||||
|
||||
if the_uuid == uuid.UUID('be7acfcb-97a9-42e8-9c71-999491e3afac'):
|
||||
# XMP data. Parse as XML. Seems to be a difference between
|
||||
|
|
@ -2262,6 +2266,12 @@ class UUIDBox(Jp2kBox):
|
|||
self.length = length
|
||||
self.offset = offset
|
||||
|
||||
def __repr__(self):
|
||||
msg = "glymur.jp2box.UUIDBox(the_uuid={0}, "
|
||||
msg += "raw_data=<byte array {1} elements>)"
|
||||
return msg.format(repr(self.uuid), len(self.raw_data))
|
||||
|
||||
|
||||
def __str__(self):
|
||||
msg = '{0}\n'
|
||||
msg += ' UUID: {1}{2}\n'
|
||||
|
|
|
|||
|
|
@ -918,6 +918,42 @@ class TestRepr(unittest.TestCase):
|
|||
self.assertEqual(box.vendor_feature, newbox.vendor_feature)
|
||||
self.assertEqual(box.vendor_mask, newbox.vendor_mask)
|
||||
|
||||
@unittest.skipIf(sys.hexversion < 0x02070000, "Requires 2.7+")
|
||||
def test_uuid_box(self):
|
||||
"""Verify uuid repr method."""
|
||||
uuid_instance = uuid.UUID('00000000-0000-0000-0000-000000000000')
|
||||
data = b'0123456789'
|
||||
box = glymur.jp2box.UUIDBox(the_uuid=uuid_instance, raw_data=data)
|
||||
|
||||
# Since the raw_data parameter is a sequence of bytes which could be
|
||||
# quite long, don't bother trying to make it conform to eval(repr()).
|
||||
regexp = "glymur.jp2box.UUIDBox\("
|
||||
regexp += "the_uuid=UUID\('00000000-0000-0000-0000-000000000000'\),\s"
|
||||
regexp += "raw_data=<byte\sarray\s10\selements>\)"
|
||||
|
||||
if sys.hexversion < 0x03000000:
|
||||
self.assertRegexpMatches(repr(box), regexp)
|
||||
else:
|
||||
self.assertRegex(repr(box), regexp)
|
||||
|
||||
@unittest.skipIf(sys.hexversion < 0x02070000, "Requires 2.7+")
|
||||
def test_contiguous_codestream_box(self):
|
||||
"""Verify contiguous codestream box repr method."""
|
||||
jp2file = glymur.data.nemo()
|
||||
jp2 = Jp2k(jp2file)
|
||||
box = jp2.box[-1]
|
||||
|
||||
# Difficult to eval(repr()) this, so just match the general pattern.
|
||||
regexp = "glymur.jp2box.ContiguousCodeStreamBox"
|
||||
regexp += "\(main_header=<glymur.codestream.Codestream\sobject\s"
|
||||
regexp += "at\s0x([a-f0-9]*)>\)"
|
||||
|
||||
if sys.hexversion < 0x03000000:
|
||||
self.assertRegexpMatches(repr(box), regexp)
|
||||
else:
|
||||
self.assertRegex(repr(box), regexp)
|
||||
|
||||
|
||||
|
||||
class TestJpxBoxes(unittest.TestCase):
|
||||
"""Tests for JPX boxes."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue