view MoinMoin/util/ @ 2657:080673c3e60a

Now nameless items can also be downloaded and removed unnecessary blank spaces in items/
author Saurabh Kathpalia <>
date Sun, 06 Jul 2014 09:25:31 +0530
parents d1f6f392cdf6
line wrap: on
line source
# Copyright: 2008 MoinMoin:BastianBlank
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

MoinMoin - Tree name and element generator

from emeraldtree import ElementTree as ET

class Name(ET.QName):
    Represents a QName and factory for elements with this QName
    def __call__(self, attrib=None, children=(), **extra):
        return ET.Element(self, attrib=attrib, children=children, **extra)

class Namespace(unicode):
    Represents a namespace and factory for Names within this namespace
    def __call__(self, name):
        Create a Name within this namespace

        :param name: The name within this namespace.
        :returns: A Name
        return Name(name, self)

    def __getattr__(self, key):
        Create a Name within this namespace

        The given key is used to generate a QName within the represented
        namespace.  Two modifications are applied to the key:
         - a trailing "_" (underscore) is removed and
         - all included "_" (underscore) are replaced by "-" (hyphen).

        :returns: A Name
        if '_' in key:
            if key.startswith('_'):
                raise AttributeError(key)
            if key.endswith('_'):
                key = key[:-1]
            key = key.replace('_', '-')
        return Name(key, self)

    def __repr__(self):
        return '<{0}({1!r})>'.format(self.__class__.__name__, str(self))

    def namespace(self):
        return self

# MoinMoin namespaces
moin_page = Namespace('')

# Well-known namespaces
dc = Namespace('')
html = Namespace('')
mathml = Namespace('')
svg = Namespace('')
xinclude = Namespace('')
xlink = Namespace('')
docbook = Namespace('')
xml = Namespace('')