From 31dfc7bf376183caac902c4aa4b24b743dfbd6fa Mon Sep 17 00:00:00 2001 From: YHQ <97353401@qq.com> Date: Sat, 28 Sep 2024 22:40:13 +0800 Subject: [PATCH] Add a global variable 'ignored_message', which is used to expose the ignored message when a CSSStyleDeclaration: Unexpected token error occurs, allowing the user to retrieve that message. --- cssutils/css/cssstyledeclaration.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cssutils/css/cssstyledeclaration.py b/cssutils/css/cssstyledeclaration.py index bdf336fa..fd7eef06 100644 --- a/cssutils/css/cssstyledeclaration.py +++ b/cssutils/css/cssstyledeclaration.py @@ -51,7 +51,7 @@ """ __all__ = ['CSSStyleDeclaration', 'Property'] - +ignored_message="" import cssutils from .cssproperties import CSS2Properties @@ -322,6 +322,8 @@ def unexpected(expected, seq, token, tokenizer=None): ignored = self._tokenvalue(token) + self._valuestr( self._tokensupto2(tokenizer, propertyvalueendonly=True) ) + global ignored_message # Expose ignored messages to the outside, allowing users to retrieve the ignored messages for further processing, such as continuing to parse the ignored content. + ignored_message=ignored self._log.error( 'CSSStyleDeclaration: Unexpected token, ignoring ' 'upto %r.' % ignored, token,