The PEAK Developers' Center   Diff for "TwistedPeak" UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View
Ignore changes in the amount of whitespace

Differences between version dated 2005-03-27 01:19:45 and 2007-03-26 18:24:48 (spanning 6 versions)

Deletions are marked like this.
Additions are marked like this.

Getting Started
---------------
 
PEAK and Twisted work very well together thanks to the the peak.commands.EventDriven class, a top level container for reactor-based applications. The following shows an XML-RPC server based on Twisted's XML-RPC HOWTO__::
PEAK and Twisted work very well together thanks to the the
peak.commands.EventDriven class, a top level container for
reactor-based applications. The following shows an XML-RPC server
based on Twisted's XML-RPC HOWTO__::
 
    from peak.api import binding, commands, running
    from twisted.web import xmlrpc, server

 
__ http://twistedmatrix.com/projects/web/documentation/howto/xmlrpc.html
 
The Example class is lifted verbatim from the HOWTO. Note how the Twisted reactor is obtained in the App class, and how the __onStart method tells the reactor to listen with the given server object and port number.
The Example class is lifted verbatim from the HOWTO. Note how the
Twisted reactor is obtained in the App class, and how the __onStart
method tells the reactor to listen with the given server object and
port number.
 
If saved in a file called '''twist_it.py''', this code can be run as follows (on Unix/Linux systems)::
If saved in a file called ``twistedpeak.py``, this code can be run as
follows (on Unix/Linux systems)::
 
    PYTHONPATH=. peak import:twist_it.App
    PYTHONPATH=. peak import:twistedpeak.App
 
The example client code from the HOWTO works exactly the same::
 

    >>> s.add(1, 2)
    3
 
This code can be used as a starting point for any kind of Twisted application.
This code can be used as a starting point for any kind of Twisted
application.
 
Configuration
-------------
Configuration and Binding
-------------------------
 
TODO
The code above is slightly longer than the example shown in the HOWTO,
but because of PEAK's component-oriented features, especially its
configuration and binding facilities, it is much more flexible. Since
``commands.EventDriven`` is a descendent of PEAK's base component
class, the ``App`` class is also a component class. This primarily
means two things:
 
- instances of it can be located in a hierarchy of other components;
  components can find each other in various ways without needing to
  know anything about the structure of the application as a
  whole. This promotes loose coupling, which can lead to more flexible
  applications and more reusable code. Components can optionally
  "offer" their properties for use by other components in the system.
 
- component objects are easily configurable by various means,
  including external configuration files (.ini-style, ZConfig),
  internally via "property names", and through keyword parameters when
  directly instantiated.
 
A component hierarchy always has a "root" object. In our example the
root object is created by the ``peak`` script, which is installed to
an executable directory by PEAK's ``setup.py`` installer script. The
``peak`` script is a simple launcher which takes a URL-like recipe for
finding a "runnable" object to load and run.
 
...
 
Notes
-----
 
This page is a replacement for the one originally created by Joel Boehland in July 2003. Unfortunately his code examples were included in a separate tar archive which has since been lost. Without the code, config files, and shell scripts, the page was no longer usable.
This page is a replacement for the one originally created by Joel
Boehland in July 2003. Unfortunately his code examples were included
in a separate tar archive which has since been lost. Without the
code, config files, and shell scripts, the page was no longer usable.
 
-- John Landahl, March 2005.
{{{

PythonPowered
ShowText of this page
EditText of this page
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck