Skip to content

Commit ed80ca6

Browse files
author
Steve Canny
committed
add ZipPkgReader.rels_xml_for()
1 parent ad52d8d commit ed80ca6

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

opc/phys_pkg.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,14 @@ def content_types_xml(self):
4444
Return the `[Content_Types].xml` blob from the zip package.
4545
"""
4646
return self._zipf.read(self._CONTENT_TYPES_MEMBERNAME)
47+
48+
def rels_xml_for(self, source_uri):
49+
"""
50+
Return rels item XML for source with *source_uri* or None if no rels
51+
item is present.
52+
"""
53+
try:
54+
rels_xml = self._zipf.read(source_uri.rels_uri.membername)
55+
except KeyError:
56+
rels_xml = None
57+
return rels_xml

tests/test_phys_pkg.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import hashlib
1313

14+
from opc.packuri import PACKAGE_URI, PackURI
1415
from opc.phys_pkg import PhysPkgReader, ZipPkgReader
1516

1617
import pytest
@@ -69,3 +70,13 @@ def it_can_be_closed(self, ZipFile_):
6970
def it_has_the_content_types_xml(self, phys_reader):
7071
sha1 = hashlib.sha1(phys_reader.content_types_xml).hexdigest()
7172
assert sha1 == '9604a4fb3bf9626f5ad59a4e82029b3a501f106a'
73+
74+
def it_can_retrieve_rels_xml_for_source_uri(self, phys_reader):
75+
rels_xml = phys_reader.rels_xml_for(PACKAGE_URI)
76+
sha1 = hashlib.sha1(rels_xml).hexdigest()
77+
assert sha1 == 'e31451d4bbe7d24adbe21454b8e9fdae92f50de5'
78+
79+
def it_returns_none_when_part_has_no_rels_xml(self, phys_reader):
80+
partname = PackURI('/ppt/viewProps.xml')
81+
rels_xml = phys_reader.rels_xml_for(partname)
82+
assert rels_xml is None

0 commit comments

Comments
 (0)