def flush(self): """Flush stream. Calls `ASStreamOut.ASStreamOut.flush`, and if that returns True (indicating the buffer is full enough) then we send data from the buffer out on the socket. """ result = ASStreamOut.flush(self) if result: # a true return value means we can send reslen = len(self._buffer) sent = 0 bufferSize = self._bufferSize while sent < reslen: try: sent += self._socket.send( self._buffer[sent:sent+bufferSize]) except socket.error as e: if debug or e[0] not in self._ignoreErrnos: print "StreamOut Error:", e self._closed = True raise ConnectionAbortedError self.pop(sent)