X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/35db0410eafcdcd3bd91caeb6711bcdc20df4c4e..95757b7ab8ad52783347c645dd3bdb37d09740e2:/forum_modules/exporter/exporter.py diff --git a/forum_modules/exporter/exporter.py b/forum_modules/exporter/exporter.py index f23538e..e266858 100644 --- a/forum_modules/exporter/exporter.py +++ b/forum_modules/exporter/exporter.py @@ -1,3 +1,5 @@ +from __future__ import with_statement + import os, tarfile, datetime, logging, re, ConfigParser, shutil, zipfile from django.core.cache import cache @@ -7,16 +9,34 @@ from forum.settings import APP_URL from forum.templatetags.extra_tags import diff_date import xml.etree.ElementTree from xml.etree import ElementTree as ET -from xml.etree.ElementTree import Comment, _encode, ProcessingInstruction, QName, fixtag, _escape_attrib, _escape_cdata +from xml.etree.ElementTree import Comment, _encode, ProcessingInstruction, QName, _escape_attrib, _escape_cdata, _namespace_map from forum import settings from django.conf import settings as djsettings import settings as selfsettings +import string -# Try to import the with statement try: - from __future__ import with_statement -except: - pass + from xml.etree.ElementTree import fixtag +except ImportError: + def fixtag(tag, namespaces): + # given a decorated tag (of the form {uri}tag), return prefixed + # tag and namespace declaration, if any + if isinstance(tag, QName): + tag = tag.text + namespace_uri, tag = string.split(tag[1:], "}", 1) + prefix = namespaces.get(namespace_uri) + if prefix is None: + prefix = _namespace_map.get(namespace_uri) + if prefix is None: + prefix = "ns%d" % len(namespaces) + namespaces[namespace_uri] = prefix + if prefix == "xml": + xmlns = None + else: + xmlns = ("xmlns:%s" % prefix, namespace_uri) + else: + xmlns = None + return "%s:%s" % (prefix, tag), xmlns CACHE_KEY = "%s_exporter_state" % APP_URL EXPORT_STEPS = [] @@ -97,8 +117,13 @@ def ET_Element_add_tag(el, tag_name, content = None, **attrs): if content: try: tag.text = unicode(content) - except: - tag.text = u'' + except Exception, e: + #logging.error('error converting unicode characters') + #import traceback + #logging.error(traceback.print_exc()) + + import string + tag.text = unicode("".join([c for c in content if c in string.printable])) for k, v in attrs.items(): tag.set(k, unicode(v)) @@ -414,7 +439,7 @@ def export_nodes(n, el, anon_data): el.add('author', n.author.id) el.add('date', make_date(n.added_at)) el.add('parent', n.parent and n.parent.id or "") - el.add('absparent', n.abs_parent and n.abs_parent or "") + el.add('absparent', n.abs_parent and n.abs_parent.id or "") act = el.add('lastactivity') act.add('by', n.last_activity_by and n.last_activity_by.id or "") @@ -450,6 +475,7 @@ def export_nodes(n, el, anon_data): rev.add('tags', ", ".join(r.tagname_list())) el.add('marked', n.marked and 'true' or 'false') + el.add('wiki', n.nis.wiki and 'true' or 'false') el.add('extraRef', n.extra_ref and n.extra_ref.id or "") make_extra(el.add('extraData'), n.extra) el.add('extraCount', n.extra_count and n.extra_count or "") @@ -513,20 +539,3 @@ def export_awards(a, el, anon_data): def export_settings(s, el, anon_data): el.add('key', s.key) make_extra(el.add('value'), s.value) - - - - - - - - - - - - - - - - -