twisted.flow.wrap.html   [plain text]


<?xml version="1.0" encoding="iso-8859-1"?>
<!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>twisted.flow.wrap</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css"></link>
</head>
<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">

<!-- =========== START OF NAVBAR =========== -->
<table class="navbar" border="0" width="100%" cellpadding="0" bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="center">
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="twisted.html">Home</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="trees.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="indices.html">Index</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar" align="right" width="100%">
      <table border="0" cellpadding="0" cellspacing="0">
      <tr><th class="navbar" align="center">
        <p class="nomargin">
          <a class="navbar" target="_top" href="http://twistedmatrix.com/">Twisted&nbsp;1.3.0rc1</a>
      </p></th></tr></table>
    </th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <font size="-1"><b class="breadcrumbs">
        <a href="twisted.html">Package&nbsp;twisted</a> ::
        <a href="twisted.flow.html">Package&nbsp;flow</a> ::
        Module&nbsp;wrap
      </b></font></br>
    </td>
    <td><table cellpadding="0" cellspacing="0">
      <tr><td align="right"><font size="-2">[<a href="frames.html"target="_top">frames</a>&nbsp;|&nbsp;<a href="twisted.flow.wrap.html" target="_top">no&nbsp;frames</a>]</font></td></tr>
    </table></td>
</tr></table>

<!-- =========== START OF MODULE DESCRIPTION =========== -->
<h2 class="module">Module twisted.flow.wrap</h2>

<p>flow.wrap</p>
This module provides the wrap() function in the flow module and the 
private classes used for its implementation.
<hr/>

<!-- =========== START OF CLASSES =========== -->
<table class="summary" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="summary">
  <th colspan="2">Classes</th></tr>
<tr><td width="15%">
  <b><a href="twisted.flow.wrap._Deferred.html"><code>_Deferred</code></a></b></td>
  <td>Wraps a Deferred object into a stage; create with flow.wrap</td></tr>
<tr><td width="15%">
  <b><a href="twisted.flow.wrap._DeferredInstruction.html"><code>_DeferredInstruction</code></a></b></td>
  <td>&nbsp;</td></tr>
<tr><td width="15%">
  <b><a href="twisted.flow.wrap._Iterable.html"><code>_Iterable</code></a></b></td>
  <td>Wrapper for iterable objects, pass in a next() function</td></tr>
<tr><td width="15%">
  <b><a href="twisted.flow.wrap._List.html"><code>_List</code></a></b></td>
  <td>Wrapper for lists and tuple objects; don't create directly</td></tr>
<tr><td width="15%">
  <b><a href="twisted.flow.wrap._String.html"><code>_String</code></a></b></td>
  <td>Wrapper for a string object; don't create directly use flow.wrap</td></tr>
</table><br />


<!-- =========== START OF FUNCTION SUMMARY =========== -->
<table class="summary" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="summary">
  <th colspan="2">Function Summary</th></tr>
<tr><td align="right" valign="top" width="15%"><font size="-1">&nbsp;</font></td>
  <td><code><span class="summary-sig"><a href="twisted.flow.wrap.html#wrap" class="summary-sig-name"><code>wrap</code></a>(<span class=summary-sig-arg>obj</span>,
          <span class="summary-sig-vararg">*trap</span>)</span></code>
<br />
Wraps various objects for use within a flow

The following example illustrates many different
ways in which regular objects can be wrapped by
the flow module to behave in a cooperative manner.</td></tr>
</table><br />


<!-- =========== START OF FUNCTION DETAILS =========== -->
<table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="details">
  <th colspan="2">Function Details</th></tr>
</table>

<a name="wrap"></a>
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
  <h3><span class="sig"><span class="sig-name">wrap</span>(<span class=sig-arg>obj</span>,
          <span class="sig-vararg">*trap</span>)</span>
  </h3>
<pre class="literalblock">
Wraps various objects for use within a flow

The following example illustrates many different
ways in which regular objects can be wrapped by
the flow module to behave in a cooperative manner.

    # required imports
    from __future__ import generators
    from twisted.flow import flow
    from twisted.internet import reactor, defer
    
    # save this function, it is used everwhere
    def printFlow(source):
        def printer(source):
            source = flow.wrap(source)
            while True:
                yield source
                print source.next()
        d = flow.Deferred(printer(source))
        d.addCallback(lambda _: reactor.stop())
        reactor.run()
  
    source = &quot;string&quot;
    printFlow(source)

    source = [&quot;one&quot;,flow.Cooperate(1),&quot;two&quot;]
    printFlow(source)

    def source():
        yield &quot;aeye&quot;
        yield flow.Cooperate()
        yield &quot;capin&quot;
    printFlow(source)

    source = Deferred()
    reactor.callLater(1, lambda: source.callback(&quot;howdy&quot;))
    printFlow(source)
</pre>
  <dl><dt></dt><dd>
  </dd></dl>
</td></tr></table>
<br />


<!-- =========== START OF NAVBAR =========== -->
<table class="navbar" border="0" width="100%" cellpadding="0" bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="center">
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="twisted.html">Home</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="trees.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="indices.html">Index</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar">&nbsp;&nbsp;&nbsp;<a class="navbar" href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>
    <th class="navbar" align="right" width="100%">
      <table border="0" cellpadding="0" cellspacing="0">
      <tr><th class="navbar" align="center">
        <p class="nomargin">
          <a class="navbar" target="_top" href="http://twistedmatrix.com/">Twisted&nbsp;1.3.0rc1</a>
      </p></th></tr></table>
    </th>
  </tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td align="left"><font size="-2">Generated by Epydoc 2.0 on Sat May 15 20:07:39 2004</font></td>
    <td align="right"><a href="http://epydoc.sourceforge.net"
                      ><font size="-2">http://epydoc.sf.net</font></a></td>
  </tr>
</table>
</body>
</html>