2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Automatically cast message and caption arguments to str

This commit is contained in:
Dan 2019-01-03 20:53:48 +01:00
parent 4f6990d735
commit d69a93d253
2 changed files with 6 additions and 6 deletions

View File

@ -38,12 +38,12 @@ class HTML:
def __init__(self, peers_by_id): def __init__(self, peers_by_id):
self.peers_by_id = peers_by_id self.peers_by_id = peers_by_id
def parse(self, text): def parse(self, message: str):
entities = [] entities = []
text = utils.add_surrogates(text) message = utils.add_surrogates(str(message))
offset = 0 offset = 0
for match in self.HTML_RE.finditer(text): for match in self.HTML_RE.finditer(message):
start = match.start() - offset start = match.start() - offset
style, url, body = match.group(1, 3, 4) style, url, body = match.group(1, 3, 4)
@ -73,12 +73,12 @@ class HTML:
continue continue
entities.append(entity) entities.append(entity)
text = text.replace(match.group(), body) message = message.replace(match.group(), body)
offset += len(style) * 2 + 5 + (len(url) + 8 if url else 0) offset += len(style) * 2 + 5 + (len(url) + 8 if url else 0)
# TODO: OrderedDict to be removed in Python3.6 # TODO: OrderedDict to be removed in Python3.6
return OrderedDict([ return OrderedDict([
("message", utils.remove_surrogates(text)), ("message", utils.remove_surrogates(message)),
("entities", entities) ("entities", entities)
]) ])

View File

@ -56,7 +56,7 @@ class Markdown:
self.peers_by_id = peers_by_id self.peers_by_id = peers_by_id
def parse(self, message: str): def parse(self, message: str):
message = utils.add_surrogates(message).strip() message = utils.add_surrogates(str(message)).strip()
entities = [] entities = []
offset = 0 offset = 0