mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Make the text parser log warnings instead of raising exceptions
This commit is contained in:
parent
2f07e7abc4
commit
7c704bbb6a
@ -17,6 +17,7 @@
|
|||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import html
|
import html
|
||||||
|
import logging
|
||||||
import re
|
import re
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
@ -27,6 +28,8 @@ from pyrogram.api import types
|
|||||||
from pyrogram.errors import PeerIdInvalid
|
from pyrogram.errors import PeerIdInvalid
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Parser(HTMLParser):
|
class Parser(HTMLParser):
|
||||||
MENTION_RE = re.compile(r"tg://user\?id=(\d+)")
|
MENTION_RE = re.compile(r"tg://user\?id=(\d+)")
|
||||||
@ -94,7 +97,7 @@ class Parser(HTMLParser):
|
|||||||
line, offset = self.getpos()
|
line, offset = self.getpos()
|
||||||
offset += 1
|
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:
|
else:
|
||||||
if not self.tag_entities[tag]:
|
if not self.tag_entities[tag]:
|
||||||
self.tag_entities.pop(tag)
|
self.tag_entities.pop(tag)
|
||||||
@ -120,7 +123,7 @@ class HTML:
|
|||||||
for tag, entities in parser.tag_entities.items():
|
for tag, entities in parser.tag_entities.items():
|
||||||
unclosed_tags.append("<{}> (x{})".format(tag, len(entities)))
|
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 = []
|
entities = []
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user