Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > aac008a726c21673c6c59aa2e521b8cb > files > 57

python-zope-event-4.3.0-3.mga7.noarch.rpm


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Class-based event handlers &#8212; zope.event 4.3.0 documentation</title>
    <link rel="stylesheet" href="_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/language_data.js"></script>
    
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Hacking on zope.event" href="hacking.html" />
    <link rel="prev" title="zope.event API Reference" href="api.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="hacking.html" title="Hacking on zope.event"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="api.html" title="zope.event API Reference"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">zope.event 4.3.0 documentation</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="class-based-event-handlers">
<h1>Class-based event handlers<a class="headerlink" href="#class-based-event-handlers" title="Permalink to this headline">ΒΆ</a></h1>
<p>A light-weight event-handler framework based on event classes is
provided by the <code class="docutils literal notranslate"><span class="pre">zope.event.classhandler</span></code> module.</p>
<p>Handlers are registered for event classes:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">zope.event.classhandler</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">MyEvent</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">handler1</span><span class="p">(</span><span class="n">event</span><span class="p">):</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;handler1 </span><span class="si">%r</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">event</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">zope</span><span class="o">.</span><span class="n">event</span><span class="o">.</span><span class="n">classhandler</span><span class="o">.</span><span class="n">handler</span><span class="p">(</span><span class="n">MyEvent</span><span class="p">,</span> <span class="n">handler1</span><span class="p">)</span>
</pre></div>
</div>
<p>Descriptor syntax:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nd">@zope</span><span class="o">.</span><span class="n">event</span><span class="o">.</span><span class="n">classhandler</span><span class="o">.</span><span class="n">handler</span><span class="p">(</span><span class="n">MyEvent</span><span class="p">)</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">handler2</span><span class="p">(</span><span class="n">event</span><span class="p">):</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;handler2 </span><span class="si">%r</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">event</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">MySubEvent</span><span class="p">(</span><span class="n">MyEvent</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">pass</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nd">@zope</span><span class="o">.</span><span class="n">event</span><span class="o">.</span><span class="n">classhandler</span><span class="o">.</span><span class="n">handler</span><span class="p">(</span><span class="n">MySubEvent</span><span class="p">)</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">handler3</span><span class="p">(</span><span class="n">event</span><span class="p">):</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;handler3 </span><span class="si">%r</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">event</span><span class="p">)</span>
</pre></div>
</div>
<p>Subscribers are called in class method-resolution order, so only
new-style event classes are supported, and then by order of registry.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">zope.event</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">zope</span><span class="o">.</span><span class="n">event</span><span class="o">.</span><span class="n">notify</span><span class="p">(</span><span class="n">MySubEvent</span><span class="p">())</span>
<span class="go">handler3 MySubEvent</span>
<span class="go">handler1 MySubEvent</span>
<span class="go">handler2 MySubEvent</span>
</pre></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="api.html"
                        title="previous chapter"><code class="docutils literal notranslate"><span class="pre">zope.event</span></code> API Reference</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="hacking.html"
                        title="next chapter">Hacking on <code class="docutils literal notranslate"><span class="pre">zope.event</span></code></a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/classhandler.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="hacking.html" title="Hacking on zope.event"
             >next</a> |</li>
        <li class="right" >
          <a href="api.html" title="zope.event API Reference"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">zope.event 4.3.0 documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2010, Zope Foundation and Contributors.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.3.
    </div>
  </body>
</html>