Source

nose3 / doc / plugin_attrib.html

Full commit
<html>
  <head>
    <title>nose: builtin plugin: attrib</title>
    <link rel="stylesheet" href="site.css" type="text/css"></link>
  </head>
  <body>
    
    <div id="menu">
      <p>This document covers nose version <b>0.10.1</b></p>
      <p>Last update: <b>Fri Jan  4 10:06:23 2008</b></p>
      <h2>Plugins</h2><ul><li><a href="plugin_attrib.html">Builtin Plugin: attrib</a></li><li><a href="plugin_capture.html">Builtin Plugin: capture</a></li><li><a href="plugin_cover.html">Builtin Plugin: cover</a></li><li><a href="plugin_debug.html">Builtin Plugin: debug</a></li><li><a href="plugin_deprecated.html">Builtin Plugin: deprecated</a></li><li><a href="plugin_doctests.html">Builtin Plugin: doctests</a></li><li><a href="plugin_failuredetail.html">Builtin Plugin: failuredetail</a></li><li><a href="plugin_isolate.html">Builtin Plugin: isolate</a></li><li><a href="plugin_prof.html">Builtin Plugin: prof</a></li><li><a href="plugin_skip.html">Builtin Plugin: skip</a></li><li><a href="plugin_testid.html">Builtin Plugin: testid</a></li><li><a href="error_class_plugin.html">ErrorClass Plugins</a></li><li><a href="plugin_interface.html">Plugin Interface</a></li><li><a href="writing_plugins.html">Writing Plugins</a></li></ul><h2>Modules</h2><ul><li><a href="module_nose.case.html">Module: nose.case</a></li><li><a href="module_nose.commands.html">Module: nose.commands</a></li><li><a href="module_nose.config.html">Module: nose.config</a></li><li><a href="module_nose.core.html">Module: nose.core</a></li><li><a href="module_nose.exc.html">Module: nose.exc</a></li><li><a href="module_nose.importer.html">Module: nose.importer</a></li><li><a href="module_nose.inspector.html">Module: nose.inspector</a></li><li><a href="module_nose.loader.html">Module: nose.loader</a></li><li><a href="module_nose.plugins.manager.html">Module: nose.plugins.manager</a></li><li><a href="module_nose.plugins.plugintest.html">Module: nose.plugins.plugintest</a></li><li><a href="module_nose.proxy.html">Module: nose.proxy</a></li><li><a href="module_nose.result.html">Module: nose.result</a></li><li><a href="module_nose.selector.html">Module: nose.selector</a></li><li><a href="module_nose.suite.html">Module: nose.suite</a></li><li><a href="module_nose.tools.html">Module: nose.tools</a></li><li><a href="module_nose.twistedtools.html">Module: nose.twistedtools</a></li><li><a href="module_nose.util.html">Module: nose.util</a></li></ul><h2>Plugin Examples</h2><ul><li><a href="unwanted_package.html">Excluding Unwanted Packages</a></li><li><a href="empty_plugin.html">Minimal plugin</a></li><li><a href="init_plugin.html">Running Initialization Code Before the Test Run</a></li><li><a href="selector_plugin.html">Using a Custom Selector</a></li><li><a href="plugin_exceptions.html">When Plugins Fail</a></li><li><a href="plugintest_environment.html">nose.plugins.plugintest, os.environ and sys.argv</a></li></ul>
    </div>
    
    <div id="main">
      <h1>nose: builtin plugin: attrib</h1>
      
      <p>Attribute selector plugin.</p>
