Commit 9916a548 authored by Joshua Roesslein's avatar Joshua Roesslein
Browse files

Merge pull request #558 from tweepy/fix-556

Fix bug where streams freeze up on Python 3 due to string formatting bug...
parents fdf13318 88172bf7
......@@ -20,7 +20,7 @@ from tweepy.models import Status
from tweepy.api import API
from tweepy.error import TweepError
from tweepy.utils import import_simplejson, urlencode_noplus
from tweepy.utils import import_simplejson
json = import_simplejson()
STREAM_VERSION = '1.1'
......@@ -397,44 +397,42 @@ class Stream(object):
def filter(self, follow=None, track=None, async=False, locations=None,
stall_warnings=False, languages=None, encoding='utf8'):
self.session.params = {}
self.body = {}
self.session.headers['Content-type'] = "application/x-www-form-urlencoded"
if self.running:
raise TweepError('Stream object already connected!')
self.url = '/%s/statuses/filter.json' % STREAM_VERSION
if follow:
self.session.params['follow'] = u','.join(follow).encode(encoding)
self.body['follow'] = u','.join(follow).encode(encoding)
if track:
self.session.params['track'] = u','.join(track).encode(encoding)
self.body['track'] = u','.join(track).encode(encoding)
if locations and len(locations) > 0:
if len(locations) % 4 != 0:
raise TweepError("Wrong number of locations points, "
"it has to be a multiple of 4")
self.session.params['locations'] = u','.join(['%.4f' % l for l in locations])
self.body['locations'] = u','.join(['%.4f' % l for l in locations])
if stall_warnings:
self.session.params['stall_warnings'] = stall_warnings
self.body['stall_warnings'] = stall_warnings
if languages:
self.session.params['language'] = u','.join(map(str, languages))
self.body = urlencode_noplus(self.session.params)
self.body['language'] = u','.join(map(str, languages))
self.session.params = {'delimited': 'length'}
self.host = 'stream.twitter.com'
self._start(async)
def sitestream(self, follow, stall_warnings=False,
with_='user', replies=False, async=False):
self.parameters = {}
self.body = {}
if self.running:
raise TweepError('Stream object already connected!')
self.url = '/%s/site.json' % STREAM_VERSION
self.parameters['follow'] = u','.join(map(six.text_type, follow))
self.parameters['delimited'] = 'length'
self.body['follow'] = u','.join(map(six.text_type, follow))
self.body['delimited'] = 'length'
if stall_warnings:
self.parameters['stall_warnings'] = stall_warnings
self.body['stall_warnings'] = stall_warnings
if with_:
self.parameters['with'] = with_
self.body['with'] = with_
if replies:
self.parameters['replies'] = replies
self.body = urlencode_noplus(self.parameters)
self.body['replies'] = replies
self._start(async)
def disconnect(self):
......
......@@ -56,9 +56,3 @@ def import_simplejson():
def list_to_csv(item_list):
if item_list:
return ','.join([str(i) for i in item_list])
def urlencode_noplus(query):
return '&'.join(['%s=%s' % (quote(str(k), ''), quote(str(v), ''))
for k, v in query.items()])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment