From f41b41696a98d229607b4a8d1abafde822235759 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 28 Jun 2018 15:32:18 +0200 Subject: [PATCH] Fix generators --- setup.py | 3 +-- telethon/client/chats.py | 9 +++------ telethon/client/dialogs.py | 8 ++------ telethon/client/messages.py | 14 +++++--------- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/setup.py b/setup.py index 62287f7f..a1db7472 100755 --- a/setup.py +++ b/setup.py @@ -222,8 +222,7 @@ def main(): packages=find_packages(exclude=[ 'telethon_*', 'run_tests.py', 'try_telethon.py' ]), - install_requires=['pyaes', 'rsa', - 'async_generator'], + install_requires=['pyaes', 'rsa'], extras_require={ 'cryptg': ['cryptg'] } diff --git a/telethon/client/chats.py b/telethon/client/chats.py index e3a35b0d..e92862e0 100644 --- a/telethon/client/chats.py +++ b/telethon/client/chats.py @@ -1,7 +1,5 @@ from collections import UserList -from async_generator import async_generator, yield_ - from .users import UserMethods from .. import utils from ..tl import types, functions @@ -11,7 +9,6 @@ class ChatMethods(UserMethods): # region Public methods - @async_generator def iter_participants( self, entity, limit=None, *, search='', filter=None, aggressive=False, _total=None): @@ -133,7 +130,7 @@ class ChatMethods(UserMethods): seen.add(participant.user_id) user = users[participant.user_id] user.participant = participant - yield_(user) + yield (user) if len(seen) >= limit: return @@ -161,7 +158,7 @@ class ChatMethods(UserMethods): else: user = users[participant.user_id] user.participant = participant - yield_(user) + yield (user) else: if _total: _total[0] = 1 @@ -169,7 +166,7 @@ class ChatMethods(UserMethods): user = self.get_entity(entity) if filter_entity(user): user.participant = None - yield_(user) + yield (user) def get_participants(self, *args, **kwargs): """ diff --git a/telethon/client/dialogs.py b/telethon/client/dialogs.py index 32c88fc2..cba960cf 100644 --- a/telethon/client/dialogs.py +++ b/telethon/client/dialogs.py @@ -1,8 +1,6 @@ import itertools from collections import UserList -from async_generator import async_generator, yield_ - from .users import UserMethods from .. import utils from ..tl import types, functions, custom @@ -12,7 +10,6 @@ class DialogMethods(UserMethods): # region Public methods - @async_generator def iter_dialogs( self, limit=None, *, offset_date=None, offset_id=0, offset_peer=types.InputPeerEmpty(), ignore_migrated=False, @@ -97,7 +94,7 @@ class DialogMethods(UserMethods): if not ignore_migrated or getattr( cd.entity, 'migrated_to', None) is None: - yield_(cd) + yield (cd) if len(r.dialogs) < req.limit\ or not isinstance(r, types.messages.DialogsSlice): @@ -129,7 +126,6 @@ class DialogMethods(UserMethods): dialogs.total = total[0] return dialogs - @async_generator def iter_drafts(self): """ Iterator over all open draft messages. @@ -141,7 +137,7 @@ class DialogMethods(UserMethods): """ r = self(functions.messages.GetAllDraftsRequest()) for update in r.updates: - yield_(custom.Draft._from_update(self, update)) + yield (custom.Draft._from_update(self, update)) def get_drafts(self): """ diff --git a/telethon/client/messages.py b/telethon/client/messages.py index f27db425..989b7d39 100644 --- a/telethon/client/messages.py +++ b/telethon/client/messages.py @@ -4,8 +4,6 @@ import logging import time from collections import UserList -from async_generator import async_generator, yield_ - from .messageparse import MessageParseMethods from .uploads import UploadMethods from .. import utils @@ -20,7 +18,6 @@ class MessageMethods(UploadMethods, MessageParseMethods): # region Message retrieval - @async_generator def iter_messages( self, entity, limit=None, *, offset_date=None, offset_id=0, max_id=0, min_id=0, add_offset=0, search=None, filter=None, @@ -116,7 +113,7 @@ class MessageMethods(UploadMethods, MessageParseMethods): if not utils.is_list_like(ids): ids = (ids,) for x in self._iter_ids(entity, ids, total=_total): - yield_(x) + yield (x) return # Telegram doesn't like min_id/max_id. If these IDs are low enough @@ -213,7 +210,7 @@ class MessageMethods(UploadMethods, MessageParseMethods): # IDs are returned in descending order. last_id = message.id - yield_(custom.Message(self, message, entities, entity)) + yield (custom.Message(self, message, entities, entity)) have += 1 if len(r.messages) < request.limit: @@ -644,7 +641,6 @@ class MessageMethods(UploadMethods, MessageParseMethods): # region Private methods - @async_generator def _iter_ids(self, entity, ids, total): """ Special case for `iter_messages` when it should only fetch some IDs. @@ -662,7 +658,7 @@ class MessageMethods(UploadMethods, MessageParseMethods): if isinstance(r, types.messages.MessagesNotModified): for _ in ids: - yield_(None) + yield (None) return entities = {utils.get_peer_id(x): x @@ -677,8 +673,8 @@ class MessageMethods(UploadMethods, MessageParseMethods): for message in r.messages: if isinstance(message, types.MessageEmpty) or ( from_id and utils.get_peer_id(message.to_id) != from_id): - yield_(None) + yield (None) else: - yield_(custom.Message(self, message, entities, entity)) + yield (custom.Message(self, message, entities, entity)) # endregion