def test_getitem0(self): if self.OleStorage is None: logger.warning('%s: skipped', self.id()) return from hwp5.storage import is_storage, is_stream olestg = self.olestg self.assertTrue(is_storage(olestg)) #self.assertEquals('', olestg.path) docinfo = olestg['DocInfo'] self.assertTrue(is_stream(docinfo)) #self.assertEquals('DocInfo', docinfo.path) bodytext = olestg['BodyText'] self.assertTrue(is_storage(bodytext)) #self.assertEquals('BodyText', bodytext.path) section = bodytext['Section0'] self.assertTrue(is_stream(section)) #self.assertEquals('BodyText/Section0', section.path) f = section.open() try: data = f.read() self.assertEquals(1529, len(data)) finally: f.close() try: bodytext['nonexists'] self.fail('KeyError expected') except KeyError: pass
def test_getitem0(self): if self.OleStorage is None: logger.warning('%s: skipped', self.id()) return olestg = self.olestg self.assertTrue(is_storage(olestg)) # self.assertEqual('', olestg.path) docinfo = olestg['DocInfo'] self.assertTrue(is_stream(docinfo)) # self.assertEqual('DocInfo', docinfo.path) bodytext = olestg['BodyText'] self.assertTrue(is_storage(bodytext)) # self.assertEqual('BodyText', bodytext.path) section = bodytext['Section0'] self.assertTrue(is_stream(section)) # self.assertEqual('BodyText/Section0', section.path) f = section.open() try: data = f.read() self.assertEqual(1529, len(data)) finally: f.close() try: bodytext['nonexists'] self.fail('KeyError expected') except KeyError: pass
def test_getitem(self): if self.OleStorage is None: logger.warning('%s: skipped', self.id()) return from hwp5.storage import is_storage #from hwp5.storage.ole import OleStorage olestg = self.olestg try: olestg['non-exists'] self.fail('KeyError expected') except KeyError: pass fileheader = olestg['FileHeader'] self.assertTrue(hasattr(fileheader, 'open')) bindata = olestg['BinData'] self.assertTrue(is_storage(bindata)) #self.assertEquals('BinData', bindata.path) self.assertEquals(sorted(['BIN0002.jpg', 'BIN0002.png', 'BIN0003.png']), sorted(iter(bindata))) bin0002 = bindata['BIN0002.jpg'] self.assertTrue(hasattr(bin0002, 'open'))
def test_getitem(self): if self.OleStorage is None: logger.warning('%s: skipped', self.id()) return olestg = self.olestg try: olestg['non-exists'] self.fail('KeyError expected') except KeyError: pass fileheader = olestg['FileHeader'] self.assertTrue(hasattr(fileheader, 'open')) bindata = olestg['BinData'] self.assertTrue(is_storage(bindata)) # self.assertEqual('BinData', bindata.path) self.assertEqual(sorted(['BIN0002.jpg', 'BIN0002.png', 'BIN0003.png']), sorted(iter(bindata))) bin0002 = bindata['BIN0002.jpg'] self.assertTrue(hasattr(bin0002, 'open'))
def test_OleStorage(self): if self.OleStorage is None: logger.warning('%s: skipped', self.id()) return OleStorage = self.OleStorage olestg = OleStorage(self.hwp5file_path) self.assertTrue(is_storage(olestg)) self.assertTrue(isinstance(olestg, OleStorage)) nonolefile = self.get_fixture_file('nonole.txt') self.assertRaises(InvalidOleStorageError, OleStorage, nonolefile)
def test_getitem(self): stg = FS.CompressedStorage(self.olestg['BinData']) self.assertTrue(is_storage(stg)) item = stg['BIN0002.jpg'] self.assertTrue(is_stream(item)) f = item.open() try: data = f.read() self.assertEquals(b'\xff\xd8\xff\xe0', data[0:4]) self.assertEquals(15895, len(data)) finally: f.close()
def test_getitem(self): stg = FS.CompressedStorage(self.olestg['BinData']) self.assertTrue(is_storage(stg)) item = stg['BIN0002.jpg'] self.assertTrue(is_stream(item)) f = item.open() try: data = f.read() self.assertEqual(b'\xff\xd8\xff\xe0', data[0:4]) self.assertEqual(15895, len(data)) finally: f.close()
def __init__(self, stg): from hwp5.errors import InvalidOleStorageError from hwp5.errors import InvalidHwp5FileError from hwp5.storage import is_storage from hwp5.storage.ole import OleStorage if not is_storage(stg): try: stg = OleStorage(stg) except InvalidOleStorageError: raise InvalidHwp5FileError('Not an OLE2 Compound Binary File.') if not storage_is_hwp5file(stg): errormsg = 'Not an HWP Document format v5 storage.' raise InvalidHwp5FileError(errormsg) ItemConversionStorage.__init__(self, stg)
def test_getitem(self): from hwp5.storage import is_storage, is_stream stg = FS.CompressedStorage(self.olestg["BinData"]) self.assertTrue(is_storage(stg)) item = stg["BIN0002.jpg"] self.assertTrue(is_stream(item)) f = item.open() try: data = f.read() self.assertEquals("\xff\xd8\xff\xe0", data[0:4]) self.assertEquals(15895, len(data)) finally: f.close()