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.')
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.')
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!"])
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!"])
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!"])
def write_line(self, msg): self.producer_fifo.append(simple_producer(msg.encode("utf-8") + b"\n"))
def deliver(self, buf): if self.listening: self.push('recv {0}\n'.format(len(buf))) self.push_with_producer(asynchat.simple_producer(buf))
def fromstring(klass, string): producer = asynchat.simple_producer(string) return klass(producer)
def write_line(self, msg): self.producer_fifo.append(simple_producer(msg + "\n"))
def push(self, data): self.producer_fifo.push( asynchat.simple_producer(data, buffer_size=self.ac_out_buffer_size)) self.initiate_send()