aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/docx/__init__.py15
-rw-r--r--mammoth/results.py18
2 files changed, 25 insertions, 8 deletions
diff --git a/mammoth/docx/__init__.py b/mammoth/docx/__init__.py
index 58bfa50..0579d09 100644
--- a/mammoth/docx/__init__.py
+++ b/mammoth/docx/__init__.py
@@ -29,11 +29,16 @@ def read(fileobj, external_file_access=False):
external_file_access=external_file_access,
)
- return results.combine([
- _read_notes(read_part_with_body, part_paths),
- _read_comments(read_part_with_body, part_paths),
- ]).bind(lambda referents:
- _read_document(read_part_with_body, notes=referents[0], comments=referents[1], part_paths=part_paths)
+ return results.combine_obj(
+ notes=_read_notes(read_part_with_body, part_paths),
+ comments=_read_comments(read_part_with_body, part_paths),
+ ).bind(lambda referents:
+ _read_document(
+ read_part_with_body,
+ notes=referents.notes,
+ comments=referents.comments,
+ part_paths=part_paths,
+ )
)
diff --git a/mammoth/results.py b/mammoth/results.py
index 59c3a42..b003d80 100644
--- a/mammoth/results.py
+++ b/mammoth/results.py
@@ -1,4 +1,5 @@
import collections
+import types
from .lists import unique
@@ -7,10 +8,10 @@ class Result(object):
def __init__(self, value, messages):
self.value = value
self.messages = unique(messages)
-
+
def map(self, func):
return Result(func(self.value), self.messages)
-
+
def bind(self, func):
result = func(self.value)
return Result(result.value, self.messages + result.messages)
@@ -34,9 +35,20 @@ def combine(results):
values.append(result.value)
for message in result.messages:
messages.append(message)
-
+
return Result(values, messages)
+def combine_obj(**results):
+ values = {}
+ messages = []
+ for key, result in results.items():
+ values[key] = result.value
+ for message in result.messages:
+ messages.append(message)
+
+ return Result(types.SimpleNamespace(**values), messages)
+
+
def map(func, *args):
return combine(args).map(lambda values: func(*values))