/usr/share/doc/python-werkzeug-doc/html/contrib/iterio.html is in python-werkzeug-doc 0.9.6+dfsg-1+deb8u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | <!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="Content-Type" content="text/html; charset=utf-8" />
<title>Iter IO — Werkzeug 0.9.6 documentation</title>
<link rel="stylesheet" href="../_static/werkzeug.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.9.6',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</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>
<link rel="top" title="Werkzeug 0.9.6 documentation" href="../index.html" />
<link rel="up" title="Contributed Modules" href="index.html" />
<link rel="next" title="Fixers" href="fixers.html" />
<link rel="prev" title="Extra Wrappers" href="wrappers.html" />
</head>
<body>
<div class="related">
<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="fixers.html" title="Fixers"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="wrappers.html" title="Extra Wrappers"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">Werkzeug 0.9.6 documentation</a> »</li>
<li><a href="index.html" accesskey="U">Contributed Modules</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-werkzeug.contrib.iterio">
<span id="iter-io"></span><h1>Iter IO<a class="headerlink" href="#module-werkzeug.contrib.iterio" title="Permalink to this headline">¶</a></h1>
<p>This module implements a <a class="reference internal" href="#werkzeug.contrib.iterio.IterIO" title="werkzeug.contrib.iterio.IterIO"><tt class="xref py py-class docutils literal"><span class="pre">IterIO</span></tt></a> that converts an iterator into
a stream object and the other way round. Converting streams into
iterators requires the <a class="reference external" href="http://codespeak.net/py/dist/greenlet.html">greenlet</a> module.</p>
<p>To convert an iterator into a stream all you have to do is to pass it
directly to the <a class="reference internal" href="#werkzeug.contrib.iterio.IterIO" title="werkzeug.contrib.iterio.IterIO"><tt class="xref py py-class docutils literal"><span class="pre">IterIO</span></tt></a> constructor. In this example we pass it
a newly created generator:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">foo</span><span class="p">():</span>
<span class="k">yield</span> <span class="s">"something</span><span class="se">\n</span><span class="s">"</span>
<span class="k">yield</span> <span class="s">"otherthings"</span>
<span class="n">stream</span> <span class="o">=</span> <span class="n">IterIO</span><span class="p">(</span><span class="n">foo</span><span class="p">())</span>
<span class="k">print</span> <span class="n">stream</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> <span class="c"># read the whole iterator</span>
</pre></div>
</div>
<p>The other way round works a bit different because we have to ensure that
the code execution doesn’t take place yet. An <a class="reference internal" href="#werkzeug.contrib.iterio.IterIO" title="werkzeug.contrib.iterio.IterIO"><tt class="xref py py-class docutils literal"><span class="pre">IterIO</span></tt></a> call with a
callable as first argument does two things. The function itself is passed
an <a class="reference internal" href="#werkzeug.contrib.iterio.IterIO" title="werkzeug.contrib.iterio.IterIO"><tt class="xref py py-class docutils literal"><span class="pre">IterIO</span></tt></a> stream it can feed. The object returned by the
<a class="reference internal" href="#werkzeug.contrib.iterio.IterIO" title="werkzeug.contrib.iterio.IterIO"><tt class="xref py py-class docutils literal"><span class="pre">IterIO</span></tt></a> constructor on the other hand is not an stream object but
an iterator:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">stream</span><span class="p">):</span>
<span class="n">stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">"some"</span><span class="p">)</span>
<span class="n">stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">"thing"</span><span class="p">)</span>
<span class="n">stream</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
<span class="n">stream</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">"otherthing"</span><span class="p">)</span>
<span class="n">iterator</span> <span class="o">=</span> <span class="n">IterIO</span><span class="p">(</span><span class="n">foo</span><span class="p">)</span>
<span class="k">print</span> <span class="n">iterator</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> <span class="c"># prints something</span>
<span class="k">print</span> <span class="n">iterator</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> <span class="c"># prints otherthing</span>
<span class="n">iterator</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> <span class="c"># raises StopIteration</span>
</pre></div>
</div>
<dl class="class">
<dt id="werkzeug.contrib.iterio.IterIO">
<em class="property">class </em><tt class="descclassname">werkzeug.contrib.iterio.</tt><tt class="descname">IterIO</tt><a class="headerlink" href="#werkzeug.contrib.iterio.IterIO" title="Permalink to this definition">¶</a></dt>
<dd><p>Instances of this object implement an interface compatible with the
standard Python <tt class="xref py py-class docutils literal"><span class="pre">file</span></tt> object. Streams are either read-only or
write-only depending on how the object is created.</p>
<p>If the first argument is an iterable a file like object is returned that
returns the contents of the iterable. In case the iterable is empty
read operations will return the sentinel value.</p>
<p>If the first argument is a callable then the stream object will be
created and passed to that function. The caller itself however will
not receive a stream but an iterable. The function will be be executed
step by step as something iterates over the returned iterable. Each
call to <tt class="xref py py-meth docutils literal"><span class="pre">flush()</span></tt> will create an item for the iterable. If
<tt class="xref py py-meth docutils literal"><span class="pre">flush()</span></tt> is called without any writes in-between the sentinel
value will be yielded.</p>
<p>Note for Python 3: due to the incompatible interface of bytes and
streams you should set the sentinel value explicitly to an empty
bytestring (<tt class="docutils literal"><span class="pre">b''</span></tt>) if you are expecting to deal with bytes as
otherwise the end of the stream is marked with the wrong sentinel
value.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.9: </span><cite>sentinel</cite> parameter was added.</p>
</div>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper"><p class="logo"><a href="../index.html">
<img class="logo" src="../_static/werkzeug.png" alt="Logo"/>
</a></p><h3>Related Topics</h3>
<ul>
<li><a href="../index.html">Documentation overview</a><ul>
<li><a href="index.html">Contributed Modules</a><ul>
<li>Previous: <a href="wrappers.html" title="previous chapter">Extra Wrappers</a></li>
<li>Next: <a href="fixers.html" title="next chapter">Fixers</a></li>
</ul></li>
</ul></li>
</ul>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/contrib/iterio.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
© Copyright 2011, The Werkzeug Team.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
</body>
</html>
|