view MoinMoin/wikixml/ @ 35:f0af060fb82b

making people choose the right approach to page_front_page imported from: moin--main--1.5--patch-36
author Thomas Waldmann <>
date Sun, 25 Sep 2005 14:45:38 +0000
parents 55ff4feb0f59
children e80ad5feaba8
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - XML Utilities

    @copyright: 2001 by Jürgen 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: self.characters(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.keys():
            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')