|
46 | 46 | you - by calling your self.found_terminator() method. |
47 | 47 | """ |
48 | 48 |
|
| 49 | +import sys |
49 | 50 | import socket |
50 | 51 | import asyncore |
51 | 52 | from collections import deque |
@@ -91,6 +92,8 @@ def handle_read (self): |
91 | 92 | self.handle_error() |
92 | 93 | return |
93 | 94 |
|
| 95 | + if isinstance(data, str): |
| 96 | + data = data.encode('ascii') |
94 | 97 | self.ac_in_buffer = self.ac_in_buffer + bytes(data) |
95 | 98 |
|
96 | 99 | # Continue to search for self.terminator in self.ac_in_buffer, |
@@ -126,6 +129,8 @@ def handle_read (self): |
126 | 129 | # 3) end of buffer does not match any prefix: |
127 | 130 | # collect data |
128 | 131 | terminator_len = len(terminator) |
| 132 | + if isinstance(terminator, str): |
| 133 | + terminator = terminator.encode('ascii') |
129 | 134 | index = self.ac_in_buffer.find(terminator) |
130 | 135 | if index != -1: |
131 | 136 | # we found the terminator |
@@ -195,11 +200,15 @@ def refill_buffer (self): |
195 | 200 | self.close() |
196 | 201 | return |
197 | 202 | elif isinstance(p, str) or isinstance(p, bytes): |
| 203 | + if isinstance(p, str): |
| 204 | + p = p.encode('ascii') |
198 | 205 | self.producer_fifo.pop() |
199 | | - self.ac_out_buffer = self.ac_out_buffer + bytes(p) |
| 206 | + self.ac_out_buffer = self.ac_out_buffer + p |
200 | 207 | return |
201 | 208 | data = p.more() |
202 | 209 | if data: |
| 210 | + if isinstance(data, str): |
| 211 | + data = data.encode('ascii') |
203 | 212 | self.ac_out_buffer = self.ac_out_buffer + bytes(data) |
204 | 213 | return |
205 | 214 | else: |
|
0 commit comments