mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-03 11:40:11 +03:00
Fix generators
This commit is contained in:
parent
e1f8807d83
commit
f41b41696a
3
setup.py
3
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']
|
||||
}
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user