aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2017-12-19 11:04:53 +0100
committerLorenz Diener <[email protected]>2017-12-19 11:04:53 +0100
commite5c50ea80d86449b5f95a32cf3a01d7bf8e9d2f4 (patch)
treeba3339e2f970f303bd9c1911787717dada717dec /mastodon
parent2420a5d6dedb0873d9bad80addcc8e20e1849b36 (diff)
downloadmastodon.py-e5c50ea80d86449b5f95a32cf3a01d7bf8e9d2f4.tar.gz
Fix missing async in hashtag/list streams
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 5080b2e..a2f7738 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -1387,7 +1387,7 @@ class Mastodon:
1387 """ 1387 """
1388 if tag.startswith("#"): 1388 if tag.startswith("#"):
1389 raise MastodonIllegalArgumentError("Tag parameter should omit leading #") 1389 raise MastodonIllegalArgumentError("Tag parameter should omit leading #")
1390 return self.__stream("/api/v1/streaming/hashtag?tag={}".format(tag), listener) 1390 return self.__stream("/api/v1/streaming/hashtag?tag={}".format(tag), listener, async=async)
1391 1391
1392 @api_version("2.1.0", "2.1.0") 1392 @api_version("2.1.0", "2.1.0")
1393 def stream_list(self, id, listener, async=False): 1393 def stream_list(self, id, listener, async=False):
@@ -1396,7 +1396,7 @@ class Mastodon:
1396 list. 1396 list.
1397 """ 1397 """
1398 id = self.__unpack_id(id) 1398 id = self.__unpack_id(id)
1399 return self.__stream("/api/v1/streaming/list?list={}".format(id), listener) 1399 return self.__stream("/api/v1/streaming/list?list={}".format(id), listener, async=async)
1400 1400
1401 ### 1401 ###
1402 # Internal helpers, dragons probably 1402 # Internal helpers, dragons probably
@@ -1670,9 +1670,11 @@ class Mastodon:
1670 1670
1671 class __stream_handle(): 1671 class __stream_handle():
1672 def __init__(self, connection): 1672 def __init__(self, connection):
1673 self.closed = False
1673 self.connection = connection 1674 self.connection = connection
1674 1675
1675 def close(self): 1676 def close(self):
1677 self.closed = True
1676 self.connection.close() 1678 self.connection.close()
1677 1679
1678 def is_alive(self): 1680 def is_alive(self):
@@ -1682,10 +1684,10 @@ class Mastodon:
1682 self._thread = threading.current_thread() 1684 self._thread = threading.current_thread()
1683 with closing(connection) as r: 1685 with closing(connection) as r:
1684 try: 1686 try:
1685 listener.handle_stream(r.iter_lines()) 1687 listener.handle_stream(r.iter_lines(chunk_size = 1, decode_unicode = True))
1686 except AttributeError as e: 1688 except AttributeError as e:
1687 # Eat AttributeError from requests if user closes early 1689 if not self.closed:
1688 pass 1690 raise e
1689 return 0 1691 return 0
1690 1692
1691 handle = __stream_handle(connection) 1693 handle = __stream_handle(connection)
Powered by cgit v1.2.3 (git 2.41.0)