Ejemplo n.º 1
0
 def next(self):
     while not len(self.data) and not self.worker.EOF.is_set():
         self.worker.data_added.clear()
         self.worker.data_added.wait(0.2)
     if len(self.data):
         self.worker.keep_reading.set()
         return _bytes(self.data.popleft())
     elif self.worker.EOF.is_set():
         raise StopIteration
Ejemplo n.º 2
0
 def next(self):
     while not len(self.data) and not self.worker.EOF.is_set():
         self.worker.data_added.clear()
         self.worker.data_added.wait(0.2)
     if len(self.data):
         self.worker.keep_reading.set()
         return _bytes(self.data.popleft())
     elif self.worker.EOF.is_set():
         raise StopIteration
Ejemplo n.º 3
0
 def __init__(self, source):
     super(StreamFeeder, self).__init__()
     self.daemon = True
     filelike = False
     self.bytes = _bytes()
     if type(source) in (type(''), _bytes, _bytearray):  # string-like
         self.bytes = _bytes(source)
     else:  # can be either file pointer or file-like
         if type(source) in (int, long):  # file pointer it is
             ## converting file descriptor (int) stdin into file-like
             try:
                 source = os.fdopen(source, 'rb', 16384)
             except Exception:
                 pass
         # let's see if source is file-like by now
         try:
             filelike = source.read
         except Exception:
             pass
     if not filelike and not self.bytes:
         raise TypeError("StreamFeeder's source object must be a readable "
                         "file-like, a file descriptor, or a string-like.")
     self.source = source
     self.readiface, self.writeiface = os.pipe()
Ejemplo n.º 4
0
 def __init__(self, source):
     super(StreamFeeder, self).__init__()
     self.daemon = True
     filelike = False
     self.bytes = _bytes()
     if type(source) in (type(''), _bytes, _bytearray):  # string-like
         self.bytes = _bytes(source)
     else:  # can be either file pointer or file-like
         if type(source) in (int, long):  # file pointer it is
             ## converting file descriptor (int) stdin into file-like
             try:
                 source = os.fdopen(source, 'rb', 16384)
             except Exception:
                 pass
         # let's see if source is file-like by now
         try:
             filelike = source.read
         except Exception:
             pass
     if not filelike and not self.bytes:
         raise TypeError("StreamFeeder's source object must be a readable "
                         "file-like, a file descriptor, or a string-like.")
     self.source = source
     self.readiface, self.writeiface = os.pipe()