Skip to content

Commit 8a3cab4

Browse files
author
Steve Canny
committed
add PackURI.from_rel_ref()
1 parent 328f922 commit 8a3cab4

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

opc/packuri.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ def __new__(cls, pack_uri_str):
2626
raise ValueError(tmpl % pack_uri_str)
2727
return str.__new__(cls, pack_uri_str)
2828

29+
@staticmethod
30+
def from_rel_ref(baseURI, relative_ref):
31+
"""
32+
Return a |PackURI| instance containing the absolute pack URI formed by
33+
translating *relative_ref* onto *baseURI*.
34+
"""
35+
joined_uri = posixpath.join(baseURI, relative_ref)
36+
abs_uri = posixpath.abspath(joined_uri)
37+
return PackURI(abs_uri)
38+
2939
@property
3040
def baseURI(self):
3141
"""

tests/test_packuri.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def cases(self, expected_values):
3232
pack_uris = [PackURI(uri_str) for uri_str in uri_str_cases]
3333
return zip(pack_uris, expected_values)
3434

35+
def it_can_construct_from_relative_ref(self):
36+
baseURI = '/ppt/slides'
37+
relative_ref = '../slideLayouts/slideLayout1.xml'
38+
pack_uri = PackURI.from_rel_ref(baseURI, relative_ref)
39+
assert pack_uri == '/ppt/slideLayouts/slideLayout1.xml'
40+
3541
def it_should_raise_on_construct_with_bad_pack_uri_str(self):
3642
with pytest.raises(ValueError):
3743
PackURI('foobar')

0 commit comments

Comments
 (0)