diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index fe204a98..122ce843 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -171,8 +171,8 @@ def start(): shutil.rmtree("{}/functions".format(DESTINATION), ignore_errors=True) with open("{}/source/auth_key.tl".format(HOME), encoding="utf-8") as auth, \ - open("{}/source/sys_msgs.tl".format(HOME), encoding="utf-8") as system, \ - open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api: + open("{}/source/sys_msgs.tl".format(HOME), encoding="utf-8") as system, \ + open("{}/source/main_api.tl".format(HOME), encoding="utf-8") as api: schema = (auth.read() + system.read() + api.read()).splitlines() with open("{}/template/mtproto.txt".format(HOME), encoding="utf-8") as f: diff --git a/compiler/error/compiler.py b/compiler/error/compiler.py index b86222e7..751db1bc 100644 --- a/compiler/error/compiler.py +++ b/compiler/error/compiler.py @@ -73,7 +73,7 @@ def start(): f_init.write("from .{}_{} import *\n".format(name.lower(), code)) with open("{}/source/{}".format(HOME, i), encoding="utf-8") as f_csv, \ - open("{}/{}_{}.py".format(DEST, name.lower(), code), "w", encoding="utf-8") as f_class: + open("{}/{}_{}.py".format(DEST, name.lower(), code), "w", encoding="utf-8") as f_class: reader = csv.reader(f_csv, delimiter="\t") super_class = caml(name) diff --git a/pyrogram/client/methods/chats/restrict_chat.py b/pyrogram/client/methods/chats/restrict_chat.py index 502d9566..ca3e8055 100644 --- a/pyrogram/client/methods/chats/restrict_chat.py +++ b/pyrogram/client/methods/chats/restrict_chat.py @@ -25,16 +25,16 @@ from ...types.user_and_chats import Chat class RestrictChat(BaseClient): def restrict_chat( - self, - chat_id: Union[int, str], - can_send_messages: bool = False, - can_send_media_messages: bool = False, - can_send_other_messages: bool = False, - can_add_web_page_previews: bool = False, - can_send_polls: bool = False, - can_change_info: bool = False, - can_invite_users: bool = False, - can_pin_messages: bool = False + self, + chat_id: Union[int, str], + can_send_messages: bool = False, + can_send_media_messages: bool = False, + can_send_other_messages: bool = False, + can_add_web_page_previews: bool = False, + can_send_polls: bool = False, + can_change_info: bool = False, + can_invite_users: bool = False, + can_pin_messages: bool = False ) -> Chat: """Use this method to restrict a chat. Pass True for all boolean parameters to lift restrictions from a chat. diff --git a/pyrogram/client/methods/chats/restrict_chat_member.py b/pyrogram/client/methods/chats/restrict_chat_member.py index f4545cb1..d75d1fa4 100644 --- a/pyrogram/client/methods/chats/restrict_chat_member.py +++ b/pyrogram/client/methods/chats/restrict_chat_member.py @@ -25,18 +25,18 @@ from ...types.user_and_chats import Chat class RestrictChatMember(BaseClient): def restrict_chat_member( - self, - chat_id: Union[int, str], - user_id: Union[int, str], - until_date: int = 0, - can_send_messages: bool = False, - can_send_media_messages: bool = False, - can_send_other_messages: bool = False, - can_add_web_page_previews: bool = False, - can_send_polls: bool = False, - can_change_info: bool = False, - can_invite_users: bool = False, - can_pin_messages: bool = False + self, + chat_id: Union[int, str], + user_id: Union[int, str], + until_date: int = 0, + can_send_messages: bool = False, + can_send_media_messages: bool = False, + can_send_other_messages: bool = False, + can_add_web_page_previews: bool = False, + can_send_polls: bool = False, + can_change_info: bool = False, + can_invite_users: bool = False, + can_pin_messages: bool = False ) -> Chat: """Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift diff --git a/pyrogram/client/methods/chats/update_chat_username.py b/pyrogram/client/methods/chats/update_chat_username.py index 156ee6f8..353c338e 100644 --- a/pyrogram/client/methods/chats/update_chat_username.py +++ b/pyrogram/client/methods/chats/update_chat_username.py @@ -45,7 +45,7 @@ class UpdateChatUsername(BaseClient): """ peer = self.resolve_peer(chat_id) - + if isinstance(peer, types.InputPeerChannel): return bool( self.send( diff --git a/pyrogram/client/methods/messages/download_media.py b/pyrogram/client/methods/messages/download_media.py index 181daa14..1c80f63a 100644 --- a/pyrogram/client/methods/messages/download_media.py +++ b/pyrogram/client/methods/messages/download_media.py @@ -106,15 +106,15 @@ class DownloadMedia(BaseClient): else: raise ValueError(error_message) elif isinstance(message, ( - pyrogram.Photo, - pyrogram.PhotoSize, - pyrogram.Audio, - pyrogram.Document, - pyrogram.Video, - pyrogram.Voice, - pyrogram.VideoNote, - pyrogram.Sticker, - pyrogram.Animation + pyrogram.Photo, + pyrogram.PhotoSize, + pyrogram.Audio, + pyrogram.Document, + pyrogram.Video, + pyrogram.Voice, + pyrogram.VideoNote, + pyrogram.Sticker, + pyrogram.Animation )): if isinstance(message, pyrogram.Photo): media = pyrogram.Document( diff --git a/pyrogram/client/methods/messages/send_cached_media.py b/pyrogram/client/methods/messages/send_cached_media.py index 843b7197..90c9b09f 100644 --- a/pyrogram/client/methods/messages/send_cached_media.py +++ b/pyrogram/client/methods/messages/send_cached_media.py @@ -28,19 +28,19 @@ from pyrogram.client.ext import BaseClient, utils class SendCachedMedia(BaseClient): def send_cached_media( - self, - chat_id: Union[int, str], - file_id: str, - caption: str = "", - parse_mode: str = "", - disable_notification: bool = None, - reply_to_message_id: int = None, - reply_markup: Union[ - "pyrogram.InlineKeyboardMarkup", - "pyrogram.ReplyKeyboardMarkup", - "pyrogram.ReplyKeyboardRemove", - "pyrogram.ForceReply" - ] = None + self, + chat_id: Union[int, str], + file_id: str, + caption: str = "", + parse_mode: str = "", + disable_notification: bool = None, + reply_to_message_id: int = None, + reply_markup: Union[ + "pyrogram.InlineKeyboardMarkup", + "pyrogram.ReplyKeyboardMarkup", + "pyrogram.ReplyKeyboardRemove", + "pyrogram.ForceReply" + ] = None ) -> Union["pyrogram.Message", None]: """Use this method to send any media stored on the Telegram servers using a file_id. diff --git a/pyrogram/client/types/user_and_chats/chat_permissions.py b/pyrogram/client/types/user_and_chats/chat_permissions.py index 4a4785b5..7b35b1d0 100644 --- a/pyrogram/client/types/user_and_chats/chat_permissions.py +++ b/pyrogram/client/types/user_and_chats/chat_permissions.py @@ -102,27 +102,27 @@ class ChatPermissions(PyrogramType): ] def __init__( - self, - *, - until_date: int = None, + self, + *, + until_date: int = None, - # Admin permissions - can_be_edited: bool = None, - can_change_info: bool = None, - can_post_messages: bool = None, # Channels only - can_edit_messages: bool = None, # Channels only - can_delete_messages: bool = None, - can_restrict_members: bool = None, - can_invite_users: bool = None, - can_pin_messages: bool = None, # Supergroups only - can_promote_members: bool = None, + # Admin permissions + can_be_edited: bool = None, + can_change_info: bool = None, + can_post_messages: bool = None, # Channels only + can_edit_messages: bool = None, # Channels only + can_delete_messages: bool = None, + can_restrict_members: bool = None, + can_invite_users: bool = None, + can_pin_messages: bool = None, # Supergroups only + can_promote_members: bool = None, - # Restricted user permissions - can_send_messages: bool = None, # Text, contacts, locations and venues - can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes - can_send_other_messages: bool = None, # Animations (GIFs), games, stickers, inline bot results - can_add_web_page_previews: bool = None, - can_send_polls: bool = None + # Restricted user permissions + can_send_messages: bool = None, # Text, contacts, locations and venues + can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes + can_send_other_messages: bool = None, # Animations (GIFs), games, stickers, inline bot results + can_add_web_page_previews: bool = None, + can_send_polls: bool = None ): super().__init__(None) @@ -146,11 +146,11 @@ class ChatPermissions(PyrogramType): @staticmethod def _parse( - entity: Union[ - types.ChannelParticipantAdmin, - types.ChannelParticipantBanned, - types.ChatBannedRights - ] + entity: Union[ + types.ChannelParticipantAdmin, + types.ChannelParticipantBanned, + types.ChatBannedRights + ] ) -> "ChatPermissions": if isinstance(entity, types.ChannelParticipantAdmin): permissions = entity.admin_rights @@ -178,8 +178,8 @@ class ChatPermissions(PyrogramType): can_send_messages=not denied_permissions.send_messages, can_send_media_messages=not denied_permissions.send_media, can_send_other_messages=( - not denied_permissions.send_stickers or not denied_permissions.send_gifs or - not denied_permissions.send_games or not denied_permissions.send_inline + not denied_permissions.send_stickers or not denied_permissions.send_gifs or + not denied_permissions.send_games or not denied_permissions.send_inline ), can_add_web_page_previews=not denied_permissions.embed_links, can_send_polls=not denied_permissions.send_polls, diff --git a/pyrogram/connection/transport/tcp/tcp_abridged_o.py b/pyrogram/connection/transport/tcp/tcp_abridged_o.py index d15d0389..136d22ef 100644 --- a/pyrogram/connection/transport/tcp/tcp_abridged_o.py +++ b/pyrogram/connection/transport/tcp/tcp_abridged_o.py @@ -40,9 +40,7 @@ class TCPAbridgedO(TCP): while True: nonce = bytearray(os.urandom(64)) - if (nonce[0] != b"\xef" - and nonce[:4] not in self.RESERVED - and nonce[4:4] != b"\x00" * 4): + if nonce[0] != b"\xef" and nonce[:4] not in self.RESERVED and nonce[4:4] != b"\x00" * 4: nonce[56] = nonce[57] = nonce[58] = nonce[59] = 0xef break diff --git a/pyrogram/connection/transport/tcp/tcp_intermediate_o.py b/pyrogram/connection/transport/tcp/tcp_intermediate_o.py index c59deed7..a92acb7f 100644 --- a/pyrogram/connection/transport/tcp/tcp_intermediate_o.py +++ b/pyrogram/connection/transport/tcp/tcp_intermediate_o.py @@ -41,9 +41,7 @@ class TCPIntermediateO(TCP): while True: nonce = bytearray(os.urandom(64)) - if (nonce[0] != b"\xef" - and nonce[:4] not in self.RESERVED - and nonce[4:4] != b"\x00" * 4): + if nonce[0] != b"\xef" and nonce[:4] not in self.RESERVED and nonce[4:4] != b"\x00" * 4: nonce[56] = nonce[57] = nonce[58] = nonce[59] = 0xee break diff --git a/pyrogram/vendor/typing/typing.py b/pyrogram/vendor/typing/typing.py index 2189cd48..16888d3f 100644 --- a/pyrogram/vendor/typing/typing.py +++ b/pyrogram/vendor/typing/typing.py @@ -1,17 +1,18 @@ import abc -from abc import abstractmethod, abstractproperty import collections import contextlib import functools import re as stdlib_re # Avoid confusion with the re we export. import sys import types +from abc import abstractmethod, abstractproperty + try: import collections.abc as collections_abc except ImportError: import collections as collections_abc # Fallback for PY3.2. if sys.version_info[:2] >= (3, 6): - import _collections_abc # Needed for private function _check_methods # noqa + pass try: from types import WrapperDescriptorType, MethodWrapperType, MethodDescriptorType except ImportError: @@ -19,7 +20,6 @@ except ImportError: MethodWrapperType = type(object().__str__) MethodDescriptorType = type(str.join) - # Please keep __all__ alphabetized within each category. __all__ = [ # Super-special typing primitives. @@ -36,7 +36,7 @@ __all__ = [ # ABCs (from collections.abc). 'AbstractSet', # collections.abc.Set. 'GenericMeta', # subclass of abc.ABCMeta and a metaclass - # for 'Generic' and ABCs below. + # for 'Generic' and ABCs below. 'ByteString', 'Container', 'ContextManager', @@ -96,6 +96,7 @@ __all__ = [ 'TYPE_CHECKING', ] + # The pseudo-submodules 're' and 'io' are part of the public # namespace, but excluded from __all__ because they might stomp on # legitimate imports of those modules. @@ -173,8 +174,8 @@ class _TypingBase(metaclass=TypingMeta, _root=True): someone tries to subclass a special typing object (not a good idea). """ if (len(args) == 3 and - isinstance(args[0], str) and - isinstance(args[1], tuple)): + isinstance(args[0], str) and + isinstance(args[1], tuple)): # Close enough. raise TypeError("Cannot subclass %r" % cls) return super().__new__(cls) @@ -396,7 +397,7 @@ def _type_repr(obj): return _qualname(obj) return '%s.%s' % (obj.__module__, _qualname(obj)) if obj is ...: - return('...') + return ('...') if isinstance(obj, types.FunctionType): return obj.__name__ return repr(obj) @@ -681,6 +682,7 @@ def _tp_cache(func): except TypeError: pass # All real errors (not unhashable args) are raised below. return func(*args, **kwds) + return inner @@ -948,7 +950,7 @@ class GenericMeta(TypingMeta, abc.ABCMeta): if base is Generic: raise TypeError("Cannot inherit from plain Generic") if (isinstance(base, GenericMeta) and - base.__origin__ is Generic): + base.__origin__ is Generic): if gvars is not None: raise TypeError( "Cannot inherit from Generic[...] multiple types.") @@ -1183,14 +1185,14 @@ def _generic_new(base_cls, cls, *args, **kwds): # but attempt to store it in __orig_class__ if cls.__origin__ is None: if (base_cls.__new__ is object.__new__ and - cls.__init__ is not object.__init__): + cls.__init__ is not object.__init__): return base_cls.__new__(cls) else: return base_cls.__new__(cls, *args, **kwds) else: origin = cls._gorg if (base_cls.__new__ is object.__new__ and - cls.__init__ is not object.__init__): + cls.__init__ is not object.__init__): obj = base_cls.__new__(origin) else: obj = base_cls.__new__(origin, *args, **kwds) @@ -1399,7 +1401,7 @@ class _ClassVar(_FinalTypingBase, _root=True): cls = type(self) if self.__type__ is None: return cls(_type_check(item, - '{} accepts only single type.'.format(cls.__name__[1:])), + '{} accepts only single type.'.format(cls.__name__[1:])), _root=True) raise TypeError('{} cannot be further subscripted' .format(cls.__name__[1:])) @@ -1671,26 +1673,26 @@ class _ProtocolMeta(GenericMeta): # Include attributes not defined in any non-protocol bases. for c in self.__mro__: if (c is not base and attr in c.__dict__ and - not getattr(c, '_is_protocol', False)): + not getattr(c, '_is_protocol', False)): break else: if (not attr.startswith('_abc_') and - attr != '__abstractmethods__' and - attr != '__annotations__' and - attr != '__weakref__' and - attr != '_is_protocol' and - attr != '_gorg' and - attr != '__dict__' and - attr != '__args__' and - attr != '__slots__' and - attr != '_get_protocol_attrs' and - attr != '__next_in_mro__' and - attr != '__parameters__' and - attr != '__origin__' and - attr != '__orig_bases__' and - attr != '__extra__' and - attr != '__tree_hash__' and - attr != '__module__'): + attr != '__abstractmethods__' and + attr != '__annotations__' and + attr != '__weakref__' and + attr != '_is_protocol' and + attr != '_gorg' and + attr != '__dict__' and + attr != '__args__' and + attr != '__slots__' and + attr != '_get_protocol_attrs' and + attr != '__next_in_mro__' and + attr != '__parameters__' and + attr != '__origin__' and + attr != '__orig_bases__' and + attr != '__extra__' and + attr != '__tree_hash__' and + attr != '__module__'): attrs.add(attr) return attrs @@ -1714,31 +1716,31 @@ class _Protocol(metaclass=_ProtocolMeta): Hashable = collections_abc.Hashable # Not generic. - if hasattr(collections_abc, 'Awaitable'): class Awaitable(Generic[T_co], extra=collections_abc.Awaitable): __slots__ = () - __all__.append('Awaitable') + __all__.append('Awaitable') if hasattr(collections_abc, 'Coroutine'): class Coroutine(Awaitable[V_co], Generic[T_co, T_contra, V_co], extra=collections_abc.Coroutine): __slots__ = () + __all__.append('Coroutine') - if hasattr(collections_abc, 'AsyncIterable'): - class AsyncIterable(Generic[T_co], extra=collections_abc.AsyncIterable): __slots__ = () + class AsyncIterator(AsyncIterable[T_co], extra=collections_abc.AsyncIterator): __slots__ = () + __all__.append('AsyncIterable') __all__.append('AsyncIterator') @@ -1810,7 +1812,6 @@ else: def __reversed__(self) -> 'Iterator[T_co]': pass - Sized = collections_abc.Sized # Not generic. @@ -1823,8 +1824,8 @@ if hasattr(collections_abc, 'Collection'): extra=collections_abc.Collection): __slots__ = () - __all__.append('Collection') + __all__.append('Collection') # Callable was defined earlier. @@ -1881,7 +1882,6 @@ class ByteString(Sequence[int], extra=collections_abc.ByteString): class List(list, MutableSequence[T], extra=list): - __slots__ = () def __new__(cls, *args, **kwds): @@ -1892,7 +1892,6 @@ class List(list, MutableSequence[T], extra=list): class Deque(collections.deque, MutableSequence[T], extra=collections.deque): - __slots__ = () def __new__(cls, *args, **kwds): @@ -1902,7 +1901,6 @@ class Deque(collections.deque, MutableSequence[T], extra=collections.deque): class Set(set, MutableSet[T], extra=set): - __slots__ = () def __new__(cls, *args, **kwds): @@ -1969,12 +1967,12 @@ else: return True return NotImplemented - if hasattr(contextlib, 'AbstractAsyncContextManager'): class AsyncContextManager(Generic[T_co], extra=contextlib.AbstractAsyncContextManager): __slots__ = () + __all__.append('AsyncContextManager') elif sys.version_info[:2] >= (3, 5): exec(""" @@ -2003,7 +2001,6 @@ __all__.append('AsyncContextManager') class Dict(dict, MutableMapping[KT, VT], extra=dict): - __slots__ = () def __new__(cls, *args, **kwds): @@ -2015,7 +2012,6 @@ class Dict(dict, MutableMapping[KT, VT], extra=dict): class DefaultDict(collections.defaultdict, MutableMapping[KT, VT], extra=collections.defaultdict): - __slots__ = () def __new__(cls, *args, **kwds): @@ -2025,7 +2021,6 @@ class DefaultDict(collections.defaultdict, MutableMapping[KT, VT], class Counter(collections.Counter, Dict[T, int], extra=collections.Counter): - __slots__ = () def __new__(cls, *args, **kwds): @@ -2038,6 +2033,7 @@ if hasattr(collections, 'ChainMap'): # ChainMap only exists in 3.3+ __all__.append('ChainMap') + class ChainMap(collections.ChainMap, MutableMapping[KT, VT], extra=collections.ChainMap): @@ -2048,7 +2044,6 @@ if hasattr(collections, 'ChainMap'): return collections.ChainMap(*args, **kwds) return _generic_new(collections.ChainMap, cls, *args, **kwds) - # Determine what base class to use for Generator. if hasattr(collections_abc, 'Generator'): # Sufficiently recent versions of 3.5 have a Generator ABC. @@ -2074,8 +2069,8 @@ if hasattr(collections_abc, 'AsyncGenerator'): extra=collections_abc.AsyncGenerator): __slots__ = () - __all__.append('AsyncGenerator') + __all__.append('AsyncGenerator') # Internal type variable used for Type[]. CT_co = TypeVar('CT_co', covariant=True, bound=type) @@ -2237,7 +2232,6 @@ def NewType(name, tp): # Python-version-specific alias (Python 2: unicode; Python 3: str) Text = str - # Constant that's True when type checking, but False here. TYPE_CHECKING = False @@ -2394,7 +2388,6 @@ class io: io.__name__ = __name__ + '.io' sys.modules[io.__name__] = io - Pattern = _TypeAlias('Pattern', AnyStr, type(stdlib_re.compile('')), lambda p: p.pattern) Match = _TypeAlias('Match', AnyStr, type(stdlib_re.match('', '')),