annotate markup/builder.py @ 49:9b5255d72e33

convert Trac search page to Markup
author mgood
date Tue, 04 Jul 2006 05:08:22 +0000
parents ae293292cbb1
children 5c024cf58ecb
rev   line source
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
2 #
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
3 # Copyright (C) 2006 Christopher Lenz
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
4 # All rights reserved.
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
5 #
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
27
b8456279c444 * Fix the boilerplate in the Python source files.
cmlenz
parents: 20
diff changeset
8 # are also available at http://markup.cmlenz.net/wiki/License.
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
9 #
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
27
b8456279c444 * Fix the boilerplate in the Python source files.
cmlenz
parents: 20
diff changeset
12 # history and logs, available at http://markup.cmlenz.net/log/.
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
13
19
7b589453b797 Enable `ElementFactory` to create namespaced elements.
cmlenz
parents: 17
diff changeset
14 from markup.core import Attributes, Namespace, QName, Stream
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
15
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
16 __all__ = ['Fragment', 'Element', 'tag']
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
17
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
18
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
19 class Fragment(object):
28
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
20 """Represents a markup fragment, which is basically just a list of element
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
21 or text nodes.
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
22 """
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
23 __slots__ = ['children']
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
24
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
25 def __init__(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
26 self.children = []
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
27
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
28 def append(self, node):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
29 """Append an element or string as child node."""
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
30 if isinstance(node, (Element, basestring, int, float, long)):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
31 # For objects of a known/primitive type, we avoid the check for
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
32 # whether it is iterable for better performance
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
33 self.children.append(node)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
34 elif isinstance(node, Fragment):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
35 self.children += node.children
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
36 elif node is not None:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
37 try:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
38 children = iter(node)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
39 except TypeError:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
40 self.children.append(node)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
41 else:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
42 for child in node:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
43 self.append(children)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
44
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
45 def __add__(self, other):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
46 return Fragment()(self, other)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
47
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
48 def __call__(self, *args):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
49 for arg in args:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
50 self.append(arg)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
51 return self
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
52
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
53 def generate(self):
28
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
54 """Return a markup event stream for the fragment."""
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
55 def _generate():
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
56 for child in self.children:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
57 if isinstance(child, Fragment):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
58 for event in child.generate():
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
59 yield event
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
60 else:
17
ad63ad459524 Refactoring to address #6: all match templates are now processed by a single filter, which means that match templates added by included templates are properly applied. A side effect of this refactoring is that `Context` objects may not be reused across multiple template processing runs.
cmlenz
parents: 1
diff changeset
61 yield Stream.TEXT, unicode(child), (-1, -1)
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
62 return Stream(_generate())
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
63
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
64 def __iter__(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
65 return iter(self.generate())
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
66
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
67 def __str__(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
68 return str(self.generate())
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
69
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
70 def __unicode__(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
71 return unicode(self.generate())
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
72
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
73
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
74 class Element(Fragment):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
75 """Simple XML output generator based on the builder pattern.
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
76
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
77 Construct XML elements by passing the tag name to the constructor:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
78
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
79 >>> print Element('strong')
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
80 <strong/>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
81
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
82 Attributes can be specified using keyword arguments. The values of the
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
83 arguments will be converted to strings and any special XML characters
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
84 escaped:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
85
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
86 >>> print Element('textarea', rows=10, cols=60)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
87 <textarea rows="10" cols="60"/>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
88 >>> print Element('span', title='1 < 2')
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
89 <span title="1 &lt; 2"/>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
90 >>> print Element('span', title='"baz"')
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
91 <span title="&#34;baz&#34;"/>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
92
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
93 The " character is escaped using a numerical entity.
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
94 The order in which attributes are rendered is undefined.
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
95
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
96 If an attribute value evaluates to `None`, that attribute is not included
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
97 in the output:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
98
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
99 >>> print Element('a', name=None)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
100 <a/>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
101
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
102 Attribute names that conflict with Python keywords can be specified by
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
103 appending an underscore:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
104
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
105 >>> print Element('div', class_='warning')
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
106 <div class="warning"/>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
107
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
108 Nested elements can be added to an element using item access notation.
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
109 The call notation can also be used for this and for adding attributes
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
110 using keyword arguments, as one would do in the constructor.
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
111
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
112 >>> print Element('ul')(Element('li'), Element('li'))
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
113 <ul><li/><li/></ul>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
114 >>> print Element('a')('Label')
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
115 <a>Label</a>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
116 >>> print Element('a')('Label', href="target")
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
117 <a href="target">Label</a>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
118
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
119 Text nodes can be nested in an element by adding strings instead of
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
120 elements. Any special characters in the strings are escaped automatically:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
121
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
122 >>> print Element('em')('Hello world')
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
123 <em>Hello world</em>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
124 >>> print Element('em')(42)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
125 <em>42</em>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
126 >>> print Element('em')('1 < 2')
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
127 <em>1 &lt; 2</em>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
128
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
129 This technique also allows mixed content:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
130
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
131 >>> print Element('p')('Hello ', Element('b')('world'))
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
132 <p>Hello <b>world</b></p>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
133
34
ae293292cbb1 quotes should not be escaped inside text nodes
mgood
parents: 28
diff changeset
134 Quotes are not escaped inside text nodes:
ae293292cbb1 quotes should not be escaped inside text nodes
mgood
parents: 28
diff changeset
135 >>> print Element('p')('"Hello"')
ae293292cbb1 quotes should not be escaped inside text nodes
mgood
parents: 28
diff changeset
136 <p>"Hello"</p>
ae293292cbb1 quotes should not be escaped inside text nodes
mgood
parents: 28
diff changeset
137
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
138 Elements can also be combined with other elements or strings using the
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
139 addition operator, which results in a `Fragment` object that contains the
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
140 operands:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
141
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
142 >>> print Element('br') + 'some text' + Element('br')
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
143 <br/>some text<br/>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
144
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
145 Elements with a namespace can be generated using the `Namespace` and/or
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
146 `QName` classes:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
147
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
148 >>> from markup.core import Namespace
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
149 >>> xhtml = Namespace('http://www.w3.org/1999/xhtml')
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
150 >>> print Element(xhtml.html, lang='en')
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
151 <html lang="en" xmlns="http://www.w3.org/1999/xhtml"/>
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
152 """
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
153 __slots__ = ['tag', 'attrib']
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
154
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
155 def __init__(self, tag_, **attrib):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
156 Fragment.__init__(self)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
157 self.tag = QName(tag_)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
158 self.attrib = Attributes()
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
159 self(**attrib)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
160
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
161 def __call__(self, *args, **kwargs):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
162 for attr, value in kwargs.items():
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
163 if value is None:
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
164 continue
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
165 attr = attr.rstrip('_').replace('_', '-')
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
166 self.attrib.set(attr, value)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
167 return Fragment.__call__(self, *args)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
168
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
169 def generate(self):
28
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
170 """Return a markup event stream for the fragment."""
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
171 def _generate():
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
172 yield Stream.START, (self.tag, self.attrib), (-1, -1)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
173 for kind, data, pos in Fragment.generate(self):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
174 yield kind, data, pos
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
175 yield Stream.END, self.tag, (-1, -1)
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
176 return Stream(_generate())
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
177
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
178
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
179 class ElementFactory(object):
28
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
180 """Factory for `Element` objects.
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
181
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
182 A new element is created simply by accessing a correspondingly named
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
183 attribute of the factory object:
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
184
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
185 >>> factory = ElementFactory()
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
186 >>> print factory.foo
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
187 <foo/>
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
188 >>> print factory.foo(id=2)
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
189 <foo id="2"/>
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
190
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
191 A factory can also be bound to a specific namespace:
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
192
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
193 >>> factory = ElementFactory('http://www.w3.org/1999/xhtml')
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
194 >>> print factory.html(lang="en")
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
195 <html lang="en" xmlns="http://www.w3.org/1999/xhtml"/>
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
196
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
197 The namespace for a specific element can be altered on an existing factory
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
198 by specifying the new namespace using item access:
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
199
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
200 >>> factory = ElementFactory()
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
201 >>> print factory.html(factory['http://www.w3.org/2000/svg'].g(id=3))
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
202 <html><g id="3" xmlns="http://www.w3.org/2000/svg"/></html>
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
203
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
204 Usually, the `ElementFactory` class is not be used directly. Rather, the
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
205 `tag` instance should be used to create elements.
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
206 """
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
207
19
7b589453b797 Enable `ElementFactory` to create namespaced elements.
cmlenz
parents: 17
diff changeset
208 def __init__(self, namespace=None):
28
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
209 """Create the factory, optionally bound to the given namespace.
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
210
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
211 @param namespace: the namespace URI for any created elements, or `None`
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
212 for no namespace
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
213 """
20
e3d3c1d8c98a Fix tests broken in [20].
cmlenz
parents: 19
diff changeset
214 if namespace and not isinstance(namespace, Namespace):
19
7b589453b797 Enable `ElementFactory` to create namespaced elements.
cmlenz
parents: 17
diff changeset
215 namespace = Namespace(namespace)
7b589453b797 Enable `ElementFactory` to create namespaced elements.
cmlenz
parents: 17
diff changeset
216 self.namespace = namespace
7b589453b797 Enable `ElementFactory` to create namespaced elements.
cmlenz
parents: 17
diff changeset
217
7b589453b797 Enable `ElementFactory` to create namespaced elements.
cmlenz
parents: 17
diff changeset
218 def __getitem__(self, namespace):
28
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
219 """Return a new factory that is bound to the specified namespace."""
19
7b589453b797 Enable `ElementFactory` to create namespaced elements.
cmlenz
parents: 17
diff changeset
220 return ElementFactory(namespace)
7b589453b797 Enable `ElementFactory` to create namespaced elements.
cmlenz
parents: 17
diff changeset
221
7b589453b797 Enable `ElementFactory` to create namespaced elements.
cmlenz
parents: 17
diff changeset
222 def __getattr__(self, name):
28
15e59a9cb362 More docstrings for the builder module.
cmlenz
parents: 27
diff changeset
223 """Create an `Element` with the given name."""
19
7b589453b797 Enable `ElementFactory` to create namespaced elements.
cmlenz
parents: 17
diff changeset
224 return Element(self.namespace and self.namespace[name] or name)
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
225
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
226
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
227 tag = ElementFactory()
Copyright (C) 2012-2017 Edgewall Software