<p>Simple syntax (-a, --attr) examples:</p>
<ul>
<li><dl class="first docutils">
<dt><cite>nosetests -a status=stable</cite>:</dt>
<dd><p class="first last">Only test cases with attribute &quot;status&quot; having value &quot;stable&quot;</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><cite>nosetests -a priority=2,status=stable</cite>:</dt>
<dd><p class="first last">Both attributes must match</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><cite>nosetests -a priority=2 -a slow</cite>:</dt>
<dd><p class="first last">Either attribute must match</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><cite>nosetests -a tags=http</cite>:</dt>
<dd><p class="first last">Attribute list &quot;tags&quot; must contain value &quot;http&quot; (see test_foobar()
below for definition)</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><cite>nosetests -a slow</cite>:</dt>
<dd><p class="first last">Attribute &quot;slow&quot; must be defined and its value cannot equal to False
(False, [], &quot;&quot;, etc...)</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><cite>nosetests -a !slow</cite>:</dt>
<dd><p class="first last">Attribute &quot;slow&quot; must NOT be defined or its value must be equal to False</p>
</dd>
</dl>
</li>
</ul>
<p>Eval expression syntax (-A, --eval-attr) examples:</p>
<ul class="simple">
<li><cite>nosetests -A &quot;not slow&quot;</cite></li>
<li><cite>nosetests -A &quot;(priority &gt; 5) and not slow&quot;</cite></li>
</ul>


      <h2>Plugin Methods Implemented</h2>

      <p>This plugin implements the following plugin interface methods:</p>
      
      <ul><li><a href="plugin_interface.html#configure">configure</a></li><li><a href="plugin_interface.html#options">options</a></li><li><a href="plugin_interface.html#wantClass">wantClass</a></li><li><a href="plugin_interface.html#wantFunction">wantFunction</a></li><li><a href="plugin_interface.html#wantMethod">wantMethod</a></li></ul>


      <h2>Commandline Options</h2>

      <p>This plugin adds the following commandline options:</p>

      <pre>Options:
  -a ATTR, --attr=ATTR  Run only tests that have attributes specified by ATTR
                        [NOSE_ATTR]
  -A EXPR, --eval-attr=EXPR
                        Run only tests for whose attributes the Python
                        expression EXPR evaluates to True [NOSE_EVAL_ATTR]
</pre>

      <h2>Source</h2>

      <div class="highlight"><pre><span class="sd">&quot;&quot;&quot;Attribute selector plugin.</span>

<span class="sd">Simple syntax (-a, --attr) examples:</span>

<span class="sd">* `nosetests -a status=stable`:</span>
<span class="sd">   Only test cases with attribute &quot;status&quot; having value &quot;stable&quot;</span>

<span class="sd">* `nosetests -a priority=2,status=stable`:</span>
<span class="sd">   Both attributes must match</span>

<span class="sd">* `nosetests -a priority=2 -a slow`:</span>
<span class="sd">   Either attribute must match</span>
<span class="sd">    </span>
<span class="sd">* `nosetests -a tags=http`:</span>
<span class="sd">   Attribute list &quot;tags&quot; must contain value &quot;http&quot; (see test_foobar()</span>
<span class="sd">   below for definition)</span>

<span class="sd">* `nosetests -a slow`:</span>
<span class="sd">   Attribute &quot;slow&quot; must be defined and its value cannot equal to False</span>
<span class="sd">   (False, [], &quot;&quot;, etc...)</span>

<span class="sd">* `nosetests -a !slow`:</span>
<span class="sd">   Attribute &quot;slow&quot; must NOT be defined or its value must be equal to False</span>

<span class="sd">Eval expression syntax (-A, --eval-attr) examples:</span>

<span class="sd">* `nosetests -A &quot;not slow&quot;`</span>

<span class="sd">* `nosetests -A &quot;(priority &gt; 5) and not slow&quot;`</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="k">import</span> <span class="nn">logging</span>
<span class="k">import</span> <span class="nn">os</span>
<span class="k">import</span> <span class="nn">sys</span>
<span class="k">from</span> <span class="nn">inspect</span> <span class="k">import</span> <span class="n">isfunction</span>
<span class="k">from</span> <span class="nn">nose.plugins.base</span> <span class="k">import</span> <span class="n">Plugin</span>
<span class="k">from</span> <span class="nn">nose.util</span> <span class="k">import</span> <span class="n">tolist</span>

