From ac8a3c933a70c2d9aa179216f9ccfd2373c39c1b Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 21 Jan 2015 17:44:59 +0000 Subject: Rename modules from footnotes to notes --- mammoth/docx/__init__.py | 2 +- mammoth/docx/footnotes_xml.py | 29 ----------------------------- mammoth/docx/notes_xml.py | 29 +++++++++++++++++++++++++++++ tests/docx/document_xml_tests.py | 2 +- tests/docx/footnotes_xml_tests.py | 34 ---------------------------------- tests/docx/notes_xml_tests.py | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 65 insertions(+), 65 deletions(-) delete mode 100644 mammoth/docx/footnotes_xml.py create mode 100644 mammoth/docx/notes_xml.py delete mode 100644 tests/docx/footnotes_xml_tests.py create mode 100644 tests/docx/notes_xml_tests.py diff --git a/mammoth/docx/__init__.py b/mammoth/docx/__init__.py index 2c3e780..9a00dd5 100644 --- a/mammoth/docx/__init__.py +++ b/mammoth/docx/__init__.py @@ -7,7 +7,7 @@ from .content_types_xml import read_content_types_xml_element from .relationships_xml import read_relationships_xml_element from .numbering_xml import read_numbering_xml_element, Numbering from .styles_xml import read_styles_xml_element -from .footnotes_xml import read_footnotes_xml_element +from .notes_xml import read_footnotes_xml_element _namespaces = [ diff --git a/mammoth/docx/footnotes_xml.py b/mammoth/docx/footnotes_xml.py deleted file mode 100644 index c477553..0000000 --- a/mammoth/docx/footnotes_xml.py +++ /dev/null @@ -1,29 +0,0 @@ -from .. import lists - - -def create_reader(note_type): - def read_notes_xml_element(element): - note_elements = lists.filter( - _is_note_element, - element.find_children("w:" + note_type), - ) - return lists.map(_read_note_element, note_elements) - - - def _is_note_element(element): - return element.attributes.get("w:type") not in ["continuationSeparator", "separator"] - - - def _read_note_element(element): - return NoteElement(note_type, element.attributes["w:id"], element.children) - - return read_notes_xml_element - -class NoteElement(object): - def __init__(self, note_type, id, body): - self.note_type = note_type - self.id = id - self.body = body - - -read_footnotes_xml_element = create_reader("footnote") diff --git a/mammoth/docx/notes_xml.py b/mammoth/docx/notes_xml.py new file mode 100644 index 0000000..c477553 --- /dev/null +++ b/mammoth/docx/notes_xml.py @@ -0,0 +1,29 @@ +from .. import lists + + +def create_reader(note_type): + def read_notes_xml_element(element): + note_elements = lists.filter( + _is_note_element, + element.find_children("w:" + note_type), + ) + return lists.map(_read_note_element, note_elements) + + + def _is_note_element(element): + return element.attributes.get("w:type") not in ["continuationSeparator", "separator"] + + + def _read_note_element(element): + return NoteElement(note_type, element.attributes["w:id"], element.children) + + return read_notes_xml_element + +class NoteElement(object): + def __init__(self, note_type, id, body): + self.note_type = note_type + self.id = id + self.body = body + + +read_footnotes_xml_element = create_reader("footnote") diff --git a/tests/docx/document_xml_tests.py b/tests/docx/document_xml_tests.py index 2cb13c7..8e2cb8d 100644 --- a/tests/docx/document_xml_tests.py +++ b/tests/docx/document_xml_tests.py @@ -9,7 +9,7 @@ from mammoth.docx.document_xml import read_document_xml_element from mammoth.docx.numbering_xml import Numbering from mammoth.docx.relationships_xml import Relationships, Relationship from mammoth.docx.styles_xml import Styles, Style -from mammoth.docx.footnotes_xml import NoteElement +from mammoth.docx.notes_xml import NoteElement @istest diff --git a/tests/docx/footnotes_xml_tests.py b/tests/docx/footnotes_xml_tests.py deleted file mode 100644 index 645f3d0..0000000 --- a/tests/docx/footnotes_xml_tests.py +++ /dev/null @@ -1,34 +0,0 @@ -from nose.tools import istest, assert_equal - -from mammoth.docx.xmlparser import element as xml_element -from mammoth.docx.footnotes_xml import read_footnotes_xml_element - - -@istest -def id_and_body_of_footnote_are_read(): - footnote_body = [xml_element("w:p")] - footnotes = read_footnotes_xml_element(xml_element("w:footnotes", {}, [ - xml_element("w:footnote", {"w:id": "1"}, footnote_body), - ])) - assert_equal(1, len(footnotes)) - assert footnote_body is footnotes[0].body - assert_equal("1", footnotes[0].id) - - -@istest -def continuation_separator_is_ignored(): - _assert_footnote_type_is_ignored("continuationSeparator") - - -@istest -def separator_is_ignored(): - _assert_footnote_type_is_ignored("separator") - - -def _assert_footnote_type_is_ignored(footnote_type): - footnote_body = [xml_element("w:p")] - footnotes = read_footnotes_xml_element(xml_element("w:footnotes", {}, [ - xml_element("w:footnote", {"w:id": "1", "w:type": footnote_type}, footnote_body), - ])) - assert_equal(0, len(footnotes)) - diff --git a/tests/docx/notes_xml_tests.py b/tests/docx/notes_xml_tests.py new file mode 100644 index 0000000..90de8f8 --- /dev/null +++ b/tests/docx/notes_xml_tests.py @@ -0,0 +1,34 @@ +from nose.tools import istest, assert_equal + +from mammoth.docx.xmlparser import element as xml_element +from mammoth.docx.notes_xml import read_footnotes_xml_element + + +@istest +def id_and_body_of_footnote_are_read(): + footnote_body = [xml_element("w:p")] + footnotes = read_footnotes_xml_element(xml_element("w:footnotes", {}, [ + xml_element("w:footnote", {"w:id": "1"}, footnote_body), + ])) + assert_equal(1, len(footnotes)) + assert footnote_body is footnotes[0].body + assert_equal("1", footnotes[0].id) + + +@istest +def continuation_separator_is_ignored(): + _assert_footnote_type_is_ignored("continuationSeparator") + + +@istest +def separator_is_ignored(): + _assert_footnote_type_is_ignored("separator") + + +def _assert_footnote_type_is_ignored(footnote_type): + footnote_body = [xml_element("w:p")] + footnotes = read_footnotes_xml_element(xml_element("w:footnotes", {}, [ + xml_element("w:footnote", {"w:id": "1", "w:type": footnote_type}, footnote_body), + ])) + assert_equal(0, len(footnotes)) + -- cgit v1.2.3