view MoinMoin/util/ @ 1364:582e7109a8c1

mass update - delete trailing spaces and/or add blank line to end of file
author Roger Haase <>
date Wed, 06 Jun 2012 15:03:07 -0700
parents 5bf6d7a2ffcf
children 4ac437141bbe
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__, 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('')