def __init__(self, channel, statusline, headers=None, data=None): Event.__init__(self, channel.env) self.channel = channel self.statusline = statusline self.headers = headers if headers is not None else {} self.write = types.MethodType(Write, self) self._write_ev = self.env.event() if data is not None: self.headers['Content-Length'] = str(len(data)) self.write(data) else: self.headers['Transfer-Encoding'] = 'chunked' try: channel._send_queue.append(self) except: if (hasattr(channel, '_send_queue') and channel._send_queue is not None): raise raise channel._writer_process.value if channel._out_message_ev is not None: channel._out_message_ev.succeed(self) channel._out_message_ev = None
def __init__(self, message, data=b'', all=False): Event.__init__(self, message.env) try: if message._write_ev.triggered: raise RuntimeError('Concurrent write attempt') except AttributeError: if message._write_ev is False: raise RuntimeError('Message has already been sent') elif message._write_ev is not None: # Unknown error occured. raise raise message.channel._writer_process.value self.data = data self.all = all if data else True message._write_ev.succeed(self)
def __init__(self, message, all=False): Event.__init__(self, message.env) try: if message._read_ev.triggered: raise RuntimeError('Concurrent read attempt') except AttributeError: if message._read_ev is False: # All content has been read. self.succeed(b'') return elif message._read_ev is not None: # Unknown error occured. raise raise message.channel._reader_process.value self.all = all message._read_ev.succeed(self)
def __init__(self, channel): Event.__init__(self, channel.env) self.channel = channel # FIXME This sould be removed. self.respond = types.MethodType(OutResponse, channel) self.read = types.MethodType(Read, self) self._read_ev = self.env.event() try: channel._recv_queue.append(self) except: if (hasattr(channel, '_recv_queue') and channel._recv_queue is not None): raise raise channel._reader_process.value if channel._in_message_ev is not None: channel._in_message_ev.succeed(self) channel._in_message_ev = None
def __init__(self, sock, data): Event.__init__(self, sock.env) self.sock = sock self.data = data
def __init__(self, message, id, content): Event.__init__(self, message.env) self.message = message self.id = id self.content = content