2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Fix errors and warnings when using Pyrogram async with Python <3.5.3

This commit is contained in:
Dan 2019-07-04 12:57:07 +02:00
parent ac4714c0dd
commit ee1f6e2c9f
7 changed files with 34 additions and 23 deletions

View File

@ -447,7 +447,8 @@ class Client(Methods, BaseClient):
Raises: Raises:
RPCError: In case of a Telegram RPC error. RPCError: In case of a Telegram RPC error.
""" """
run = asyncio.get_event_loop().run_until_complete loop = asyncio.get_event_loop()
run = loop.run_until_complete
run(self.start()) run(self.start())
@ -460,6 +461,8 @@ class Client(Methods, BaseClient):
if self.is_started: if self.is_started:
run(self.stop()) run(self.stop())
loop.close()
return coroutine return coroutine
def add_handler(self, handler: Handler, group: int = 0): def add_handler(self, handler: Handler, group: int = 0):

View File

@ -19,7 +19,6 @@
from typing import Union, List from typing import Union, List
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
@ -45,14 +44,19 @@ class ArchiveChats(BaseClient):
if not isinstance(chat_ids, list): if not isinstance(chat_ids, list):
chat_ids = [chat_ids] chat_ids = [chat_ids]
folder_peers = []
for chat in chat_ids:
folder_peers.append(
types.InputFolderPeer(
peer=await self.resolve_peer(chat),
folder_id=1
)
)
await self.send( await self.send(
functions.folders.EditPeerFolders( functions.folders.EditPeerFolders(
folder_peers=[ folder_peers=folder_peers
types.InputFolderPeer(
peer=await self.resolve_peer(chat),
folder_id=1
) for chat in chat_ids
]
) )
) )

View File

@ -17,7 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from string import ascii_lowercase from string import ascii_lowercase
from typing import Union, AsyncGenerator, Optional from typing import Union, Generator, Optional
import pyrogram import pyrogram
from async_generator import async_generator, yield_ from async_generator import async_generator, yield_
@ -47,7 +47,7 @@ class IterChatMembers(BaseClient):
limit: int = 0, limit: int = 0,
query: str = "", query: str = "",
filter: str = Filters.ALL filter: str = Filters.ALL
) -> Optional[AsyncGenerator["pyrogram.ChatMember", None]]: ) -> Optional[Generator["pyrogram.ChatMember", None, None]]:
"""Iterate through the members of a chat sequentially. """Iterate through the members of a chat sequentially.
This convenience method does the same as repeatedly calling :meth:`~Client.get_chat_members` in a loop, thus saving you This convenience method does the same as repeatedly calling :meth:`~Client.get_chat_members` in a loop, thus saving you

View File

@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import AsyncGenerator, Optional from typing import Generator, Optional
import pyrogram import pyrogram
from async_generator import async_generator, yield_ from async_generator import async_generator, yield_
@ -30,7 +30,7 @@ class IterDialogs(BaseClient):
self, self,
limit: int = 0, limit: int = 0,
offset_date: int = None offset_date: int = None
) -> Optional[AsyncGenerator["pyrogram.Dialog", None]]: ) -> Optional[Generator["pyrogram.Dialog", None, None]]:
"""Iterate through a user's dialogs sequentially. """Iterate through a user's dialogs sequentially.
This convenience method does the same as repeatedly calling :meth:`~Client.get_dialogs` in a loop, thus saving This convenience method does the same as repeatedly calling :meth:`~Client.get_dialogs` in a loop, thus saving

View File

@ -19,7 +19,6 @@
from typing import Union, List from typing import Union, List
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
@ -45,14 +44,19 @@ class UnarchiveChats(BaseClient):
if not isinstance(chat_ids, list): if not isinstance(chat_ids, list):
chat_ids = [chat_ids] chat_ids = [chat_ids]
folder_peers = []
for chat in chat_ids:
folder_peers.append(
types.InputFolderPeer(
peer=await self.resolve_peer(chat),
folder_id=0
)
)
await self.send( await self.send(
functions.folders.EditPeerFolders( functions.folders.EditPeerFolders(
folder_peers=[ folder_peers=folder_peers
types.InputFolderPeer(
peer=await self.resolve_peer(chat),
folder_id=0
) for chat in chat_ids
]
) )
) )

View File

@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union, Optional, AsyncGenerator from typing import Union, Optional, Generator
import pyrogram import pyrogram
from async_generator import async_generator, yield_ from async_generator import async_generator, yield_
@ -34,7 +34,7 @@ class IterHistory(BaseClient):
offset_id: int = 0, offset_id: int = 0,
offset_date: int = 0, offset_date: int = 0,
reverse: bool = False reverse: bool = False
) -> Optional[AsyncGenerator["pyrogram.Message", None]]: ) -> Optional[Generator["pyrogram.Message", None, None]]:
"""Iterate through a chat history sequentially. """Iterate through a chat history sequentially.
This convenience method does the same as repeatedly calling :meth:`~Client.get_history` in a loop, thus saving This convenience method does the same as repeatedly calling :meth:`~Client.get_history` in a loop, thus saving

View File

@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union, AsyncGenerator, Optional from typing import Union, Generator, Optional
import pyrogram import pyrogram
from async_generator import async_generator, yield_ from async_generator import async_generator, yield_
@ -31,7 +31,7 @@ class IterProfilePhotos(BaseClient):
chat_id: Union[int, str], chat_id: Union[int, str],
offset: int = 0, offset: int = 0,
limit: int = 0, limit: int = 0,
) -> Optional[AsyncGenerator["pyrogram.Message", None]]: ) -> Optional[Generator["pyrogram.Message", None, None]]:
"""Iterate through a chat or a user profile photos sequentially. """Iterate through a chat or a user profile photos sequentially.
This convenience method does the same as repeatedly calling :meth:`~Client.get_profile_photos` in a loop, thus This convenience method does the same as repeatedly calling :meth:`~Client.get_profile_photos` in a loop, thus