summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-07-18 04:40:10 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-07-18 04:40:10 +0200
commitdeb558cfb82718cd0a719e98c1e78a67f444910e (patch)
tree6753cdc68496c815ee7a1b664c9d138fe7b26a70
parent07182d8f114eb87e9e1ae958df6c46d7dbac3b56 (diff)
downloadIshtar-deb558cfb82718cd0a719e98c1e78a67f444910e.tar.bz2
Ishtar-deb558cfb82718cd0a719e98c1e78a67f444910e.zip
ooo_replace: register opendocument namespace (refs #3654)
-rw-r--r--old/ooo_replace.py45
1 files changed, 38 insertions, 7 deletions
diff --git a/old/ooo_replace.py b/old/ooo_replace.py
index 18c4e1878..cff5c2acc 100644
--- a/old/ooo_replace.py
+++ b/old/ooo_replace.py
@@ -21,7 +21,7 @@ import locale
import re
from zipfile import ZipFile, ZIP_DEFLATED
from cStringIO import StringIO
-from xml.etree.cElementTree import ElementTree, fromstring
+from xml.etree.cElementTree import ElementTree, fromstring, register_namespace
from django.conf import settings
from ooo_translation import ooo_translation
@@ -38,7 +38,36 @@ def translate_context(context, locale):
new_context[new_key] = context[k]
return new_context
-OOO_NS = "{urn:oasis:names:tc:opendocument:xmlns:text:1.0}"
+OOO_MAIN_NS = "{urn:oasis:names:tc:opendocument:xmlns:text:1.0}"
+
+OOO_NS = {
+ "office": "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
+ "style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
+ "text": "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
+ "table": "urn:oasis:names:tc:opendocument:xmlns:table:1.0",
+ "draw": "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0",
+ "fo": "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
+ "xlink": "http://www.w3.org/1999/xlink",
+ "dc": "http://purl.org/dc/elements/1.1/",
+ "meta": "urn:oasis:names:tc:opendocument:xmlns:meta:1.0",
+ "number": "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0",
+ "svg": "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0",
+ "chart": "urn:oasis:names:tc:opendocument:xmlns:chart:1.0",
+ "dr3d": "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0",
+ "math": "http://www.w3.org/1998/Math/MathML",
+ "form": "urn:oasis:names:tc:opendocument:xmlns:form:1.0",
+ "script": "urn:oasis:names:tc:opendocument:xmlns:script:1.0",
+ "ooo": "http://openoffice.org/2004/office",
+ "ooow": "http://openoffice.org/2004/writer",
+ "oooc": "http://openoffice.org/2004/calc",
+ "dom": "http://www.w3.org/2001/xml-events",
+ "rpt": "http://openoffice.org/2005/report",
+ "of": "urn:oasis:names:tc:opendocument:xmlns:of:1.2",
+ "xhtml": "http://www.w3.org/1999/xhtml",
+ "grddl": "http://www.w3.org/2003/g/data-view#",
+ "tableooo": "http://openoffice.org/2009/table",
+ "css3t": "http://www.w3.org/TR/css3-text/",
+}
def _set_value_from_formula(value, context, default_value):
@@ -159,8 +188,8 @@ def _ooo_replace(content, context, missing_keys, default_value=''):
# regular ooo parsing
for xp in ('variable-set', 'variable-get'):
- for p in content.findall(".//" + OOO_NS + xp):
- name = p.get(OOO_NS + "name")
+ for p in content.findall(".//" + OOO_MAIN_NS + xp):
+ name = p.get(OOO_MAIN_NS + "name")
if name in context:
value = context[name]
p.text = _format_value(value, default_value)
@@ -168,11 +197,11 @@ def _ooo_replace(content, context, missing_keys, default_value=''):
if default_value is not None:
p.text = default_value
missing_keys.add(name)
- for p in content.findall(".//" + OOO_NS + "conditional-text"):
- condition = p.get(OOO_NS + "condition")
+ for p in content.findall(".//" + OOO_MAIN_NS + "conditional-text"):
+ condition = p.get(OOO_MAIN_NS + "condition")
res = 'true' if _parse_condition(condition, context, default_value) \
else 'false'
- value = p.get(OOO_NS + 'string-value-if-' + res)
+ value = p.get(OOO_MAIN_NS + 'string-value-if-' + res)
value = _format_value(value, default_value)
if value.strip() in context:
value = context[value.strip()]
@@ -192,6 +221,8 @@ def ooo_replace(infile, outfile, context, default_value=''):
values = {}
missing_keys = set()
+ for k in OOO_NS:
+ register_namespace(k, OOO_NS[k])
for xml_file in ('content.xml', 'styles.xml'):
content = ElementTree(fromstring(inzip.read(xml_file)))
values[xml_file] = _ooo_replace(content, context, missing_keys,