From 7c704bbb6ac11553b556f6dc01f20d4b0b4e2d37 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 11 Jul 2019 04:14:14 +0200 Subject: [PATCH] Make the text parser log warnings instead of raising exceptions --- pyrogram/client/parser/html.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/parser/html.py b/pyrogram/client/parser/html.py index 04f4ad30..9aff757f 100644 --- a/pyrogram/client/parser/html.py +++ b/pyrogram/client/parser/html.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . import html +import logging import re from collections import OrderedDict from html.parser import HTMLParser @@ -27,6 +28,8 @@ from pyrogram.api import types from pyrogram.errors import PeerIdInvalid from . import utils +log = logging.getLogger(__name__) + class Parser(HTMLParser): MENTION_RE = re.compile(r"tg://user\?id=(\d+)") @@ -94,7 +97,7 @@ class Parser(HTMLParser): line, offset = self.getpos() offset += 1 - raise ValueError("Unmatched closing tag at line {}:{}".format(tag, line, offset)) + log.warning("Unmatched closing tag at line {}:{}".format(tag, line, offset)) else: if not self.tag_entities[tag]: self.tag_entities.pop(tag) @@ -120,7 +123,7 @@ class HTML: for tag, entities in parser.tag_entities.items(): unclosed_tags.append("<{}> (x{})".format(tag, len(entities))) - raise ValueError("Unclosed tags: {}".format(", ".join(unclosed_tags))) + log.warning("Unclosed tags: {}".format(", ".join(unclosed_tags))) entities = []