Example #1
0
    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
Example #2
0
 def _value(self, value):
     try:
         eid = self._values[value]
         s = dumps((eid, value), -1)
         self.push(Write(s), target=self._socket)
     except:
         return
Example #3
0
 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
Example #4
0
 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
Example #5
0
 def RAW(self, data):
     self.push(Write("%s\r\n" % data), "write", self.channel)
Example #6
0
 def RAW(self, data):
     self.push(Write("%s\r\n" % data))
Example #7
0
 def connected(self, host, port):
     print "Connected to %s" % host
     self.push(Write('GET / HTTP/1.0\r\n\r\n'))
Example #8
0
 def send(self, data):
     self.push(Write(data))