<span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s">&#39;nose.plugins.attrib&#39;</span><span class="p">)</span>
<span class="n">compat_24</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span> <span class="o">&gt;=</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">ContextHelper</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;Returns default values for dictionary lookups.&quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">obj</span> <span class="o">=</span> <span class="n">obj</span>
        
    <span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">obj</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>


<span class="k">class</span> <span class="nc">AttributeGetter</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;Helper for looking up attributes</span>
<span class="sd">    </span>
<span class="sd">    First we check the method, and if the attribute is not present,</span>
<span class="sd">    we check the method&#39;s class.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">missing</span> <span class="o">=</span> <span class="nb">object</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cls</span><span class="p">,</span> <span class="n">method</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cls</span> <span class="o">=</span> <span class="n">cls</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="n">method</span>

    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;Get </span><span class="si">%s</span><span class="s"> from </span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cls</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span><span class="p">)</span>
        <span class="n">val</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span><span class="o">.</span><span class="n">__dict__</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">missing</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">val</span> <span class="ow">is</span> <span class="bp">self</span><span class="o">.</span><span class="n">missing</span><span class="p">:</span>
            <span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;No attribute </span><span class="si">%s</span><span class="s"> in method, getting from class&#39;</span><span class="p">,</span>
                      <span class="n">name</span><span class="p">)</span>
            <span class="n">val</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cls</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">default</span><span class="p">)</span>
            <span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&#39;Class attribute </span><span class="si">%s</span><span class="s"> value: </span><span class="si">%s</span><span class="s">&#39;</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">val</span>

<span class="k">class</span> <span class="nc">AttributeSelector</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Selects test cases to be run based on their attributes.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">Plugin</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">attribs</span> <span class="o">=</span> <span class="p">[]</span>
    
    <span class="k">def</span> <span class="nf">options</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parser</span><span class="p">,</span> <span class="n">env</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add command-line options for this plugin.&quot;&quot;&quot;</span>

        <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;-a&quot;</span><span class="p">,</span> <span class="s">&quot;--attr&quot;</span><span class="p">,</span>
                          <span class="n">dest</span><span class="o">=</span><span class="s">&quot;attr&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s">&quot;append&quot;</span><span class="p">,</span>
                          <span class="n">default</span><span class="o">=</span><span class="n">env</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;NOSE_ATTR&#39;</span><span class="p">),</span>
                          <span class="n">help</span><span class="o">=</span><span class="s">&quot;Run only tests that have attributes &quot;</span>
                          <span class="s">&quot;specified by ATTR [NOSE_ATTR]&quot;</span><span class="p">)</span>
        <span class="c"># disable in &lt; 2.4: eval can&#39;t take needed args</span>
        <span class="k">if</span> <span class="n">compat_24</span><span class="p">:</span>
            <span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">&quot;-A&quot;</span><span class="p">,</span> <span class="s">&quot;--eval-attr&quot;</span><span class="p">,</span>
                              <span class="n">dest</span><span class="o">=</span><span class="s">&quot;eval_attr&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s">&quot;EXPR&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s">&quot;append&quot;</span><span class="p">,</span>
                              <span class="n">default</span><span class="o">=</span><span class="n">env</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;NOSE_EVAL_ATTR&#39;</span><span class="p">),</span>
                              <span class="n">help</span><span class="o">=</span><span class="s">&quot;Run only tests for whose attributes &quot;</span>
                              <span class="s">&quot;the Python expression EXPR evaluates &quot;</span>
                              <span class="s">&quot;to True [NOSE_EVAL_ATTR]&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">configure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">config</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Configure the plugin and system, based on selected options.</span>

<span class="sd">        attr and eval_attr may each be lists.</span>

