Mercurial > genshi > mirror
comparison markup/builder.py @ 19:704f10b06507 trunk
Enable `ElementFactory` to create namespaced elements.
author | cmlenz |
---|---|
date | Mon, 19 Jun 2006 16:34:00 +0000 |
parents | 74cc70129d04 |
children | cc92d74ce9e5 |
comparison
equal
deleted
inserted
replaced
18:5420cfe42d36 | 19:704f10b06507 |
---|---|
9 # | 9 # |
10 # This software consists of voluntary contributions made by many | 10 # This software consists of voluntary contributions made by many |
11 # individuals. For the exact contribution history, see the revision | 11 # individuals. For the exact contribution history, see the revision |
12 # history and logs, available at http://projects.edgewall.com/trac/. | 12 # history and logs, available at http://projects.edgewall.com/trac/. |
13 | 13 |
14 from markup.core import Attributes, QName, Stream | 14 from markup.core import Attributes, Namespace, QName, Stream |
15 | 15 |
16 __all__ = ['Fragment', 'Element', 'tag'] | 16 __all__ = ['Fragment', 'Element', 'tag'] |
17 | 17 |
18 | 18 |
19 class Fragment(object): | 19 class Fragment(object): |
169 return Stream(_generate()) | 169 return Stream(_generate()) |
170 | 170 |
171 | 171 |
172 class ElementFactory(object): | 172 class ElementFactory(object): |
173 | 173 |
174 def __getattribute__(self, name): | 174 def __init__(self, namespace=None): |
175 return Element(name.lower()) | 175 if not isinstance(namespace, Namespace): |
176 namespace = Namespace(namespace) | |
177 self.namespace = namespace | |
178 | |
179 def __getitem__(self, namespace): | |
180 return ElementFactory(namespace) | |
181 | |
182 def __getattr__(self, name): | |
183 return Element(self.namespace and self.namespace[name] or name) | |
176 | 184 |
177 | 185 |
178 tag = ElementFactory() | 186 tag = ElementFactory() |