Permalink
Browse files

refs #2: no more dict comprehensions (Not supported in 2.6)

  • Loading branch information...
jlward committed Mar 22, 2013
1 parent 9f027e6 commit 26fadbcc9244ca42e965b324914202b3368ae3c2
Showing with 16 additions and 3 deletions.
  1. +16 −3 pydocx/DocxParser.py
View
@@ -7,24 +7,32 @@
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("NewParser")
+
def remove_namespaces(document):
root = ElementTree.fromstring(document)
for child in root.iter():
child.tag = child.tag.split("}")[1]
- child.attrib = {k.split("}")[1]:v for k,v in child.attrib.items()}
+ child.attrib = dict(
+ (k.split("}")[1], v)
+ for k, v in child.attrib.items()
+ )
return ElementTree.tostring(root)
# Add some helper functions to Element to make it slightly more readable
+
def has_child(self, tag):
return True if self.find(tag) is not None else False
+
def has_child_all(self, tag):
return True if self.find('.//' + tag) is not None else False
+
def find_all(self, tag):
return self.find('.//' + tag)
+
def findall_all(self, tag):
return self.findall('.//' + tag)
@@ -164,8 +172,13 @@ def parse_lists(self, el):
def parse(self, el):
parsed = ''
if not self.ignore_current:
- tmp_d = {tmpel.tag:i for i, tmpel in enumerate(el.parent_list)}
- if 'tbl' in tmp_d and el.parent_list[tmp_d['tbl']] not in self.tables_seen:
+ tmp_d = dict(
+ (tmpel.tag, i)
+ for i, tmpel in enumerate(el.parent_list)
+ )
+ if (
+ 'tbl' in tmp_d and
+ el.parent_list[tmp_d['tbl']] not in self.tables_seen):
self.ignore_current = True
self.tables_seen.append(el.parent_list[tmp_d['tbl']])
tmpout = self.table(self.parse(el.parent_list[tmp_d['tbl']]))

0 comments on commit 26fadbc

Please sign in to comment.