def response(self, response): self.push(Write(response.sock, str(response))) if response.stream and response.body: try: data = response.body.next() except StopIteration: data = None self.push(Stream(response, data)) else: body = "".join(response.body) if body: if response.chunked: buf = [hex(len(body))[2:], "\r\n", body, "\r\n"] body = "".join(buf) self.push(Write(response.sock, body)) if response.chunked: self.push(Write(response.sock, "0\r\n\r\n")) if not response.stream: if response.close: self.push(Close(response.sock)) response.done = True
def _value(self, value): try: eid = self._values[value] s = dumps((eid, value), -1) self.push(Write(s), target=self._socket) except: return
def _writer(self, event): try: eid = id(event) self._values[eid] = event.value s = dumps((eid, event)) self.push(Write(s), target=self._socket) except: return
def stream(self, response, data): if data: if response.chunked: buf = [hex(len(data))[2:], "\r\n", data, "\r\n"] data = "".join(buf) self.push(Write(response.sock, data)) if response.body and not response.done: try: data = response.body.next() except StopIteration: data = None self.push(Stream(response, data)) else: if response.body: response.body.close() if response.chunked: self.push(Write(response.sock, "0\r\n\r\n")) if response.close: self.push(Close(response.sock)) response.done = True
def RAW(self, data): self.push(Write("%s\r\n" % data), "write", self.channel)
def RAW(self, data): self.push(Write("%s\r\n" % data))
def connected(self, host, port): print "Connected to %s" % host self.push(Write('GET / HTTP/1.0\r\n\r\n'))
def send(self, data): self.push(Write(data))