File manager - Edit - /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyc
Back
� �ْSc @ s� d Z y d d l Z Wn e k r/ d Z n Xd d l m Z d � Z d � Z e d e f d � � Y� Z d e f d � � YZ d e f d � � YZ d S( s werkzeug.contrib.iterio ~~~~~~~~~~~~~~~~~~~~~~~ This module implements a :class:`IterIO` that converts an iterator into a stream object and the other way round. Converting streams into iterators requires the `greenlet`_ module. To convert an iterator into a stream all you have to do is to pass it directly to the :class:`IterIO` constructor. In this example we pass it a newly created generator:: def foo(): yield "something\n" yield "otherthings" stream = IterIO(foo()) print stream.read() # read the whole iterator The other way round works a bit different because we have to ensure that the code execution doesn't take place yet. An :class:`IterIO` call with a callable as first argument does two things. The function itself is passed an :class:`IterIO` stream it can feed. The object returned by the :class:`IterIO` constructor on the other hand is not an stream object but an iterator:: def foo(stream): stream.write("some") stream.write("thing") stream.flush() stream.write("otherthing") iterator = IterIO(foo) print iterator.next() # prints something print iterator.next() # prints otherthing iterator.next() # raises StopIteration .. _greenlet: http://codespeak.net/py/dist/greenlet.html :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details. :license: BSD, see LICENSE for more details. i����N( t implements_iteratorc C sL t | � } t | | � } t | t � r; | d j | � S| d j | � S( s2 concatenate any string type in an intelligent way.t u ( t itert nextt isinstancet bytest join( t iterablet sentinelt iteratort first_item( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt _mixed_join2 s c C s t | t � r d Sd S( Ns u ( R R ( t reference_string( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt _newline; s t IterIOc B s� e Z d Z d d � Z d � Z d � Z d � Z d d � Z d d � Z d � Z d � Z d d � Z d d � Z d d � Z d � Z d � Z RS( s� Instances of this object implement an interface compatible with the standard Python :class:`file` object. Streams are either read-only or write-only depending on how the object is created. 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. 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 :meth:`flush` will create an item for the iterable. If :meth:`flush` is called without any writes in-between the sentinel value will be yielded. Note for Python 3: due to the incompatible interface of bytes and streams you should set the sentinel value explicitly to an empty bytestring (``b''``) if you are expecting to deal with bytes as otherwise the end of the stream is marked with the wrong sentinel value. .. versionadded:: 0.9 `sentinel` parameter was added. R c C s; y t | � } Wn t k r- t | | � SXt | | � S( N( R t TypeErrort IterIt IterO( t clst objR R ( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt __new__] s c C s | S( N( ( t self( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt __iter__d s c C s | j r t d � � n | j S( Ns I/O operation on closed file( t closedt ValueErrort pos( R ( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt tellg s c C s | j r t d � � n t S( Ns I/O operation on closed file( R R t False( R ( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt isattyl s i c C s+ | j r t d � � n t d d � � d S( Ns I/O operation on closed filei s Bad file descriptor( R R t IOError( R R t mode( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt seekq s c C s+ | j r t d � � n t d d � � d S( Ns I/O operation on closed filei s Bad file descriptor( R R R ( R t size( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt truncatev s c C s+ | j r t d � � n t d d � � d S( Ns I/O operation on closed filei s Bad file descriptor( R R R ( R t s( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt write{ s c C s+ | j r t d � � n t d d � � d S( Ns I/O operation on closed filei s Bad file descriptor( R R R ( R t list( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt writelines� s i����c C s+ | j r t d � � n t d d � � d S( Ns I/O operation on closed filei s Bad file descriptor( R R R ( R t n( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt read� s c C s+ | j r t d � � n t d d � � d S( Ns I/O operation on closed filei s Bad file descriptor( R R R ( R t sizehint( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt readlines� s c C s+ | j r t d � � n t d d � � d S( Ns I/O operation on closed filei s Bad file descriptor( R R R ( R t length( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt readline� s c C s+ | j r t d � � n t d d � � d S( Ns I/O operation on closed filei s Bad file descriptor( R R R ( R ( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt flush� s c C s7 | j r t � � n | j � } | s3 t � � n | S( N( R t StopIterationR+ ( R t line( ( sF /opt/imh-python/lib/python2.7/site-packages/werkzeug/contrib/iterio.pyt __next__� s N( t __name__t __module__t __doc__R R R R R t NoneR! R# R% R'