1
<?xml version="1.0" encoding="ascii"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
"DTD/xhtml1-transitional.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6
<title>genshi.core.Attrs</title>
7
<link rel="stylesheet" href="epydoc.css" type="text/css" />
8
<script type="text/javascript" src="epydoc.js"></script>
11
<body bgcolor="white" text="black" link="blue" vlink="#204080"
13
<!-- ==================== NAVIGATION BAR ==================== -->
14
<table class="navbar" border="0" width="100%" cellpadding="0"
15
bgcolor="#a0c0ff" cellspacing="0">
18
<th> <a
19
href="genshi-module.html">Home</a> </th>
22
<th> <a
23
href="module-tree.html">Trees</a> </th>
26
<th> <a
27
href="identifier-index.html">Indices</a> </th>
30
<th> <a
31
href="help.html">Help</a> </th>
33
<!-- Project homepage -->
34
<th class="navbar" align="right" width="100%">
35
<table border="0" cellpadding="0" cellspacing="0">
36
<tr><th class="navbar" align="center"
37
><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th>
41
<table width="100%" cellpadding="0" cellspacing="0">
44
<span class="breadcrumbs">
45
<a href="genshi-module.html">Package genshi</a> ::
46
<a href="genshi.core-module.html">Module core</a> ::
51
<table cellpadding="0" cellspacing="0">
52
<!-- hide/show private -->
57
<!-- ==================== CLASS DESCRIPTION ==================== -->
58
<h1 class="epydoc">Class Attrs</h1><br /><br />
59
<pre class="base-tree">
64
<strong class="uidshort">Attrs</strong>
68
<p>Immutable sequence type that stores the attributes of an element.</p>
69
<p>Ordering of the attributes is preserved, while access by name is also
71
<pre class="py-doctest">
72
<span class="py-prompt">>>> </span>attrs = Attrs([(<span class="py-string">'href'</span>, <span class="py-string">'#'</span>), (<span class="py-string">'title'</span>, <span class="py-string">'Foo'</span>)])
73
<span class="py-prompt">>>> </span>attrs
74
<span class="py-output">Attrs([('href', '#'), ('title', 'Foo')])</span></pre>
75
<pre class="py-doctest">
76
<span class="py-prompt">>>> </span><span class="py-string">'href'</span> <span class="py-keyword">in</span> attrs
77
<span class="py-output">True</span>
78
<span class="py-output"></span><span class="py-prompt">>>> </span><span class="py-string">'tabindex'</span> <span class="py-keyword">in</span> attrs
79
<span class="py-output">False</span>
80
<span class="py-output"></span><span class="py-prompt">>>> </span>attrs.get(<span class="py-string">'title'</span>)
81
<span class="py-output">'Foo'</span></pre>
82
<p>Instances may not be manipulated directly. Instead, the operators <tt class="rst-docutils literal"><span class="pre">|</span></tt> and
83
<tt class="rst-docutils literal"><span class="pre">-</span></tt> can be used to produce new instances that have specific attributes
84
added, replaced or removed.</p>
85
<p>To remove an attribute, use the <tt class="rst-docutils literal"><span class="pre">-</span></tt> operator. The right hand side can be
86
either a string or a set/sequence of strings, identifying the name(s) of
87
the attribute(s) to remove:</p>
88
<pre class="py-doctest">
89
<span class="py-prompt">>>> </span>attrs - <span class="py-string">'title'</span>
90
<span class="py-output">Attrs([('href', '#')])</span>
91
<span class="py-output"></span><span class="py-prompt">>>> </span>attrs - (<span class="py-string">'title'</span>, <span class="py-string">'href'</span>)
92
<span class="py-output">Attrs()</span></pre>
93
<p>The original instance is not modified, but the operator can of course be
94
used with an assignment:</p>
95
<pre class="py-doctest">
96
<span class="py-prompt">>>> </span>attrs
97
<span class="py-output">Attrs([('href', '#'), ('title', 'Foo')])</span>
98
<span class="py-output"></span><span class="py-prompt">>>> </span>attrs -= <span class="py-string">'title'</span>
99
<span class="py-prompt">>>> </span>attrs
100
<span class="py-output">Attrs([('href', '#')])</span></pre>
101
<p>To add a new attribute, use the <tt class="rst-docutils literal"><span class="pre">|</span></tt> operator, where the right hand value
102
is a sequence of <tt class="rst-docutils literal"><span class="pre">(name,</span> <span class="pre">value)</span></tt> tuples (which includes <a href="genshi.core.Attrs-class.html" class="link">Attrs</a>
104
<pre class="py-doctest">
105
<span class="py-prompt">>>> </span>attrs | [(<span class="py-string">'title'</span>, <span class="py-string">'Bar'</span>)]
106
<span class="py-output">Attrs([('href', '#'), ('title', 'Bar')])</span></pre>
107
<p>If the attributes already contain an attribute with a given name, the value
108
of that attribute is replaced:</p>
109
<pre class="py-doctest">
110
<span class="py-prompt">>>> </span>attrs | [(<span class="py-string">'href'</span>, <span class="py-string">'http://example.org/'</span>)]
111
<span class="py-output">Attrs([('href', 'http://example.org/')])</span></pre><br /><br />
113
<!-- ==================== INSTANCE METHODS ==================== -->
114
<a name="section-InstanceMethods"></a>
115
<table class="summary" border="1" cellpadding="3"
116
cellspacing="0" width="100%" bgcolor="white">
117
<tr bgcolor="#70b0f0" class="table-header">
118
<td align="left" colspan="2" class="table-header">
119
<span class="table-header">Instance Methods</span></td>
122
<td width="15%" align="right" valign="top" class="summary">
123
<span class="summary-type"> </span>
124
</td><td class="summary">
125
<table width="100%" cellpadding="0" cellspacing="0" border="0">
127
<td><span class="summary-sig"><a href="genshi.core.Attrs-class.html#__contains__" class="summary-sig-name">__contains__</a>(<span class="summary-sig-arg">self</span>,
128
<span class="summary-sig-arg">name</span>)</span><br />
129
Return whether the list includes an attribute with the specified
131
<td align="right" valign="top">
141
<td width="15%" align="right" valign="top" class="summary">
142
<span class="summary-type"> </span>
143
</td><td class="summary">
144
<table width="100%" cellpadding="0" cellspacing="0" border="0">
146
<td><span class="summary-sig"><a href="genshi.core.Attrs-class.html#__getslice__" class="summary-sig-name">__getslice__</a>(<span class="summary-sig-arg">self</span>,
147
<span class="summary-sig-arg">i</span>,
148
<span class="summary-sig-arg">j</span>)</span><br />
150
<td align="right" valign="top">
160
<td width="15%" align="right" valign="top" class="summary">
161
<span class="summary-type"> </span>
162
</td><td class="summary">
163
<table width="100%" cellpadding="0" cellspacing="0" border="0">
165
<td><span class="summary-sig"><a name="__or__"></a><span class="summary-sig-name">__or__</span>(<span class="summary-sig-arg">self</span>,
166
<span class="summary-sig-arg">attrs</span>)</span><br />
167
Return a new instance that contains the attributes in <code class="link">attrs</code> in
168
addition to any already existing attributes.</td>
169
<td align="right" valign="top">
179
<td width="15%" align="right" valign="top" class="summary">
180
<span class="summary-type"> </span>
181
</td><td class="summary">
182
<table width="100%" cellpadding="0" cellspacing="0" border="0">
184
<td><span class="summary-sig"><a href="genshi.core.Attrs-class.html#__repr__" class="summary-sig-name">__repr__</a>(<span class="summary-sig-arg">self</span>)</span><br />
186
<td align="right" valign="top">
196
<td width="15%" align="right" valign="top" class="summary">
197
<span class="summary-type"> </span>
198
</td><td class="summary">
199
<table width="100%" cellpadding="0" cellspacing="0" border="0">
201
<td><span class="summary-sig"><a name="__sub__"></a><span class="summary-sig-name">__sub__</span>(<span class="summary-sig-arg">self</span>,
202
<span class="summary-sig-arg">names</span>)</span><br />
203
Return a new instance with all attributes with a name in <code class="link">names</code> are
205
<td align="right" valign="top">
215
<td width="15%" align="right" valign="top" class="summary">
216
<span class="summary-type"> </span>
217
</td><td class="summary">
218
<table width="100%" cellpadding="0" cellspacing="0" border="0">
220
<td><span class="summary-sig"><a href="genshi.core.Attrs-class.html#get" class="summary-sig-name">get</a>(<span class="summary-sig-arg">self</span>,
221
<span class="summary-sig-arg">name</span>,
222
<span class="summary-sig-arg">default</span>=<span class="summary-sig-default">None</span>)</span><br />
223
Return the value of the attribute with the specified name, or the
224
value of the <code class="link">default</code> parameter if no such attribute is found.</td>
225
<td align="right" valign="top">
235
<td width="15%" align="right" valign="top" class="summary">
236
<span class="summary-type"> </span>
237
</td><td class="summary">
238
<table width="100%" cellpadding="0" cellspacing="0" border="0">
240
<td><span class="summary-sig"><a href="genshi.core.Attrs-class.html#totuple" class="summary-sig-name">totuple</a>(<span class="summary-sig-arg">self</span>)</span><br />
241
Return the attributes as a markup event.</td>
242
<td align="right" valign="top">
252
<td colspan="2" class="summary">
253
<p class="indent-wrapped-lines"><b>Inherited from <code>tuple</code></b>:
254
<code>__add__</code>,
257
<code>__getattribute__</code>,
258
<code>__getitem__</code>,
259
<code>__getnewargs__</code>,
261
<code>__hash__</code>,
262
<code>__iter__</code>,
264
<code>__len__</code>,
266
<code>__mul__</code>,
268
<code>__new__</code>,
269
<code>__rmul__</code>
271
<p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
272
<code>__delattr__</code>,
273
<code>__init__</code>,
274
<code>__reduce__</code>,
275
<code>__reduce_ex__</code>,
276
<code>__setattr__</code>,
282
<!-- ==================== PROPERTIES ==================== -->
283
<a name="section-Properties"></a>
284
<table class="summary" border="1" cellpadding="3"
285
cellspacing="0" width="100%" bgcolor="white">
286
<tr bgcolor="#70b0f0" class="table-header">
287
<td align="left" colspan="2" class="table-header">
288
<span class="table-header">Properties</span></td>
291
<td colspan="2" class="summary">
292
<p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
293
<code>__class__</code>
298
<!-- ==================== METHOD DETAILS ==================== -->
299
<a name="section-MethodDetails"></a>
300
<table class="details" border="1" cellpadding="3"
301
cellspacing="0" width="100%" bgcolor="white">
302
<tr bgcolor="#70b0f0" class="table-header">
303
<td align="left" colspan="2" class="table-header">
304
<span class="table-header">Method Details</span></td>
307
<a name="__contains__"></a>
309
<table class="details" border="1" cellpadding="3"
310
cellspacing="0" width="100%" bgcolor="white">
312
<table width="100%" cellpadding="0" cellspacing="0" border="0">
313
<tr valign="top"><td>
314
<h3 class="epydoc"><span class="sig"><span class="sig-name">__contains__</span>(<span class="sig-arg">self</span>,
315
<span class="sig-arg">name</span>)</span>
316
<br /><em class="fname">(In operator)</em>
318
</td><td align="right" valign="top"
323
Return whether the list includes an attribute with the specified
332
<a name="__getslice__"></a>
334
<table class="details" border="1" cellpadding="3"
335
cellspacing="0" width="100%" bgcolor="white">
337
<table width="100%" cellpadding="0" cellspacing="0" border="0">
338
<tr valign="top"><td>
339
<h3 class="epydoc"><span class="sig"><span class="sig-name">__getslice__</span>(<span class="sig-arg">self</span>,
340
<span class="sig-arg">i</span>,
341
<span class="sig-arg">j</span>)</span>
342
<br /><em class="fname">(Slicling operator)</em>
344
</td><td align="right" valign="top"
350
<p>Use of negative indices is not supported.</p>
354
<dd><em class="note">(inherited documentation)</em></dd>
359
<a name="__repr__"></a>
361
<table class="details" border="1" cellpadding="3"
362
cellspacing="0" width="100%" bgcolor="white">
364
<table width="100%" cellpadding="0" cellspacing="0" border="0">
365
<tr valign="top"><td>
366
<h3 class="epydoc"><span class="sig"><span class="sig-name">__repr__</span>(<span class="sig-arg">self</span>)</span>
367
<br /><em class="fname">(Representation operator)</em>
369
</td><td align="right" valign="top"
378
<dd><em class="note">(inherited documentation)</em></dd>
385
<table class="details" border="1" cellpadding="3"
386
cellspacing="0" width="100%" bgcolor="white">
388
<table width="100%" cellpadding="0" cellspacing="0" border="0">
389
<tr valign="top"><td>
390
<h3 class="epydoc"><span class="sig"><span class="sig-name">get</span>(<span class="sig-arg">self</span>,
391
<span class="sig-arg">name</span>,
392
<span class="sig-arg">default</span>=<span class="sig-default">None</span>)</span>
394
</td><td align="right" valign="top"
399
Return the value of the attribute with the specified name, or the
400
value of the <code class="link">default</code> parameter if no such attribute is found.
403
<dd><ul class="nomargin-top">
404
<li><strong class="pname"><code>name</code></strong> - the name of the attribute</li>
405
<li><strong class="pname"><code>default</code></strong> - the value to return when the attribute does not exist</li>
408
<dd>the attribute value, or the <code class="link">default</code> value if that attribute
413
<a name="totuple"></a>
415
<table class="details" border="1" cellpadding="3"
416
cellspacing="0" width="100%" bgcolor="white">
418
<table width="100%" cellpadding="0" cellspacing="0" border="0">
419
<tr valign="top"><td>
420
<h3 class="epydoc"><span class="sig"><span class="sig-name">totuple</span>(<span class="sig-arg">self</span>)</span>
422
</td><td align="right" valign="top"
427
<p>Return the attributes as a markup event.</p>
428
<p>The returned event is a <a href="genshi.core-module.html#TEXT" class="link">TEXT</a> event, the data is the value of all
429
attributes joined together.</p>
430
<pre class="py-doctest">
431
<span class="py-prompt">>>> </span>Attrs([(<span class="py-string">'href'</span>, <span class="py-string">'#'</span>), (<span class="py-string">'title'</span>, <span class="py-string">'Foo'</span>)]).totuple()
432
<span class="py-output">('TEXT', u'#Foo', (None, -1, -1))</span></pre>
438
<!-- ==================== NAVIGATION BAR ==================== -->
439
<table class="navbar" border="0" width="100%" cellpadding="0"
440
bgcolor="#a0c0ff" cellspacing="0">
443
<th> <a
444
href="genshi-module.html">Home</a> </th>
447
<th> <a
448
href="module-tree.html">Trees</a> </th>
451
<th> <a
452
href="identifier-index.html">Indices</a> </th>
455
<th> <a
456
href="help.html">Help</a> </th>
458
<!-- Project homepage -->
459
<th class="navbar" align="right" width="100%">
460
<table border="0" cellpadding="0" cellspacing="0">
461
<tr><th class="navbar" align="center"
462
><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th>
466
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
468
<td align="left" class="footer">
469
Generated by Epydoc 3.0beta1 on Mon Apr 16 16:02:13 2007
471
<td align="right" class="footer">
472
<a href="http://epydoc.sourceforge.net">http://epydoc.sourceforge.net</a>
477
<script type="text/javascript">
479
// Private objects are initially displayed (because if
480
// javascript is turned off then we want them to be
481
// visible); but by default, we want to hide them. So hide
482
// them unless we have a cookie that says to show them.