Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python3.7 compatibility issue #1042

Merged
merged 2 commits into from
Jun 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ def test_filter_track(self):

def test_track_encoding(self):
s = Stream(None, None)
s._start = lambda async: None
s._start = lambda is_async: None
s.filter(track=[u'Caf\xe9'])

# Should be UTF-8 encoded
self.assertEqual(u'Caf\xe9'.encode('utf8'), s.body['track'])

def test_follow_encoding(self):
s = Stream(None, None)
s._start = lambda async: None
s._start = lambda is_async: None
s.filter(follow=[u'Caf\xe9'])

# Should be UTF-8 encoded
Expand Down
28 changes: 14 additions & 14 deletions tweepy/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ def _read_loop(self, resp):
if resp.raw.closed:
self.on_closed(resp)

def _start(self, async):
def _start(self, is_async):
self.running = True
if async:
if is_async:
self._thread = Thread(target=self._run)
self._thread.start()
else:
Expand All @@ -373,7 +373,7 @@ def userstream(self,
replies=None,
track=None,
locations=None,
async=False,
is_async=False,
encoding='utf8'):
self.session.params = {'delimited': 'length'}
if self.running:
Expand All @@ -394,25 +394,25 @@ def userstream(self,
if track:
self.session.params['track'] = u','.join(track).encode(encoding)

self._start(async)
self._start(is_async)

def firehose(self, count=None, async=False):
def firehose(self, count=None, is_async=False):
self.session.params = {'delimited': 'length'}
if self.running:
raise TweepError('Stream object already connected!')
self.url = '/%s/statuses/firehose.json' % STREAM_VERSION
if count:
self.url += '&count=%s' % count
self._start(async)
self._start(is_async)

def retweet(self, async=False):
def retweet(self, is_async=False):
self.session.params = {'delimited': 'length'}
if self.running:
raise TweepError('Stream object already connected!')
self.url = '/%s/statuses/retweet.json' % STREAM_VERSION
self._start(async)
self._start(is_async)

def sample(self, async=False, languages=None, stall_warnings=False):
def sample(self, is_async=False, languages=None, stall_warnings=False):
self.session.params = {'delimited': 'length'}
if self.running:
raise TweepError('Stream object already connected!')
Expand All @@ -421,9 +421,9 @@ def sample(self, async=False, languages=None, stall_warnings=False):
self.session.params['language'] = ','.join(map(str, languages))
if stall_warnings:
self.session.params['stall_warnings'] = 'true'
self._start(async)
self._start(is_async)

def filter(self, follow=None, track=None, async=False, locations=None,
def filter(self, follow=None, track=None, is_async=False, locations=None,
stall_warnings=False, languages=None, encoding='utf8', filter_level=None):
self.body = {}
self.session.headers['Content-type'] = "application/x-www-form-urlencoded"
Expand All @@ -447,10 +447,10 @@ def filter(self, follow=None, track=None, async=False, locations=None,
self.body['filter_level'] = filter_level.encode(encoding)
self.session.params = {'delimited': 'length'}
self.host = 'stream.twitter.com'
self._start(async)
self._start(is_async)

def sitestream(self, follow, stall_warnings=False,
with_='user', replies=False, async=False):
with_='user', replies=False, is_async=False):
self.body = {}
if self.running:
raise TweepError('Stream object already connected!')
Expand All @@ -463,7 +463,7 @@ def sitestream(self, follow, stall_warnings=False,
self.body['with'] = with_
if replies:
self.body['replies'] = replies
self._start(async)
self._start(is_async)

def disconnect(self):
if self.running is False:
Expand Down