Skip to content

Commit 44837e4

Browse files
author
Steve Canny
committed
add ZipPkgReader.blob_for()
1 parent db5a748 commit 44837e4

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

opc/phys_pkg.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ def __init__(self, pkg_file):
3232
super(ZipPkgReader, self).__init__()
3333
self._zipf = ZipFile(pkg_file, 'r')
3434

35+
def blob_for(self, pack_uri):
36+
"""
37+
Return blob corresponding to *pack_uri*. Raises |ValueError| if no
38+
matching member is present in zip archive.
39+
"""
40+
return self._zipf.read(pack_uri.membername)
41+
3542
def close(self):
3643
"""
3744
Close the zip archive, releasing any resources it is using.

tests/test_phys_pkg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ def it_can_be_closed(self, ZipFile_):
6767
# verify -----------------------
6868
zipf.close.assert_called_once_with()
6969

70+
def it_can_retrieve_the_blob_for_a_pack_uri(self, phys_reader):
71+
pack_uri = PackURI('/ppt/presentation.xml')
72+
blob = phys_reader.blob_for(pack_uri)
73+
sha1 = hashlib.sha1(blob).hexdigest()
74+
assert sha1 == 'efa7bee0ac72464903a67a6744c1169035d52a54'
75+
7076
def it_has_the_content_types_xml(self, phys_reader):
7177
sha1 = hashlib.sha1(phys_reader.content_types_xml).hexdigest()
7278
assert sha1 == '9604a4fb3bf9626f5ad59a4e82029b3a501f106a'

0 commit comments

Comments
 (0)