Sophie

Sophie

distrib > CentOS > 5 > i386 > by-pkgid > 90dba77ca23efa667b541b5c0dd77497 > files > 238

python-lxml-2.0.11-2.el5.i386.rpm

<?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>lxml.pyclasslookup</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>&nbsp;&nbsp;&nbsp;<a
        href="lxml-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</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="http://codespeak.net/lxml/">lxml API</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="lxml-module.html">Package&nbsp;lxml</a> ::
        Module&nbsp;pyclasslookup
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="lxml.pyclasslookup-module.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module pyclasslookup</h1><p class="nomargin-top"></p>
<p>A whole-tree Element class lookup scheme for <a href="lxml.etree-module.html" class="link">lxml.etree</a>.</p>
<p>This class lookup scheme allows access to the entire XML tree in
read-only mode.  To use it, let a class inherit from
<a href="lxml.pyclasslookup.PythonElementClassLookup-class.html" class="link">PythonElementClassLookup</a> and re-implement the <tt class="rst-docutils literal"><span class="pre">lookup(self,</span> <span class="pre">doc,</span>
<span class="pre">root)</span></tt> method:</p>
<blockquote>
<pre class="py-doctest">
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">from</span> lxml <span class="py-keyword">import</span> etree, pyclasslookup
<span class="py-prompt">&gt;&gt;&gt;</span>
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">class</span> <span class="py-defname">MyElementClass</span>(etree.ElementBase):
<span class="py-more">... </span>    honkey = True
<span class="py-more">...</span>
<span class="py-prompt">&gt;&gt;&gt; </span><span class="py-keyword">class</span> <span class="py-defname">MyLookup</span>(pyclasslookup.PythonElementClassLookup):
<span class="py-more">... </span>    <span class="py-keyword">def</span> <span class="py-defname">lookup</span>(self, doc, root):
<span class="py-more">... </span>        <span class="py-keyword">if</span> root.tag == <span class="py-string">&quot;sometag&quot;</span>:
<span class="py-more">... </span>            return MyElementClass
<span class="py-more">... </span>        <span class="py-keyword">else</span>:
<span class="py-more">... </span>            <span class="py-keyword">for</span> child <span class="py-keyword">in</span> root:
<span class="py-more">... </span>                <span class="py-keyword">if</span> child.tag == <span class="py-string">&quot;someothertag&quot;</span>:
<span class="py-more">... </span>                    return MyElementClass
<span class="py-more">... </span>        <span class="py-comment"># delegate to default</span>
<span class="py-more">... </span>        return None</pre>
</blockquote>
<p>Note that the API of the Element objects is not complete.  It is
purely read-only and does not support all features of the normal
<a href="lxml.etree-module.html" class="link">lxml.etree</a> API (such as XPath, extended slicing or some iteration
methods).</p>
<p>Also, you cannot wrap such a read-only Element in an ElementTree, and
you must take care not to keep a reference to them outside of the
<code class="link">lookup()</code> method.</p>
<p>See <a class="rst-reference" href="http://codespeak.net/lxml/element_classes.html" target="_top">http://codespeak.net/lxml/element_classes.html</a></p>

<hr />
<div class="fields">      <p><strong>Version:</strong>
        2.0.10-60473
      </p>
</div><!-- ==================== CLASSES ==================== -->
<a name="section-Classes"></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">Classes</span></td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="lxml.pyclasslookup.PythonElementClassLookup-class.html" class="summary-name">PythonElementClassLookup</a><br />
      PythonElementClassLookup(self, fallback=None)
Element class lookup based on a subclass method.
    </td>
  </tr>
</table>
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="lxml-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</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="http://codespeak.net/lxml/">lxml API</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 on Fri Dec 12 22:40:29 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>