view MoinMoin/wikixml/ @ 3077:66d35649ca99

add 'percent' kw to getText (must be True when using result as left side of % operator), refactored some code, better comments (ported from 1.6)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 22 Feb 2008 22:35:46 +0100
parents dbf2b7426385
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - XML Utilities

    @copyright: 2001 Juergen Hermann <>
    @license: GNU GPL, see COPYING for details.

from xml.sax import saxutils
from MoinMoin import config

class XMLGenerator(saxutils.XMLGenerator):
    default_xmlns = {}

    def __init__(self, out):
        saxutils.XMLGenerator.__init__(self, out=out, encoding=config.charset)
        self.xmlns = self.default_xmlns

    def _build_tag(self, tag):
        if type(tag) == type(""):
            qname = tag
            tag = (None, tag)
            qname = "%s:%s" % tag
            tag = (self.xmlns[tag[0]], tag[1])
        return tag, qname

    def startNode(self, tag, attr={}):
        tag, qname = self._build_tag(tag)
        self.startElementNS(tag, qname, attr)

    def endNode(self, tag):
        tag, qname = self._build_tag(tag)
        self.endElementNS(tag, qname)

    def simpleNode(self, tag, value, attr={}):
        self.startNode(tag, attr)
        if value:

    def startDocument(self):
        for prefix, uri in self.xmlns.items():
            self.startPrefixMapping(prefix or None, uri)

    def endDocument(self):
        for prefix in self.xmlns:
            self.endPrefixMapping(prefix or None)

class RssGenerator(XMLGenerator):
    default_xmlns = {
        None:       "",
        'rdf':      "",
        'xlink':    "",
        'dc':       "",
        'wiki':     "",

    def __init__(self, out):
        XMLGenerator.__init__(self, out=out)

    def startDocument(self):
        self.startElementNS((self.xmlns['rdf'], 'RDF'), 'rdf:RDF', {})

    def endDocument(self):
        self.endElementNS((self.xmlns['rdf'], 'RDF'), 'rdf:RDF')