<span class="sd">        self.attribs will be a list of lists of tuples. In that list, each</span>
<span class="sd">        list is a group of attributes, all of which must match for the rule to</span>
<span class="sd">        match.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">attribs</span> <span class="o">=</span> <span class="p">[]</span>
        
        <span class="c"># handle python eval-expression parameter</span>
        <span class="k">if</span> <span class="n">compat_24</span> <span class="ow">and</span> <span class="n">options</span><span class="o">.</span><span class="n">eval_attr</span><span class="p">:</span>
            <span class="n">eval_attr</span> <span class="o">=</span> <span class="n">tolist</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">eval_attr</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">attr</span> <span class="ow">in</span> <span class="n">eval_attr</span><span class="p">:</span>
                <span class="c"># &quot;&lt;python expression&gt;&quot;</span>
                <span class="c"># -&gt; eval(expr) in attribute context must be True</span>
                <span class="k">def</span> <span class="nf">eval_in_context</span><span class="p">(</span><span class="n">expr</span><span class="p">,</span> <span class="n">attribs</span><span class="p">):</span>
                    <span class="k">return</span> <span class="nb">eval</span><span class="p">(</span><span class="n">expr</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="n">ContextHelper</span><span class="p">(</span><span class="n">attribs</span><span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">attribs</span><span class="o">.</span><span class="n">append</span><span class="p">([(</span><span class="n">attr</span><span class="p">,</span> <span class="n">eval_in_context</span><span class="p">)])</span>

        <span class="c"># attribute requirements are a comma separated list of</span>
        <span class="c"># &#39;key=value&#39; pairs</span>
        <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">attr</span><span class="p">:</span>
            <span class="n">std_attr</span> <span class="o">=</span> <span class="n">tolist</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">attr</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">attr</span> <span class="ow">in</span> <span class="n">std_attr</span><span class="p">:</span>
                <span class="c"># all attributes within an attribute group must match</span>
                <span class="n">attr_group</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">attrib</span> <span class="ow">in</span> <span class="n">attr</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&quot;,&quot;</span><span class="p">):</span>
                    <span class="c"># don&#39;t die on trailing comma</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">attrib</span><span class="p">:</span>
                        <span class="k">continue</span>
                    <span class="n">items</span> <span class="o">=</span> <span class="n">attrib</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&quot;=&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">items</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                        <span class="c"># &quot;name=value&quot;</span>
                        <span class="c"># -&gt; &#39;str(obj.name) == value&#39; must be True</span>
                        <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">items</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">key</span> <span class="o">=</span> <span class="n">items</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                        <span class="k">if</span> <span class="n">key</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;!&quot;</span><span class="p">:</span>
                            <span class="c"># &quot;!name&quot;</span>
                            <span class="c"># &#39;bool(obj.name)&#39; must be False</span>
                            <span class="n">key</span> <span class="o">=</span> <span class="n">key</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
                            <span class="n">value</span> <span class="o">=</span> <span class="bp">False</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="c"># &quot;name&quot;</span>
                            <span class="c"># -&gt; &#39;bool(obj.name)&#39; must be True</span>
                            <span class="n">value</span> <span class="o">=</span> <span class="bp">True</span>
                    <span class="n">attr_group</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">attribs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">attr_group</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">attribs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">enabled</span> <span class="o">=</span> <span class="bp">True</span>
            
    <span class="k">def</span> <span class="nf">validateAttrib</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attribs</span><span class="p">):</span>
        <span class="c"># TODO: is there a need for case-sensitive value comparison?</span>
        <span class="c"># within each group, all must match for the group to match</span>
        <span class="c"># if any group matches, then the attribute set as a whole</span>
        <span class="c"># has matched</span>
        <span class="n">any</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">for</span> <span class="n">group</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">attribs</span><span class="p">:</span>
            <span class="n">match</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">group</span><span class="p">:</span>
                <span class="n">obj_value</span> <span class="o">=</span> <span class="n">attribs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
                <span class="k">if</span> <span class="nb">callable</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">value</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">attribs</span><span class="p">):</span>
                        <span class="n">match</span> <span class="o">=</span> <span class="bp">False</span>
                        <span class="k">break</span>
                <span class="k">elif</span> <span class="n">value</span> <span class="ow">is</span> <span class="bp">True</span><span class="p">:</span>
                    <span class="c"># value must exist and be True</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="nb">bool</span><span class="p">(</span><span class="n">obj_value</span><span class="p">):</span>
                        <span class="n">match</span> <span class="o">=</span> <span class="bp">False</span>
                        <span class="k">break</span>
                <span class="k">elif</span> <span class="n">value</span> <span class="ow">is</span> <span class="bp">False</span><span class="p">:</span>
                    <span class="c"># value must not exist or be False</span>
                    <span class="k">if</span> <span class="nb">bool</span><span class="p">(</span><span class="n">obj_value</span><span class="p">):</span>
                        <span class="n">match</span> <span class="o">=</span> <span class="bp">False</span>
                        <span class="k">break</span>
                <span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">obj_value</span><span class="p">)</span> <span class="ow">in</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">):</span>
                    <span class="c"># value must be found in the list attribute</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="n">value</span> <span class="ow">in</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">obj_value</span><span class="p">]:</span>
                        <span class="n">match</span> <span class="o">=</span> <span class="bp">False</span>
                        <span class="k">break</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="c"># value must match, convert to string and compare</span>
                    <span class="k">if</span> <span class="p">(</span><span class="n">value</span> <span class="o">!=</span> <span class="n">obj_value</span>
                        <span class="ow">and</span> <span class="nb">str</span><span class="p">(</span><span class="n">value</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">!=</span> <span class="nb">str</span><span class="p">(</span><span class="n">obj_value</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()):</span>
                        <span class="n">match</span> <span class="o">=</span> <span class="bp">False</span>
                        <span class="k">break</span>
            <span class="n">any</span> <span class="o">=</span> <span class="n">any</span> <span class="ow">or</span> <span class="n">match</span>
        <span class="k">if</span> <span class="n">any</span><span class="p">:</span>
            <span class="c"># not True because we don&#39;t want to FORCE the selection of the</span>
            <span class="c"># item, only say that it is acceptable</span>
            <span class="k">return</span> <span class="bp">None</span>
        <span class="k">return</span> <span class="bp">False</span>

    <span class="k">def</span> <span class="nf">wantClass</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cls</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Accept the class if the class or any method is wanted.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cls_attr</span> <span class="o">=</span> <span class="n">cls</span><span class="o">.</span><span class="n">__dict__</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">validateAttrib</span><span class="p">(</span><span class="n">cls_attr</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">False</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span>
        <span class="c"># Methods in __dict__.values() are functions, oddly enough.</span>
        <span class="n">methods</span> <span class="o">=</span> <span class="nb">filter</span><span class="p">(</span><span class="n">isfunction</span><span class="p">,</span> <span class="n">cls_attr</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
        <span class="n">wanted</span> <span class="o">=</span> <span class="nb">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">m</span><span class="p">:</span> <span class="n">m</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">False</span><span class="p">,</span>
                        <span class="nb">map</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">wantFunction</span><span class="p">,</span> <span class="n">methods</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">wanted</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span>
        <span class="k">return</span> <span class="bp">False</span>
        
    <span class="k">def</span> <span class="nf">wantFunction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">function</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">validateAttrib</span><span class="p">(</span><span class="n">function</span><span class="o">.</span><span class="n">__dict__</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">wantMethod</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">method</span><span class="p">):</span>
        <span class="n">attribs</span> <span class="o">=</span> <span class="n">AttributeGetter</span><span class="p">(</span><span class="n">method</span><span class="o">.</span><span class="n">im_class</span><span class="p">,</span> <span class="n">method</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">validateAttrib</span><span class="p">(</span><span class="n">attribs</span><span class="p">)</span>
</pre></div>


    </div>
    <script src="http://www.google-analytics.com/urchin.js" 
	    type="text/javascript">
    </script>
    <script type="text/javascript">
      _uacct = "UA-2236166-1";
      urchinTracker();
    </script>
  </body>
</html>