aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/conversion.py4
-rw-r--r--mammoth/html_generation.py9
2 files changed, 9 insertions, 4 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py
index 87e1bf9..b3b41d0 100644
--- a/mammoth/conversion.py
+++ b/mammoth/conversion.py
@@ -74,9 +74,7 @@ class DocumentConverter(object):
def _convert_image(self, image, html_generator):
with image.open() as image_bytes:
- output = io.BytesIO()
- base64.encode(image_bytes, output)
- encoded_src = output.getvalue().rstrip("\n")
+ encoded_src = base64.b64encode(image_bytes.read()).decode("ascii")
attributes = {
"src": "data:{0};base64,{1}".format(image.content_type, encoded_src)
diff --git a/mammoth/html_generation.py b/mammoth/html_generation.py
index 563e2d6..9716ac2 100644
--- a/mammoth/html_generation.py
+++ b/mammoth/html_generation.py
@@ -1,4 +1,5 @@
import cgi
+import sys
class HtmlGenerator(object):
@@ -67,7 +68,7 @@ def _generate_attribute_string(attributes):
else:
return "".join(
' {0}="{1}"'.format(key, _escape_html(value))
- for key, value in attributes.iteritems()
+ for key, value in _iteritems(attributes)
)
@@ -101,3 +102,9 @@ def _is_element_match(generated_element, path_element):
def _generate_class_attribute(path_element):
return " ".join(path_element.class_names)
+
+
+if sys.version_info[0] == 2:
+ _iteritems = lambda x: x.iteritems()
+else:
+ _iteritems = lambda x: x.items()