Mercurial > genshi > genshi-test
changeset 19:7b589453b797
Enable `ElementFactory` to create namespaced elements.
author | cmlenz |
---|---|
date | Mon, 19 Jun 2006 16:34:00 +0000 |
parents | 4cbebb15a834 |
children | e3d3c1d8c98a |
files | markup/builder.py markup/output.py |
diffstat | 2 files changed, 17 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/markup/builder.py +++ b/markup/builder.py @@ -11,7 +11,7 @@ # individuals. For the exact contribution history, see the revision # history and logs, available at http://projects.edgewall.com/trac/. -from markup.core import Attributes, QName, Stream +from markup.core import Attributes, Namespace, QName, Stream __all__ = ['Fragment', 'Element', 'tag'] @@ -171,8 +171,16 @@ class ElementFactory(object): - def __getattribute__(self, name): - return Element(name.lower()) + def __init__(self, namespace=None): + if not isinstance(namespace, Namespace): + namespace = Namespace(namespace) + self.namespace = namespace + + def __getitem__(self, namespace): + return ElementFactory(namespace) + + def __getattr__(self, name): + return Element(self.namespace and self.namespace[name] or name) tag = ElementFactory()
--- a/markup/output.py +++ b/markup/output.py @@ -103,9 +103,12 @@ tag = data tagname = tag.localname if tag.namespace: - prefix = ns_mapping[tag.namespace] - if prefix: - tagname = prefix + ':' + tag.localname + try: + prefix = ns_mapping[tag.namespace] + if prefix: + tagname = prefix + ':' + tag.localname + except KeyError: + pass yield Markup('</%s>' % tagname) elif kind is Stream.TEXT: