~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to doc/howto/plugin.html

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-17 14:52:35 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20070117145235-btmig6qfmqfen0om
Tags: 2.5.0-0ubuntu1
New upstream version, compatible with python2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><title>Twisted Documentation: The Twisted Plugin System</title><link href="../howto/stylesheet.css" type="text/css" rel="stylesheet" /></head><body bgcolor="white"><h1 class="title">The Twisted Plugin System</h1><div class="toc"><ol><li><a href="#auto0">Writing Extensible Programs</a></li><li><a href="#auto1">Extending an Existing Program</a></li><li><a href="#auto2">Alternate Plugin Packages</a></li><li><a href="#auto3">Plugin Caching</a></li></ol></div><div class="content"><span></span><p>The purpose of this guide is to describe the preferred way to
 
2
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><title>Twisted Documentation: The Twisted Plugin System</title><link href="../howto/stylesheet.css" type="text/css" rel="stylesheet" /></head><body bgcolor="white"><h1 class="title">The Twisted Plugin System</h1><div class="toc"><ol><li><a href="#auto0">Writing Extensible Programs</a></li><li><a href="#auto1">Extending an Existing Program</a></li><li><a href="#auto2">Alternate Plugin Packages</a></li><li><a href="#auto3">Plugin Caching</a></li><li><a href="#auto4">Further Reading</a></li></ol></div><div class="content"><span></span><p>The purpose of this guide is to describe the preferred way to
3
3
    write extensible Twisted applications (and consequently, also to
4
4
    describe how to extend applications written in such a way).  This
5
5
    extensibility is achieved through the definition of one or more
13
13
      run, or re-discovered each time the program starts up, or they
14
14
      can be polled for repeatedly at runtime (allowing the discovery
15
15
      of new plugins installed after the program has started).</li></ul><h2>Writing Extensible Programs<a name="auto0"></a></h2><p>Taking advantage of <code class="API">twisted.plugin</code> is
16
 
    a two step process:</p><ol><li>Define an interface which plugins will be required to
17
 
      implement.  This is done using the <code class="API">zope.interface</code> package in the same way one
18
 
      would define an interface for any other purpose.</li><li>At one or more places in your program, invoke <code class="API">twisted.plugin.getPlugins</code> and iterate over
19
 
      its result.</li></ol><p>As an example of the first step, consider the following
20
 
    interface definition for a physical modelling system.</p><pre class="python">
 
16
    a two step process:</p><ol><li><p>
 
17
        Define an interface which plugins will be required to implement. 
 
18
        This is done using the <code class="API">zope.interface</code>
 
19
        package in the same way one would define an interface for any other
 
20
        purpose.
 
21
        </p><p>
 
22
        A convention for defining interfaces is do so in a file named like
 
23
        <em>ProjectName/projectname/iprojectname.py</em>.  The rest of this
 
24
        document will follow that convention: consider the following
 
25
        interface definition be in <code>Matsim/matsim/imatsim.py</code>, an
 
26
        interface definition module for a hypothetical material simulation
 
27
        package.
 
28
        </p></li><li>
 
29
      At one or more places in your program, invoke <code class="API">twisted.plugin.getPlugins</code> and iterate over its
 
30
      result.
 
31
      </li></ol><p>
 
32
    As an example of the first step, consider the following interface
 
33
    definition for a physical modelling system.
 
34
    </p><pre class="python">
21
35
<span class="py-src-keyword">from</span> <span class="py-src-variable">zope</span>.<span class="py-src-variable">interface</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">Interface</span>, <span class="py-src-variable">Attribute</span>
22
36
 
23
37
<span class="py-src-keyword">class</span> <span class="py-src-identifier">IMaterial</span>(<span class="py-src-parameter">Interface</span>):
74
88
        <span class="py-src-variable">self</span>.<span class="py-src-variable">dielectricConstant</span> = <span class="py-src-variable">dielectricConstant</span>
75
89
 
76
90
    <span class="py-src-keyword">def</span> <span class="py-src-identifier">yieldStress</span>(<span class="py-src-parameter">self</span>, <span class="py-src-parameter">temperature</span>):
77
 
        <span class="py-src-keyword">return</span> <span class="py-src-variable">self</span>.<span class="py-src-variable">_yieldStressFactory</span> * <span class="py-src-variable">temperature</span>
 
91
        <span class="py-src-keyword">return</span> <span class="py-src-variable">self</span>.<span class="py-src-variable">_yieldStressFactor</span> * <span class="py-src-variable">temperature</span>
78
92
 
79
93
<span class="py-src-variable">steelPlate</span> = <span class="py-src-variable">SimpleMaterial</span>(<span class="py-src-number">2.06842719e11</span>, <span class="py-src-number">2.7</span> + <span class="py-src-number">0.2j</span>)
80
94
<span class="py-src-variable">brassPlate</span> = <span class="py-src-variable">SimpleMaterial</span>(<span class="py-src-number">1.03421359e11</span>, <span class="py-src-number">1.4</span> + <span class="py-src-number">0.5j</span>)
136
150
<span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">plugin</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">IPlugin</span>, <span class="py-src-variable">getPlugin</span>
137
151
<span class="py-src-variable">list</span>(<span class="py-src-variable">getPlugin</span>(<span class="py-src-variable">IPlugin</span>))
138
152
</pre><p>As mentioned, it is normal for exceptions to be raised
139
 
    <strong>once</strong> here if plugins have been removed.</p></div><p><a href="../howto/index.html">Index</a></p><span class="version">Version: 2.4.0</span></body></html>
 
 
b'\\ No newline at end of file'
 
153
    <strong>once</strong> here if plugins have been removed.</p><h2>Further Reading<a name="auto4"></a></h2><ul><li><a href="components.html">Components: Interfaces and Adapters</a></li></ul></div><p><a href="../howto/index.html">Index</a></p><span class="version">Version: 2.5.0</span></body></html>
 
 
b'\\ No newline at end of file'