Some fixes and speed improvments (#439)
* Use raw string for re pattern * Trim trailing whitespaces from docstrings and code * Use isinstance() instead of type() for typechecking * Remove unused imports
This commit is contained in:
parent
5261e9550e
commit
531069b1e2
@ -26,7 +26,7 @@ NOTICE_PATH = "NOTICE"
|
|||||||
SECTION_RE = re.compile(r"---(\w+)---")
|
SECTION_RE = re.compile(r"---(\w+)---")
|
||||||
LAYER_RE = re.compile(r"//\sLAYER\s(\d+)")
|
LAYER_RE = re.compile(r"//\sLAYER\s(\d+)")
|
||||||
COMBINATOR_RE = re.compile(r"^([\w.]+)#([0-9a-f]+)\s(?:.*)=\s([\w<>.]+);(?: // Docs: (.+))?$", re.MULTILINE)
|
COMBINATOR_RE = re.compile(r"^([\w.]+)#([0-9a-f]+)\s(?:.*)=\s([\w<>.]+);(?: // Docs: (.+))?$", re.MULTILINE)
|
||||||
ARGS_RE = re.compile("[^{](\w+):([\w?!.<>#]+)")
|
ARGS_RE = re.compile(r"[^{](\w+):([\w?!.<>#]+)")
|
||||||
FLAGS_RE = re.compile(r"flags\.(\d+)\?")
|
FLAGS_RE = re.compile(r"flags\.(\d+)\?")
|
||||||
FLAGS_RE_2 = re.compile(r"flags\.(\d+)\?([\w<>.]+)")
|
FLAGS_RE_2 = re.compile(r"flags\.(\d+)\?([\w<>.]+)")
|
||||||
FLAGS_RE_3 = re.compile(r"flags:#")
|
FLAGS_RE_3 = re.compile(r"flags:#")
|
||||||
|
@ -1649,7 +1649,7 @@ class Client(Methods, BaseClient):
|
|||||||
try:
|
try:
|
||||||
return self.storage.get_peer_by_id(peer_id)
|
return self.storage.get_peer_by_id(peer_id)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if type(peer_id) is str:
|
if isinstance(peer_id, str):
|
||||||
if peer_id in ("self", "me"):
|
if peer_id in ("self", "me"):
|
||||||
return types.InputPeerSelf()
|
return types.InputPeerSelf()
|
||||||
|
|
||||||
|
@ -277,11 +277,11 @@ class Filters:
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
commands = commands if type(commands) is list else [commands]
|
commands = commands if isinstance(commands, list) else [commands]
|
||||||
commands = {c if case_sensitive else c.lower() for c in commands}
|
commands = {c if case_sensitive else c.lower() for c in commands}
|
||||||
|
|
||||||
prefixes = [] if prefixes is None else prefixes
|
prefixes = [] if prefixes is None else prefixes
|
||||||
prefixes = prefixes if type(prefixes) is list else [prefixes]
|
prefixes = prefixes if isinstance(prefixes, list) else [prefixes]
|
||||||
prefixes = set(prefixes) if prefixes else {""}
|
prefixes = set(prefixes) if prefixes else {""}
|
||||||
|
|
||||||
return create(
|
return create(
|
||||||
@ -345,11 +345,11 @@ class Filters:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, users: int or str or list = None):
|
def __init__(self, users: int or str or list = None):
|
||||||
users = [] if users is None else users if type(users) is list else [users]
|
users = [] if users is None else users if isinstance(users, list) else [users]
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"me" if u in ["me", "self"]
|
"me" if u in ["me", "self"]
|
||||||
else u.lower().strip("@") if type(u) is str
|
else u.lower().strip("@") if isinstance(u, str)
|
||||||
else u for u in users
|
else u for u in users
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -376,11 +376,11 @@ class Filters:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, chats: int or str or list = None):
|
def __init__(self, chats: int or str or list = None):
|
||||||
chats = [] if chats is None else chats if type(chats) is list else [chats]
|
chats = [] if chats is None else chats if isinstance(chats, list) else [chats]
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"me" if c in ["me", "self"]
|
"me" if c in ["me", "self"]
|
||||||
else c.lower().strip("@") if type(c) is str
|
else c.lower().strip("@") if isinstance(c, str)
|
||||||
else c for c in chats
|
else c for c in chats
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions
|
||||||
from pyrogram.client.ext import BaseClient
|
from pyrogram.client.ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,12 +17,10 @@
|
|||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
|
||||||
from typing import Union, List
|
from typing import Union, List
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions, types
|
||||||
from pyrogram.errors import FloodWait
|
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -17,12 +17,10 @@
|
|||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions, types
|
||||||
from pyrogram.errors import FloodWait
|
|
||||||
from ...ext import BaseClient, utils
|
from ...ext import BaseClient, utils
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -17,13 +17,11 @@
|
|||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
|
||||||
from typing import Union, List
|
from typing import Union, List
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import functions
|
from pyrogram.api import functions
|
||||||
from pyrogram.client.ext import utils
|
from pyrogram.client.ext import utils
|
||||||
from pyrogram.errors import FloodWait
|
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -17,12 +17,10 @@
|
|||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
|
||||||
from typing import Union, Iterable, List
|
from typing import Union, Iterable, List
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions, types
|
||||||
from pyrogram.errors import FloodWait
|
|
||||||
from ...ext import BaseClient, utils
|
from ...ext import BaseClient, utils
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from struct import pack
|
from struct import pack
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
@ -41,7 +40,6 @@ from pyrogram.client.types.object import Object
|
|||||||
from pyrogram.client.types.update import Update
|
from pyrogram.client.types.update import Update
|
||||||
from pyrogram.client.types.user_and_chats import User
|
from pyrogram.client.types.user_and_chats import User
|
||||||
from pyrogram.client.types.messages_and_media import Location
|
from pyrogram.client.types.messages_and_media import Location
|
||||||
from pyrogram.client.ext import utils
|
|
||||||
|
|
||||||
|
|
||||||
class ChosenInlineResult(Object, Update):
|
class ChosenInlineResult(Object, Update):
|
||||||
|
@ -16,14 +16,9 @@
|
|||||||
# 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 struct import pack
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from .thumbnail import Thumbnail
|
|
||||||
from ..object import Object
|
from ..object import Object
|
||||||
from ...ext.utils import encode_file_id, encode_file_ref
|
|
||||||
|
|
||||||
|
|
||||||
class Dice(Object):
|
class Dice(Object):
|
||||||
|
@ -23,7 +23,7 @@ from pyrogram.api.core import Message, MsgContainer, TLObject
|
|||||||
from .msg_id import MsgId
|
from .msg_id import MsgId
|
||||||
from .seq_no import SeqNo
|
from .seq_no import SeqNo
|
||||||
|
|
||||||
not_content_related = [Ping, HttpWait, MsgsAck, MsgContainer]
|
not_content_related = (Ping, HttpWait, MsgsAck, MsgContainer)
|
||||||
|
|
||||||
|
|
||||||
class MsgFactory:
|
class MsgFactory:
|
||||||
@ -34,6 +34,6 @@ class MsgFactory:
|
|||||||
return Message(
|
return Message(
|
||||||
body,
|
body,
|
||||||
MsgId(),
|
MsgId(),
|
||||||
self.seq_no(type(body) not in not_content_related),
|
self.seq_no(not isinstance(body, not_content_related)),
|
||||||
len(body)
|
len(body)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user