Merge branch 'devel' into issue130
This commit is contained in:
commit
55be4b2cf1
3 changed files with 63 additions and 9 deletions
|
|
@ -98,10 +98,36 @@ class Jp2kBox(object):
|
||||||
for box in self.box:
|
for box in self.box:
|
||||||
boxstr = str(box)
|
boxstr = str(box)
|
||||||
# Indent the child boxes to make the association clear.
|
# Indent the child boxes to make the association clear.
|
||||||
msg += '\n' + textwrap.indent(boxstr, ' ')
|
msg += '\n' + self._indent(boxstr)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
def _indent(self, textstr, indent_level=4):
|
||||||
|
"""
|
||||||
|
Indent a string.
|
||||||
|
|
||||||
|
Textwrap's indent method only exists for 3.3 or above. In 2.7 we have
|
||||||
|
to fake it.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
textstring : str
|
||||||
|
String to be indented.
|
||||||
|
indent_level : str
|
||||||
|
Number of spaces of indentation to add.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
indented_string : str
|
||||||
|
Possibly multi-line string indented a certain bit.
|
||||||
|
"""
|
||||||
|
if sys.hexversion >= 0x03030000:
|
||||||
|
return textwrap.indent(textstr, ' ' * indent_level)
|
||||||
|
else:
|
||||||
|
lst = [(' ' * indent_level + x) for x in textstr.split('\n')]
|
||||||
|
return '\n'.join(lst)
|
||||||
|
|
||||||
|
|
||||||
def _write_superbox(self, fptr):
|
def _write_superbox(self, fptr):
|
||||||
"""Write a superbox.
|
"""Write a superbox.
|
||||||
|
|
||||||
|
|
@ -888,7 +914,7 @@ class ContiguousCodestreamBox(Jp2kBox):
|
||||||
|
|
||||||
msg += '\n Main header:'
|
msg += '\n Main header:'
|
||||||
for segment in self.main_header.segment:
|
for segment in self.main_header.segment:
|
||||||
msg += '\n' + textwrap.indent(str(segment), ' ')
|
msg += '\n' + self._indent(str(segment), indent_level=8)
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
@ -2563,7 +2589,7 @@ class XMLBox(Jp2kBox):
|
||||||
pretty_print=True).decode('utf-8')
|
pretty_print=True).decode('utf-8')
|
||||||
else:
|
else:
|
||||||
xmlstring = 'None'
|
xmlstring = 'None'
|
||||||
msg += textwrap.indent(xmlstring, ' ')
|
msg += self._indent(xmlstring)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def write(self, fptr):
|
def write(self, fptr):
|
||||||
|
|
@ -2972,7 +2998,7 @@ class UUIDBox(Jp2kBox):
|
||||||
encoding='utf-8',
|
encoding='utf-8',
|
||||||
pretty_print=True).decode('utf-8')
|
pretty_print=True).decode('utf-8')
|
||||||
# indent it a bit
|
# indent it a bit
|
||||||
xmlstring = textwrap.indent(xmlstring.rstrip(), ' ')
|
xmlstring = self._indent(xmlstring.rstrip())
|
||||||
msg += line.format(xmlstring)
|
msg += line.format(xmlstring)
|
||||||
elif self.uuid.bytes == b'JpgTiffExif->JP2':
|
elif self.uuid.bytes == b'JpgTiffExif->JP2':
|
||||||
msg += '\n UUID Data: {0}'.format(str(self.data))
|
msg += '\n UUID Data: {0}'.format(str(self.data))
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,32 @@ except:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def _indent(textstr):
|
||||||
|
"""
|
||||||
|
Indent a string.
|
||||||
|
|
||||||
|
Textwrap's indent method only exists for 3.3 or above. In 2.7 we have
|
||||||
|
to fake it.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
textstring : str
|
||||||
|
String to be indented.
|
||||||
|
indent_level : str
|
||||||
|
Number of spaces of indentation to add.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
indented_string : str
|
||||||
|
Possibly multi-line string indented a certain bit.
|
||||||
|
"""
|
||||||
|
if sys.hexversion >= 0x03030000:
|
||||||
|
return textwrap.indent(textstr, ' ')
|
||||||
|
else:
|
||||||
|
lst = [(' ' + x) for x in textstr.split('\n')]
|
||||||
|
return '\n'.join(lst)
|
||||||
|
|
||||||
|
|
||||||
def opj_data_file(relative_file_name):
|
def opj_data_file(relative_file_name):
|
||||||
"""Compact way of forming a full filename from OpenJPEG's test suite."""
|
"""Compact way of forming a full filename from OpenJPEG's test suite."""
|
||||||
jfile = os.path.join(OPJ_DATA_ROOT, relative_file_name)
|
jfile = os.path.join(OPJ_DATA_ROOT, relative_file_name)
|
||||||
|
|
@ -270,12 +296,12 @@ nemo_xmp = """<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
|
||||||
nemo_xmp_box = """UUID Box (uuid) @ (77, 3146)
|
nemo_xmp_box = """UUID Box (uuid) @ (77, 3146)
|
||||||
UUID: be7acfcb-97a9-42e8-9c71-999491e3afac (XMP)
|
UUID: be7acfcb-97a9-42e8-9c71-999491e3afac (XMP)
|
||||||
UUID Data:
|
UUID Data:
|
||||||
{0}""".format(textwrap.indent(nemo_xmp, ' '))
|
{0}""".format(_indent(nemo_xmp))
|
||||||
|
|
||||||
nemo_xmp_box = """UUID Box (uuid) @ (77, 3146)
|
nemo_xmp_box = """UUID Box (uuid) @ (77, 3146)
|
||||||
UUID: be7acfcb-97a9-42e8-9c71-999491e3afac (XMP)
|
UUID: be7acfcb-97a9-42e8-9c71-999491e3afac (XMP)
|
||||||
UUID Data:
|
UUID Data:
|
||||||
{0}""".format(textwrap.indent(nemo_xmp, ' '))
|
{0}""".format(_indent(nemo_xmp))
|
||||||
|
|
||||||
SimpleRDF = """<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
|
SimpleRDF = """<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
|
||||||
<rdf:Description rdf:about='Test:XMPCoreCoverage/kSimpleRDF'
|
<rdf:Description rdf:about='Test:XMPCoreCoverage/kSimpleRDF'
|
||||||
|
|
@ -419,7 +445,7 @@ Contiguous Codestream Box (jp2c) @ (3223, 1132296)
|
||||||
Step size: [(0, 8), (0, 9), (0, 9), (0, 10)]
|
Step size: [(0, 8), (0, 9), (0, 9), (0, 10)]
|
||||||
CME marker segment @ (3305, 37)
|
CME marker segment @ (3305, 37)
|
||||||
"Created by OpenJPEG version 2.0.0"'''
|
"Created by OpenJPEG version 2.0.0"'''
|
||||||
nemo_dump_full = dump.format(textwrap.indent(nemo_xmp, ' '))
|
nemo_dump_full = dump.format(_indent(nemo_xmp))
|
||||||
|
|
||||||
nemo_dump_short = r"""JPEG 2000 Signature Box (jP ) @ (0, 12)
|
nemo_dump_short = r"""JPEG 2000 Signature Box (jP ) @ (0, 12)
|
||||||
File Type Box (ftyp) @ (12, 20)
|
File Type Box (ftyp) @ (12, 20)
|
||||||
|
|
@ -506,7 +532,7 @@ UUID Box (uuid) @ (77, 3146)
|
||||||
UUID Data:
|
UUID Data:
|
||||||
{0}
|
{0}
|
||||||
Contiguous Codestream Box (jp2c) @ (3223, 1132296)"""
|
Contiguous Codestream Box (jp2c) @ (3223, 1132296)"""
|
||||||
nemo_dump_no_codestream = dump.format(textwrap.indent(nemo_xmp, ' '))
|
nemo_dump_no_codestream = dump.format(_indent(nemo_xmp))
|
||||||
|
|
||||||
nemo_dump_no_codestream_no_xml = r"""JPEG 2000 Signature Box (jP ) @ (0, 12)
|
nemo_dump_no_codestream_no_xml = r"""JPEG 2000 Signature Box (jP ) @ (0, 12)
|
||||||
Signature: 0d0a870a
|
Signature: 0d0a870a
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,9 @@ class TestPrinting(unittest.TestCase):
|
||||||
lst = actual.split('\n')
|
lst = actual.split('\n')
|
||||||
lst = lst[1:]
|
lst = lst[1:]
|
||||||
actual = '\n'.join(lst)
|
actual = '\n'.join(lst)
|
||||||
self.assertEqual(actual, fixtures.nemo_dump_no_xml)
|
expected = fixtures.nemo_dump_no_xml
|
||||||
|
self.maxDiff = None
|
||||||
|
self.assertEqual(actual, expected)
|
||||||
|
|
||||||
def test_printoptions_short(self):
|
def test_printoptions_short(self):
|
||||||
"""Verify printed output when short=True"""
|
"""Verify printed output when short=True"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue