mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 12:51:18 +00:00
Filter out empty entities internally (#1041)
* Filter out empty entities internally I guess it's fine to handle empty entities internally to avoid ENTITY_BOUNDS_INVALID , so the client won't send the empty entities * revert utils and apply changes to parser/html.py * Update utils.py * Update utils.py * Update utils.py * Update html.py * Update utils.py * Update utils.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
This commit is contained in:
parent
d9c8e0450b
commit
ed748952b5
@ -140,6 +140,9 @@ class HTML:
|
||||
|
||||
entities.append(entity)
|
||||
|
||||
# Remove zero-length entities
|
||||
entities = list(filter(lambda x: x.length > 0, entities))
|
||||
|
||||
return {
|
||||
"message": utils.remove_surrogates(parser.text),
|
||||
"entities": sorted(entities, key=lambda e: e.offset)
|
||||
@ -156,13 +159,21 @@ class HTML:
|
||||
start = entity.offset
|
||||
end = start + entity.length
|
||||
|
||||
if entity_type in (MessageEntityType.BOLD, MessageEntityType.ITALIC, MessageEntityType.UNDERLINE,
|
||||
MessageEntityType.STRIKETHROUGH):
|
||||
if entity_type in (
|
||||
MessageEntityType.BOLD,
|
||||
MessageEntityType.ITALIC,
|
||||
MessageEntityType.UNDERLINE,
|
||||
MessageEntityType.STRIKETHROUGH,
|
||||
):
|
||||
name = entity_type.name[0].lower()
|
||||
start_tag = f"<{name}>"
|
||||
end_tag = f"</{name}>"
|
||||
elif entity_type in (MessageEntityType.CODE, MessageEntityType.PRE, MessageEntityType.BLOCKQUOTE,
|
||||
MessageEntityType.SPOILER):
|
||||
elif entity_type in (
|
||||
MessageEntityType.CODE,
|
||||
MessageEntityType.PRE,
|
||||
MessageEntityType.BLOCKQUOTE,
|
||||
MessageEntityType.SPOILER,
|
||||
):
|
||||
name = entity_type.name.lower()
|
||||
start_tag = f"<{name}>"
|
||||
end_tag = f"</{name}>"
|
||||
|
@ -48,8 +48,10 @@ def get_input_media_from_file_id(
|
||||
try:
|
||||
decoded = FileId.decode(file_id)
|
||||
except Exception:
|
||||
raise ValueError(f'Failed to decode "{file_id}". The value does not represent an existing local file, '
|
||||
f'HTTP URL, or valid file id.')
|
||||
raise ValueError(
|
||||
f'Failed to decode "{file_id}". The value does not represent an existing local file, '
|
||||
f"HTTP URL, or valid file id."
|
||||
)
|
||||
|
||||
file_type = decoded.file_type
|
||||
|
||||
@ -82,7 +84,11 @@ def get_input_media_from_file_id(
|
||||
raise ValueError(f"Unknown file id: {file_id}")
|
||||
|
||||
|
||||
async def parse_messages(client, messages: "raw.types.messages.Messages", replies: int = 1) -> List["types.Message"]:
|
||||
async def parse_messages(
|
||||
client,
|
||||
messages: "raw.types.messages.Messages",
|
||||
replies: int = 1
|
||||
) -> List["types.Message"]:
|
||||
users = {i.id: i for i in messages.users}
|
||||
chats = {i.id: i for i in messages.chats}
|
||||
|
||||
@ -260,8 +266,10 @@ def xor(a: bytes, b: bytes) -> bytes:
|
||||
return bytes(i ^ j for i, j in zip(a, b))
|
||||
|
||||
|
||||
def compute_password_hash(algo: raw.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow,
|
||||
password: str) -> bytes:
|
||||
def compute_password_hash(
|
||||
algo: raw.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow,
|
||||
password: str
|
||||
) -> bytes:
|
||||
hash1 = sha256(algo.salt1 + password.encode() + algo.salt1)
|
||||
hash2 = sha256(algo.salt2 + hash1 + algo.salt2)
|
||||
hash3 = hashlib.pbkdf2_hmac("sha512", hash2, algo.salt1, 100000)
|
||||
@ -270,7 +278,10 @@ def compute_password_hash(algo: raw.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACS
|
||||
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
def compute_password_check(r: raw.types.account.Password, password: str) -> raw.types.InputCheckPasswordSRP:
|
||||
def compute_password_check(
|
||||
r: raw.types.account.Password,
|
||||
password: str
|
||||
) -> raw.types.InputCheckPasswordSRP:
|
||||
algo = r.current_algo
|
||||
|
||||
p_bytes = algo.p
|
||||
|
Loading…
Reference in New Issue
Block a user