Modify ReadBuffer for Py3
authorKatsunori SUZUI <kt@7kry.net>
Wed, 19 Nov 2014 14:49:50 +0000 (23:49 +0900)
committerKatsunori SUZUI <kt@7kry.net>
Wed, 19 Nov 2014 14:49:50 +0000 (23:49 +0900)
On my Python 3.4.2 environment, UserStreaming did't work
because of an error of bytes-to-str conversion.

tweepy/streaming.py

index 186d69ae2e9efc04c0f6fd4680fd7f57f0e08479..0cf1d7cbe3ea9a824aa1b1784f50651be0127a6a 100644 (file)
@@ -146,7 +146,7 @@ class ReadBuffer(object):
 
     def __init__(self, stream, chunk_size):
         self._stream = stream
-        self._buffer = ""
+        self._buffer = u""
         self._chunk_size = chunk_size
 
     def read_len(self, length):
@@ -154,7 +154,7 @@ class ReadBuffer(object):
             if len(self._buffer) >= length:
                 return self._pop(length)
             read_len = max(self._chunk_size, length - len(self._buffer))
-            self._buffer += self._stream.read(read_len)
+            self._buffer += self._stream.read(read_len).decode("ascii")
 
     def read_line(self, sep='\n'):
         start = 0
@@ -164,7 +164,7 @@ class ReadBuffer(object):
                 return self._pop(loc + len(sep))
             else:
                 start = len(self._buffer)
-            self._buffer += self._stream.read(self._chunk_size)
+            self._buffer += self._stream.read(self._chunk_size).decode("ascii")
 
     def _pop(self, length):
         r = self._buffer[:length]