From e23fe00ff2a8fb3c796bfcc600dcc58dba902fa5 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 23 Jan 2017 20:39:05 +0000 Subject: Move target URI handling out of zips module --- mammoth/docx/body_xml.py | 2 +- mammoth/docx/uris.py | 5 +++++ mammoth/zips.py | 7 ------- tests/docx/uris_tests.py | 19 +++++++++++++++++++ tests/zips_tests.py | 19 ------------------- 5 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 mammoth/docx/uris.py create mode 100644 tests/docx/uris_tests.py delete mode 100644 tests/zips_tests.py diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py index 433d5a2..6c2c501 100644 --- a/mammoth/docx/body_xml.py +++ b/mammoth/docx/body_xml.py @@ -3,9 +3,9 @@ import contextlib from .. import documents from .. import results from .. import lists -from ..zips import uri_to_zip_entry_name from .xmlparser import node_types, XmlElement from .styles_xml import Styles +from .uris import uri_to_zip_entry_name def reader(numbering=None, diff --git a/mammoth/docx/uris.py b/mammoth/docx/uris.py new file mode 100644 index 0000000..59f3ffe --- /dev/null +++ b/mammoth/docx/uris.py @@ -0,0 +1,5 @@ +def uri_to_zip_entry_name(base, uri): + if uri.startswith("/"): + return uri[1:] + else: + return base + "/" + uri diff --git a/mammoth/zips.py b/mammoth/zips.py index 8e09924..432be5d 100644 --- a/mammoth/zips.py +++ b/mammoth/zips.py @@ -54,10 +54,3 @@ def update_zip(fileobj, files): fileobj.seek(0) destination_fileobj.seek(0) shutil.copyfileobj(destination_fileobj, fileobj) - - -def uri_to_zip_entry_name(base, uri): - if uri.startswith("/"): - return uri[1:] - else: - return base + "/" + uri diff --git a/tests/docx/uris_tests.py b/tests/docx/uris_tests.py new file mode 100644 index 0000000..6b9c264 --- /dev/null +++ b/tests/docx/uris_tests.py @@ -0,0 +1,19 @@ +from nose.tools import istest, assert_equal + +from mammoth.docx.uris import uri_to_zip_entry_name + + +@istest +def when_path_does_not_have_leading_slash_then_path_is_resolved_relative_to_base(): + assert_equal( + "one/two/three/four", + uri_to_zip_entry_name("one/two", "three/four"), + ) + + +@istest +def when_path_has_leading_slash_then_base_is_ignored(): + assert_equal( + "three/four", + uri_to_zip_entry_name("one/two", "/three/four"), + ) diff --git a/tests/zips_tests.py b/tests/zips_tests.py deleted file mode 100644 index bef9895..0000000 --- a/tests/zips_tests.py +++ /dev/null @@ -1,19 +0,0 @@ -from nose.tools import istest, assert_equal - -from mammoth.zips import uri_to_zip_entry_name - - -@istest -def when_path_does_not_have_leading_slash_then_path_is_resolved_relative_to_base(): - assert_equal( - "one/two/three/four", - uri_to_zip_entry_name("one/two", "three/four"), - ) - - -@istest -def when_path_has_leading_slash_then_base_is_ignored(): - assert_equal( - "three/four", - uri_to_zip_entry_name("one/two", "/three/four"), - ) -- cgit v1.2.3