diff options
author | Guido van Rossum <guido@python.org> | 2007-07-12 07:58:54 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-07-12 07:58:54 +0000 |
commit | 076da0957b1af50cccf40ec5c60742212b4a1f90 (patch) | |
tree | 249b3131cfd00f85e76e7ece18b0ff93cabe8cff /Lib/asynchat.py | |
parent | e7a0d3997846155e1a9dcd95eb559039da34ee08 (diff) | |
download | cpython-git-076da0957b1af50cccf40ec5c60742212b4a1f90.tar.gz |
Fix asynchat to use bytes instead of strings.
Fix by Alexandre Vassalotti, SF# 1752173.
Diffstat (limited to 'Lib/asynchat.py')
-rw-r--r-- | Lib/asynchat.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Lib/asynchat.py b/Lib/asynchat.py index dc7f10f7bf..2206984884 100644 --- a/Lib/asynchat.py +++ b/Lib/asynchat.py @@ -60,8 +60,8 @@ class async_chat (asyncore.dispatcher): ac_out_buffer_size = 4096 def __init__ (self, conn=None): - self.ac_in_buffer = '' - self.ac_out_buffer = '' + self.ac_in_buffer = b'' + self.ac_out_buffer = b'' self.producer_fifo = fifo() asyncore.dispatcher.__init__ (self, conn) @@ -91,7 +91,7 @@ class async_chat (asyncore.dispatcher): self.handle_error() return - self.ac_in_buffer = self.ac_in_buffer + data + self.ac_in_buffer = self.ac_in_buffer + bytes(data) # Continue to search for self.terminator in self.ac_in_buffer, # while calling self.collect_incoming_data. The while loop @@ -110,7 +110,7 @@ class async_chat (asyncore.dispatcher): n = terminator if lb < n: self.collect_incoming_data (self.ac_in_buffer) - self.ac_in_buffer = '' + self.ac_in_buffer = b'' self.terminator = self.terminator - lb else: self.collect_incoming_data (self.ac_in_buffer[:n]) @@ -147,7 +147,7 @@ class async_chat (asyncore.dispatcher): else: # no prefix, collect it all self.collect_incoming_data (self.ac_in_buffer) - self.ac_in_buffer = '' + self.ac_in_buffer = b'' def handle_write (self): self.initiate_send () @@ -172,7 +172,7 @@ class async_chat (asyncore.dispatcher): # return len(self.ac_out_buffer) or len(self.producer_fifo) or (not self.connected) # this is about twice as fast, though not as clear. return not ( - (self.ac_out_buffer == '') and + (self.ac_out_buffer == b'') and self.producer_fifo.is_empty() and self.connected ) @@ -194,13 +194,13 @@ class async_chat (asyncore.dispatcher): self.producer_fifo.pop() self.close() return - elif isinstance(p, str): + elif isinstance(p, str) or isinstance(p, bytes): self.producer_fifo.pop() - self.ac_out_buffer = self.ac_out_buffer + p + self.ac_out_buffer = self.ac_out_buffer + bytes(p) return data = p.more() if data: - self.ac_out_buffer = self.ac_out_buffer + data + self.ac_out_buffer = self.ac_out_buffer + bytes(data) return else: self.producer_fifo.pop() @@ -226,8 +226,8 @@ class async_chat (asyncore.dispatcher): def discard_buffers (self): # Emergencies only! - self.ac_in_buffer = '' - self.ac_out_buffer = '' + self.ac_in_buffer = b'' + self.ac_out_buffer = b'' while self.producer_fifo: self.producer_fifo.pop() @@ -245,7 +245,7 @@ class simple_producer: return result else: result = self.data - self.data = '' + self.data = b'' return result class fifo: |