Project

General

Profile

« Previous | Next » 

Revision 1759

streams.py: Added consume(). Added documentation labels to each section.

View differences:

lib/streams.py
2 2

  
3 3
import timeouts
4 4

  
5
##### Wrapped streams
6

  
5 7
class WrapStream:
6 8
    '''Forwards close() to the underlying stream'''
7 9
    def __init__(self, stream): self.stream = stream
8 10
    
9 11
    def close(self): self.stream.close()
10 12

  
13
##### Line iteration
14

  
11 15
class StreamIter(WrapStream):
12 16
    '''Iterates over the lines in a stream.
13 17
    Unlike stream.__iter__(), doesn't wait for EOF to start returning lines.
......
32 36
def copy(from_, to):
33 37
    for line in StreamIter(from_): to.write(line)
34 38

  
39
def consume(in_):
40
    for line in StreamIter(in_): pass
41

  
42
##### Timeouts
43

  
35 44
class TimeoutInputStream(WrapStream):
36 45
    '''@param timeout sec'''
37 46
    def __init__(self, stream, timeout):

Also available in: Unified diff