Python 3 compat

This commit is contained in:
Mike Helmick 2013-05-24 16:17:50 -04:00
parent c8b1202880
commit 64b1349993
2 changed files with 7 additions and 3 deletions

View file

@ -102,7 +102,7 @@ class TwythonAPITestCase(unittest.TestCase):
counter = 0
while counter < 2:
counter += 1
result = search.next()
result = next(search)
new_id_str = int(result['id_str'])
if counter == 1:
prev_id_str = new_id_str

View file

@ -1,5 +1,5 @@
from .. import __version__
from ..compat import json
from ..compat import json, is_py3
from ..exceptions import TwythonStreamError
from .types import TwythonStreamerTypes
@ -93,7 +93,11 @@ class TwythonStreamer(object):
break
if line:
try:
self.on_success(json.loads(line))
if not is_py3:
self.on_success(json.loads(line))
else:
line = line.decode('utf-8')
self.on_success(json.loads(line))
except ValueError:
raise TwythonStreamError('Response was not valid JSON, \
unable to decode.')