|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present <https://github.com/TelegramPlayGround> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | + |
| 20 | +from asyncio import sleep |
| 21 | + |
| 22 | +import pyrogram |
| 23 | +from pyrogram.raw.core import TLObject |
| 24 | + |
| 25 | + |
| 26 | +class IterInvoke: |
| 27 | + async def iter_invoke( |
| 28 | + self: "pyrogram.Client", |
| 29 | + query: TLObject, |
| 30 | + key: str, |
| 31 | + ): |
| 32 | + """Invoke raw Telegram yield functions. |
| 33 | +
|
| 34 | + This method makes it possible to do bakchodi. |
| 35 | +
|
| 36 | + .. note:: |
| 37 | +
|
| 38 | + This is a utility method intended to be used **only** when working with raw |
| 39 | + :obj:`functions <pyrogram.api.functions>` (i.e: a Telegram API method you wish to use which is not |
| 40 | + available yet in the Client class as an easy-to-use method). |
| 41 | +
|
| 42 | + .. include:: /_includes/usable-by/users-bots.rst |
| 43 | +
|
| 44 | + Parameters: |
| 45 | + query (``RawFunction``): |
| 46 | + The API Schema function filled with proper arguments. |
| 47 | +
|
| 48 | + key (``str``): |
| 49 | + The key using which to yield the iterator. |
| 50 | +
|
| 51 | + Returns: |
| 52 | + ``Generator``: A generator yielding the raw type response object generated by the query. |
| 53 | +
|
| 54 | + Raises: |
| 55 | + RPCError: In case of a Telegram RPC error. |
| 56 | +
|
| 57 | + """ |
| 58 | + |
| 59 | + r = await self.invoke(query) |
| 60 | + s = getattr(r, key, []) |
| 61 | + for d in s: |
| 62 | + await sleep(0) |
| 63 | + yield d |
0 commit comments