Exemplo n.º 1
0
 def retr_completion(self, file, response):
     status=response.getStatus()
     if status==200:
         self.make_xmit_channel()
         if not response._wrote:
             # chrism: we explicitly use a large-buffered producer here to
             # increase speed.  Using "client_dc.push" with the body causes
             # a simple producer with a buffer size of 512 to be created
             # to serve the data, and it's very slow
             # (about 100 times slower than the large-buffered producer)
             self.client_dc.push_with_producer(
                 asynchat.simple_producer(response.body, 1<<16))
             # chrism: if the response has a bodyproducer, it means that
             # the actual body was likely an empty string.  This happens
             # typically when someone returns a StreamIterator from
             # Zope application code.
             if response._bodyproducer:
                 self.client_dc.push_with_producer(response._bodyproducer)
         else:
             for producer in self._response_producers:
                 self.client_dc.push_with_producer(producer)
         self._response_producers = None
         self.client_dc.close_when_done()
         self.respond(
                 "150 Opening %s mode data connection for file '%s'" % (
                     self.type_map[self.current_mode],
                     file
                     ))
     elif status in (401, 403):
         self.respond('530 Unauthorized.')
     else:
         self.respond('550 Error opening file.')
Exemplo n.º 2
0
 def retr_completion(self, file, response):
     status = response.getStatus()
     if status == 200:
         self.make_xmit_channel()
         if not response._wrote:
             # chrism: we explicitly use a large-buffered producer here to
             # increase speed.  Using "client_dc.push" with the body causes
             # a simple producer with a buffer size of 512 to be created
             # to serve the data, and it's very slow
             # (about 100 times slower than the large-buffered producer)
             self.client_dc.push_with_producer(
                 asynchat.simple_producer(response.body, 1 << 16))
             # chrism: if the response has a bodyproducer, it means that
             # the actual body was likely an empty string.  This happens
             # typically when someone returns a StreamIterator from
             # Zope application code.
             if response._bodyproducer:
                 self.client_dc.push_with_producer(response._bodyproducer)
         else:
             for producer in self._response_producers:
                 self.client_dc.push_with_producer(producer)
         self._response_producers = None
         self.client_dc.close_when_done()
         self.respond("150 Opening %s mode data connection for file '%s'" %
                      (self.type_map[self.current_mode], file))
     elif status in (401, 403):
         self.respond('530 Unauthorized.')
     else:
         self.respond('550 Error opening file.')
Exemplo n.º 3
0
    def test_simple_producer(self):
        s, event = start_echo_server()
        c = echo_client(b'\n', s.port)
        data = b"hello world\nI'm not dead yet!\n"
        p = asynchat.simple_producer(data + SERVER_QUIT, buffer_size=8)
        c.push_with_producer(p)
        asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
        threading_helper.join_thread(s)

        self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
Exemplo n.º 4
0
    def test_simple_producer(self):
        s, event = start_echo_server()
        c = echo_client('\n', s.port)
        data = "hello world\nI'm not dead yet!\n"
        p = asynchat.simple_producer(data+SERVER_QUIT, buffer_size=8)
        c.push_with_producer(p)
        asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
        s.join()

        self.assertEqual(c.contents, ["hello world", "I'm not dead yet!"])
Exemplo n.º 5
0
 def test_simple_producer(self):
     s, event = start_echo_server()
     c = echo_client(b'\n', s.port)
     data = b"hello world\nI'm not dead yet!\n"
     p = asynchat.simple_producer(data + SERVER_QUIT, buffer_size=8)
     c.push_with_producer(p)
     asyncore.loop(use_poll=self.usepoll, count=300, timeout=0.01)
     s.join(timeout=TIMEOUT)
     if s.is_alive():
         self.fail('join() timed out')
     self.assertEqual(c.contents, [b'hello world', b"I'm not dead yet!"])
Exemplo n.º 6
0
 def write_line(self, msg):
     self.producer_fifo.append(simple_producer(msg.encode("utf-8") + b"\n"))
Exemplo n.º 7
0
 def deliver(self, buf):
     if self.listening:
         self.push('recv {0}\n'.format(len(buf)))
         self.push_with_producer(asynchat.simple_producer(buf))
Exemplo n.º 8
0
 def fromstring(klass, string):
     producer = asynchat.simple_producer(string)
     return klass(producer)
Exemplo n.º 9
0
 def write_line(self, msg):
     self.producer_fifo.append(simple_producer(msg + "\n"))
Exemplo n.º 10
0
 def write_line(self, msg):
     self.producer_fifo.append(simple_producer(msg.encode("utf-8") + b"\n"))
Exemplo n.º 11
0
 def push(self, data):
     self.producer_fifo.push(
         asynchat.simple_producer(data, buffer_size=self.ac_out_buffer_size))
     self.initiate_send()
Exemplo n.º 12
0
 def fromstring(klass, string):
     producer = asynchat.simple_producer(string)
     return klass(producer)