<?xml version="1.0" encoding="ascii"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>genshi.core.Attrs</title> <link rel="stylesheet" href="epydoc.css" type="text/css" /> <script type="text/javascript" src="epydoc.js"></script> </head> <body bgcolor="white" text="black" link="blue" vlink="#204080" alink="#204080"> <!-- ==================== NAVIGATION BAR ==================== --> <table class="navbar" border="0" width="100%" cellpadding="0" bgcolor="#a0c0ff" cellspacing="0"> <tr valign="middle"> <!-- Home link --> <th> <a href="genshi-module.html">Home</a> </th> <!-- Tree link --> <th> <a href="module-tree.html">Trees</a> </th> <!-- Index link --> <th> <a href="identifier-index.html">Indices</a> </th> <!-- Help link --> <th> <a href="help.html">Help</a> </th> <!-- Project homepage --> <th class="navbar" align="right" width="100%"> <table border="0" cellpadding="0" cellspacing="0"> <tr><th class="navbar" align="center" ><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th> </tr></table></th> </tr> </table> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="100%"> <span class="breadcrumbs"> <a href="genshi-module.html">Package genshi</a> :: <a href="genshi.core-module.html">Module core</a> :: Class Attrs </span> </td> <td> <table cellpadding="0" cellspacing="0"> <!-- hide/show private --> </table> </td> </tr> </table> <!-- ==================== CLASS DESCRIPTION ==================== --> <h1 class="epydoc">Class Attrs</h1><p class="nomargin-top"></p> <pre class="base-tree"> object --+ | tuple --+ | <strong class="uidshort">Attrs</strong> </pre> <hr /> <p>Immutable sequence type that stores the attributes of an element.</p> <p>Ordering of the attributes is preserved, while access by name is also supported.</p> <pre class="py-doctest"> <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>)]) <span class="py-prompt">>>> </span>attrs <span class="py-output">Attrs([('href', '#'), ('title', 'Foo')])</span></pre> <pre class="py-doctest"> <span class="py-prompt">>>> </span><span class="py-string">'href'</span> <span class="py-keyword">in</span> attrs <span class="py-output">True</span> <span class="py-output"></span><span class="py-prompt">>>> </span><span class="py-string">'tabindex'</span> <span class="py-keyword">in</span> attrs <span class="py-output">False</span> <span class="py-output"></span><span class="py-prompt">>>> </span>attrs.get(<span class="py-string">'title'</span>) <span class="py-output">'Foo'</span></pre> <p>Instances may not be manipulated directly. Instead, the operators <tt class="rst-docutils literal"><span class="pre">|</span></tt> and <tt class="rst-docutils literal"><span class="pre">-</span></tt> can be used to produce new instances that have specific attributes added, replaced or removed.</p> <p>To remove an attribute, use the <tt class="rst-docutils literal"><span class="pre">-</span></tt> operator. The right hand side can be either a string or a set/sequence of strings, identifying the name(s) of the attribute(s) to remove:</p> <pre class="py-doctest"> <span class="py-prompt">>>> </span>attrs - <span class="py-string">'title'</span> <span class="py-output">Attrs([('href', '#')])</span> <span class="py-output"></span><span class="py-prompt">>>> </span>attrs - (<span class="py-string">'title'</span>, <span class="py-string">'href'</span>) <span class="py-output">Attrs()</span></pre> <p>The original instance is not modified, but the operator can of course be used with an assignment:</p> <pre class="py-doctest"> <span class="py-prompt">>>> </span>attrs <span class="py-output">Attrs([('href', '#'), ('title', 'Foo')])</span> <span class="py-output"></span><span class="py-prompt">>>> </span>attrs -= <span class="py-string">'title'</span> <span class="py-prompt">>>> </span>attrs <span class="py-output">Attrs([('href', '#')])</span></pre> <p>To add a new attribute, use the <tt class="rst-docutils literal"><span class="pre">|</span></tt> operator, where the right hand value 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> instances):</p> <pre class="py-doctest"> <span class="py-prompt">>>> </span>attrs | [(<span class="py-string">'title'</span>, <span class="py-string">'Bar'</span>)] <span class="py-output">Attrs([('href', '#'), ('title', 'Bar')])</span></pre> <p>If the attributes already contain an attribute with a given name, the value of that attribute is replaced:</p> <pre class="py-doctest"> <span class="py-prompt">>>> </span>attrs | [(<span class="py-string">'href'</span>, <span class="py-string">'http://example.org/'</span>)] <span class="py-output">Attrs([('href', 'http://example.org/')])</span></pre> <!-- ==================== INSTANCE METHODS ==================== --> <a name="section-InstanceMethods"></a> <table class="summary" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white"> <tr bgcolor="#70b0f0" class="table-header"> <td align="left" colspan="2" class="table-header"> <span class="table-header">Instance Methods</span></td> </tr> <tr> <td width="15%" align="right" valign="top" class="summary"> <span class="summary-type"><code class="link">bool</code></span> </td><td class="summary"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <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>, <span class="summary-sig-arg">name</span>)</span><br /> Return whether the list includes an attribute with the specified name.</td> <td align="right" valign="top"> </td> </tr> </table> </td> </tr> <tr> <td width="15%" align="right" valign="top" class="summary"> <span class="summary-type"> </span> </td><td class="summary"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <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>, <span class="summary-sig-arg">i</span>, <span class="summary-sig-arg">j</span>)</span><br /> Return a slice of the attributes list.</td> <td align="right" valign="top"> </td> </tr> </table> </td> </tr> <tr> <td width="15%" align="right" valign="top" class="summary"> <span class="summary-type"><a href="genshi.core.Attrs-class.html" class="link">Attrs</a></span> </td><td class="summary"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td><span class="summary-sig"><a href="genshi.core.Attrs-class.html#__or__" class="summary-sig-name">__or__</a>(<span class="summary-sig-arg">self</span>, <span class="summary-sig-arg">attrs</span>)</span><br /> Return a new instance that contains the attributes in <code class="link">attrs</code> in addition to any already existing attributes.</td> <td align="right" valign="top"> </td> </tr> </table> </td> </tr> <tr> <td width="15%" align="right" valign="top" class="summary"> <span class="summary-type"> </span> </td><td class="summary"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <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 /> repr(x)</td> <td align="right" valign="top"> </td> </tr> </table> </td> </tr> <tr> <td width="15%" align="right" valign="top" class="summary"> <span class="summary-type"><a href="genshi.core.Attrs-class.html" class="link">Attrs</a></span> </td><td class="summary"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td><span class="summary-sig"><a href="genshi.core.Attrs-class.html#__sub__" class="summary-sig-name">__sub__</a>(<span class="summary-sig-arg">self</span>, <span class="summary-sig-arg">names</span>)</span><br /> Return a new instance with all attributes with a name in <code class="link">names</code> are removed.</td> <td align="right" valign="top"> </td> </tr> </table> </td> </tr> <tr> <td width="15%" align="right" valign="top" class="summary"> <span class="summary-type"><code class="link">object</code></span> </td><td class="summary"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <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>, <span class="summary-sig-arg">name</span>, <span class="summary-sig-arg">default</span>=<span class="summary-sig-default">None</span>)</span><br /> Return the value of the attribute with the specified name, or the value of the <code class="link">default</code> parameter if no such attribute is found.</td> <td align="right" valign="top"> </td> </tr> </table> </td> </tr> <tr> <td width="15%" align="right" valign="top" class="summary"> <span class="summary-type"><code class="link">tuple</code></span> </td><td class="summary"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <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 /> Return the attributes as a markup event.</td> <td align="right" valign="top"> </td> </tr> </table> </td> </tr> <tr> <td colspan="2" class="summary"> <p class="indent-wrapped-lines"><b>Inherited from <code>tuple</code></b>: <code>__add__</code>, <code>__eq__</code>, <code>__ge__</code>, <code>__getattribute__</code>, <code>__getitem__</code>, <code>__getnewargs__</code>, <code>__gt__</code>, <code>__hash__</code>, <code>__iter__</code>, <code>__le__</code>, <code>__len__</code>, <code>__lt__</code>, <code>__mul__</code>, <code>__ne__</code>, <code>__new__</code>, <code>__rmul__</code> </p> <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>: <code>__delattr__</code>, <code>__init__</code>, <code>__reduce__</code>, <code>__reduce_ex__</code>, <code>__setattr__</code>, <code>__str__</code> </p> </td> </tr> </table> <!-- ==================== PROPERTIES ==================== --> <a name="section-Properties"></a> <table class="summary" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white"> <tr bgcolor="#70b0f0" class="table-header"> <td align="left" colspan="2" class="table-header"> <span class="table-header">Properties</span></td> </tr> <tr> <td colspan="2" class="summary"> <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>: <code>__class__</code> </p> </td> </tr> </table> <!-- ==================== METHOD DETAILS ==================== --> <a name="section-MethodDetails"></a> <table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white"> <tr bgcolor="#70b0f0" class="table-header"> <td align="left" colspan="2" class="table-header"> <span class="table-header">Method Details</span></td> </tr> </table> <a name="__contains__"></a> <div> <table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white"> <tr><td> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr valign="top"><td> <h3 class="epydoc"><span class="sig"><span class="sig-name">__contains__</span>(<span class="sig-arg">self</span>, <span class="sig-arg">name</span>)</span> <br /><em class="fname">(In operator)</em> </h3> </td><td align="right" valign="top" > </td> </tr></table> Return whether the list includes an attribute with the specified name. <dl class="fields"> <dt>Returns: <code class="link">bool</code></dt> <dd><code class="link">True</code> if the list includes the attribute</dd> <dt>Overrides: tuple.__contains__ </dt> </dl> </td></tr></table> </div> <a name="__getslice__"></a> <div> <table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white"> <tr><td> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr valign="top"><td> <h3 class="epydoc"><span class="sig"><span class="sig-name">__getslice__</span>(<span class="sig-arg">self</span>, <span class="sig-arg">i</span>, <span class="sig-arg">j</span>)</span> <br /><em class="fname">(Slicling operator)</em> </h3> </td><td align="right" valign="top" > </td> </tr></table> <p>Return a slice of the attributes list.</p> <pre class="py-doctest"> <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>)]) <span class="py-prompt">>>> </span>attrs[1:] <span class="py-output">Attrs([('title', 'Foo')])</span></pre> <dl class="fields"> <dt>Overrides: tuple.__getslice__ </dt> </dl> </td></tr></table> </div> <a name="__or__"></a> <div> <table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white"> <tr><td> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr valign="top"><td> <h3 class="epydoc"><span class="sig"><span class="sig-name">__or__</span>(<span class="sig-arg">self</span>, <span class="sig-arg">attrs</span>)</span> <br /><em class="fname">(Or operator)</em> </h3> </td><td align="right" valign="top" > </td> </tr></table> Return a new instance that contains the attributes in <code class="link">attrs</code> in addition to any already existing attributes. <dl class="fields"> <dt>Returns: <a href="genshi.core.Attrs-class.html" class="link">Attrs</a></dt> <dd>a new instance with the merged attributes</dd> </dl> </td></tr></table> </div> <a name="__repr__"></a> <div> <table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white"> <tr><td> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr valign="top"><td> <h3 class="epydoc"><span class="sig"><span class="sig-name">__repr__</span>(<span class="sig-arg">self</span>)</span> <br /><em class="fname">(Representation operator)</em> </h3> </td><td align="right" valign="top" > </td> </tr></table> repr(x) <dl class="fields"> <dt>Overrides: object.__repr__ <dd><em class="note">(inherited documentation)</em></dd> </dt> </dl> </td></tr></table> </div> <a name="__sub__"></a> <div> <table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white"> <tr><td> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr valign="top"><td> <h3 class="epydoc"><span class="sig"><span class="sig-name">__sub__</span>(<span class="sig-arg">self</span>, <span class="sig-arg">names</span>)</span> <br /><em class="fname">(Subtraction operator)</em> </h3> </td><td align="right" valign="top" > </td> </tr></table> Return a new instance with all attributes with a name in <code class="link">names</code> are removed. <dl class="fields"> <dt>Parameters:</dt> <dd><ul class="nomargin-top"> <li><strong class="pname"><code>names</code></strong> - the names of the attributes to remove</li> </ul></dd> <dt>Returns: <a href="genshi.core.Attrs-class.html" class="link">Attrs</a></dt> <dd>a new instance with the attribute removed</dd> </dl> </td></tr></table> </div> <a name="get"></a> <div> <table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white"> <tr><td> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr valign="top"><td> <h3 class="epydoc"><span class="sig"><span class="sig-name">get</span>(<span class="sig-arg">self</span>, <span class="sig-arg">name</span>, <span class="sig-arg">default</span>=<span class="sig-default">None</span>)</span> </h3> </td><td align="right" valign="top" > </td> </tr></table> Return the value of the attribute with the specified name, or the value of the <code class="link">default</code> parameter if no such attribute is found. <dl class="fields"> <dt>Parameters:</dt> <dd><ul class="nomargin-top"> <li><strong class="pname"><code>name</code></strong> - the name of the attribute</li> <li><strong class="pname"><code>default</code></strong> - the value to return when the attribute does not exist</li> </ul></dd> <dt>Returns: <code class="link">object</code></dt> <dd>the attribute value, or the <code class="link">default</code> value if that attribute does not exist</dd> </dl> </td></tr></table> </div> <a name="totuple"></a> <div> <table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white"> <tr><td> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr valign="top"><td> <h3 class="epydoc"><span class="sig"><span class="sig-name">totuple</span>(<span class="sig-arg">self</span>)</span> </h3> </td><td align="right" valign="top" > </td> </tr></table> <p>Return the attributes as a markup event.</p> <p>The returned event is a <a href="genshi.core-module.html#TEXT" class="link" onclick="show_private();">TEXT</a> event, the data is the value of all attributes joined together.</p> <pre class="py-doctest"> <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() <span class="py-output">('TEXT', u'#Foo', (None, -1, -1))</span></pre> <dl class="fields"> <dt>Returns: <code class="link">tuple</code></dt> <dd>a <a href="genshi.core-module.html#TEXT" class="link" onclick="show_private();">TEXT</a> event</dd> </dl> </td></tr></table> </div> <br /> <!-- ==================== NAVIGATION BAR ==================== --> <table class="navbar" border="0" width="100%" cellpadding="0" bgcolor="#a0c0ff" cellspacing="0"> <tr valign="middle"> <!-- Home link --> <th> <a href="genshi-module.html">Home</a> </th> <!-- Tree link --> <th> <a href="module-tree.html">Trees</a> </th> <!-- Index link --> <th> <a href="identifier-index.html">Indices</a> </th> <!-- Help link --> <th> <a href="help.html">Help</a> </th> <!-- Project homepage --> <th class="navbar" align="right" width="100%"> <table border="0" cellpadding="0" cellspacing="0"> <tr><th class="navbar" align="center" ><a class="navbar" target="_top" href="../index.html">Documentation Index</a></th> </tr></table></th> </tr> </table> <table border="0" cellpadding="0" cellspacing="0" width="100%%"> <tr> <td align="left" class="footer"> Generated by Epydoc 3.0.1 on Wed Jul 9 18:16:20 2008 </td> <td align="right" class="footer"> <a target="mainFrame" href="http://epydoc.sourceforge.net" >http://epydoc.sourceforge.net</a> </td> </tr> </table> <script type="text/javascript"> <!-- // Private objects are initially displayed (because if // javascript is turned off then we want them to be // visible); but by default, we want to hide them. So hide // them unless we have a cookie that says to show them. checkCookie(); // --> </script> </body> </html>