From d69a93d253c203a43bd0c0da5bc21c08be3a4899 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 3 Jan 2019 20:53:48 +0100 Subject: [PATCH] Automatically cast message and caption arguments to str --- pyrogram/client/style/html.py | 10 +++++----- pyrogram/client/style/markdown.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pyrogram/client/style/html.py b/pyrogram/client/style/html.py index 0014c4d9..9a72a565 100644 --- a/pyrogram/client/style/html.py +++ b/pyrogram/client/style/html.py @@ -38,12 +38,12 @@ class HTML: def __init__(self, peers_by_id): self.peers_by_id = peers_by_id - def parse(self, text): + def parse(self, message: str): entities = [] - text = utils.add_surrogates(text) + message = utils.add_surrogates(str(message)) offset = 0 - for match in self.HTML_RE.finditer(text): + for match in self.HTML_RE.finditer(message): start = match.start() - offset style, url, body = match.group(1, 3, 4) @@ -73,12 +73,12 @@ class HTML: continue 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) # TODO: OrderedDict to be removed in Python3.6 return OrderedDict([ - ("message", utils.remove_surrogates(text)), + ("message", utils.remove_surrogates(message)), ("entities", entities) ]) diff --git a/pyrogram/client/style/markdown.py b/pyrogram/client/style/markdown.py index 7bd96ed6..05a11a25 100644 --- a/pyrogram/client/style/markdown.py +++ b/pyrogram/client/style/markdown.py @@ -56,7 +56,7 @@ class Markdown: self.peers_by_id = peers_by_id def parse(self, message: str): - message = utils.add_surrogates(message).strip() + message = utils.add_surrogates(str(message)).strip() entities = [] offset = 0