Commit fc016de0 authored by Vincent Pelletier's avatar Vincent Pelletier

Simplify code a bit.

parent 55364f3d
...@@ -269,7 +269,7 @@ class OOoParser(Implicit): ...@@ -269,7 +269,7 @@ class OOoParser(Implicit):
""" """
Return a dictionnary of all pictures in the document Return a dictionnary of all pictures in the document
""" """
if len(self.pictures) <= 0: if not self.pictures:
for file_name in self.oo_files: for file_name in self.oo_files:
raw_data = self.oo_files[file_name] raw_data = self.oo_files[file_name]
pict_type = imghdr.what(None, raw_data) pict_type = imghdr.what(None, raw_data)
...@@ -498,13 +498,7 @@ class OOoParser(Implicit): ...@@ -498,13 +498,7 @@ class OOoParser(Implicit):
""" """
Get table dimension as dictionnary contain both height and width Get table dimension as dictionnary contain both height and width
""" """
max_cols = 0 return { 'width' : max(len(x) for x in table)
for line_index in range(len(table)):
line = table[line_index]
if len(line) > max_cols:
max_cols = len(line)
return { 'width' : max_cols
, 'height': len(table) , 'height': len(table)
} }
...@@ -512,11 +506,9 @@ class OOoParser(Implicit): ...@@ -512,11 +506,9 @@ class OOoParser(Implicit):
""" """
Add necessary cells and lines to obtain given bounds Add necessary cells and lines to obtain given bounds
""" """
while height > len(table): table += [[]] * (len(table) - height)
table.append([]) for line in table:
for line in range(height): line += [None] * (len(line) - width)
while width > len(table[line]):
table[line].append(None)
return table return table
def _getTableListUnion(self, list1, list2): def _getTableListUnion(self, list1, list2):
...@@ -526,10 +518,10 @@ class OOoParser(Implicit): ...@@ -526,10 +518,10 @@ class OOoParser(Implicit):
several embedded spreadsheets with the same id. This explain the several embedded spreadsheets with the same id. This explain the
use of random suffix in such extreme case. use of random suffix in such extreme case.
""" """
for list2_key in list2.keys(): for list2_key in list2:
# Generate a new table ID if needed # Generate a new table ID if needed
new_key = list2_key new_key = list2_key
while new_key in list1.keys(): while new_key in list1:
new_key = list2_key + '_' + str(random.randint(1000,9999)) new_key = list2_key + '_' + str(random.randint(1000,9999))
list1[new_key] = list2[list2_key] list1[new_key] = list2[list2_key]
return list1 return list1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment