Permalink
Browse files

refs #2: fixed python 2.6

  • Loading branch information...
1 parent 6ffb48e commit 82ae6efdd63d061e484f18f9224150076b7984b9 @jlward committed Mar 22, 2013
Showing with 23 additions and 12 deletions.
  1. +17 −9 pydocx/DocxParser.py
  2. +6 −3 pydocx/parsers/Docx2Html.py
View
@@ -2,15 +2,15 @@
import zipfile
import logging
import xml.etree.ElementTree as ElementTree
-from xml.etree.ElementTree import Element
+from xml.etree.ElementTree import _ElementInterface
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("NewParser")
def remove_namespaces(document):
root = ElementTree.fromstring(document)
- for child in root.iter():
+ for child in el_iter(root):
child.tag = child.tag.split("}")[1]
child.attrib = dict(
(k.split("}")[1], v)
@@ -36,12 +36,20 @@ def find_all(self, tag):
def findall_all(self, tag):
return self.findall('.//' + tag)
-setattr(Element, 'has_child', has_child)
-setattr(Element, 'has_child_all', has_child_all)
-setattr(Element, 'find_all', find_all)
-setattr(Element, 'findall_all', findall_all)
-setattr(Element, 'parent', None)
-setattr(Element, 'parent_list', [])
+
+def el_iter(el):
+ try:
+ return el.iter()
+ except AttributeError:
+ return el.findall('.//*')
+
+
+setattr(_ElementInterface, 'has_child', has_child)
+setattr(_ElementInterface, 'has_child_all', has_child_all)
+setattr(_ElementInterface, 'find_all', find_all)
+setattr(_ElementInterface, 'findall_all', findall_all)
+setattr(_ElementInterface, 'parent', None)
+setattr(_ElementInterface, 'parent_list', [])
# End helpers
@@ -290,7 +298,7 @@ def get_list_style(self, numval):
)
for info in style_information:
if info.attrib['abstractNumId'] == abstractid:
- for i in info.iter():
+ for i in el_iter(info):
if i.find('numFmt') is not None:
return i.find('numFmt').attrib
@@ -14,8 +14,8 @@ def parsed(self):
'<html><head><style>.insert{{color:red}}.delete'
'{{color:red; text-decoration:line-through}}.center'
'{{text-align:center}}.right{{text-align:right}}'
- '</style></head><body>{}</body></html>'
- ).format(self._parsed)
+ '</style></head><body>{content}</body></html>'
+ ).format(content=self._parsed)
def escape(self, text):
return xml.sax.saxutils.quoteattr(text)[1:-1]
@@ -80,4 +80,7 @@ def right_justify(self, text):
return "<div class = 'right'>" + text + '</div>'
def indent(self, text, right, left, firstLine):
- return "<div style = 'margin-left:{}pt'>{}</div>".format(left, text)
+ return "<div style = 'margin-left:{left}pt'>{text}</div>".format(
+ left=left,
+ text=text,
+ )

0 comments on commit 82ae6ef

Please sign in to comment.