Mercurial > genshi > genshi-test
comparison markup/core.py @ 182:41db0260ebb1
Renamed `Attributes` to `Attrs` to reduce the verbosity.
author | cmlenz |
---|---|
date | Mon, 21 Aug 2006 20:03:13 +0000 |
parents | 4b4e80b2b0b5 |
children | 50eab0469148 |
comparison
equal
deleted
inserted
replaced
181:d07ce6c1dbbe | 182:41db0260ebb1 |
---|---|
154 else: | 154 else: |
155 event = TEXT, unicode(event), (None, -1, -1) | 155 event = TEXT, unicode(event), (None, -1, -1) |
156 yield event | 156 yield event |
157 | 157 |
158 | 158 |
159 class Attributes(list): | 159 class Attrs(list): |
160 """Sequence type that stores the attributes of an element. | 160 """Sequence type that stores the attributes of an element. |
161 | 161 |
162 The order of the attributes is preserved, while accessing and manipulating | 162 The order of the attributes is preserved, while accessing and manipulating |
163 attributes by name is also supported. | 163 attributes by name is also supported. |
164 | 164 |
165 >>> attrs = Attributes([('href', '#'), ('title', 'Foo')]) | 165 >>> attrs = Attrs([('href', '#'), ('title', 'Foo')]) |
166 >>> attrs | 166 >>> attrs |
167 [(u'href', '#'), (u'title', 'Foo')] | 167 [(u'href', '#'), (u'title', 'Foo')] |
168 | 168 |
169 >>> 'href' in attrs | 169 >>> 'href' in attrs |
170 True | 170 True |
185 | 185 |
186 >>> attrs.set(u'accesskey', 'k') | 186 >>> attrs.set(u'accesskey', 'k') |
187 >>> attrs | 187 >>> attrs |
188 [(u'href', '#'), (u'accesskey', 'k')] | 188 [(u'href', '#'), (u'accesskey', 'k')] |
189 | 189 |
190 An `Attributes` instance can also be initialized with keyword arguments. | 190 An `Attrs` instance can also be initialized with keyword arguments. |
191 | 191 |
192 >>> attrs = Attributes(class_='bar', href='#', title='Foo') | 192 >>> attrs = Attrs(class_='bar', href='#', title='Foo') |
193 >>> attrs.get('class') | 193 >>> attrs.get('class') |
194 'bar' | 194 'bar' |
195 >>> attrs.get('href') | 195 >>> attrs.get('href') |
196 '#' | 196 '#' |
197 >>> attrs.get('title') | 197 >>> attrs.get('title') |
198 'Foo' | 198 'Foo' |
199 | 199 |
200 Reserved words can be used by appending a trailing underscore to the name, | 200 Reserved words can be used by appending a trailing underscore to the name, |
201 and any other underscore is replaced by a dash: | 201 and any other underscore is replaced by a dash: |
202 | 202 |
203 >>> attrs = Attributes(class_='bar', accept_charset='utf-8') | 203 >>> attrs = Attrs(class_='bar', accept_charset='utf-8') |
204 >>> attrs.get('class') | 204 >>> attrs.get('class') |
205 'bar' | 205 'bar' |
206 >>> attrs.get('accept-charset') | 206 >>> attrs.get('accept-charset') |
207 'utf-8' | 207 'utf-8' |
208 | 208 |
210 actual underscore characters. | 210 actual underscore characters. |
211 """ | 211 """ |
212 __slots__ = [] | 212 __slots__ = [] |
213 | 213 |
214 def __init__(self, attrib=None, **kwargs): | 214 def __init__(self, attrib=None, **kwargs): |
215 """Create the `Attributes` instance. | 215 """Create the `Attrs` instance. |
216 | 216 |
217 If the `attrib` parameter is provided, it is expected to be a sequence | 217 If the `attrib` parameter is provided, it is expected to be a sequence |
218 of `(name, value)` tuples. | 218 of `(name, value)` tuples. |
219 """ | 219 """ |
220 if attrib is None: | 220 if attrib is None: |