From 7a606b71cf99ccefbcc62b7efd9fe17316cea290 Mon Sep 17 00:00:00 2001 From: Lionel Dricot Date: Tue, 12 Sep 2023 18:06:42 +0200 Subject: [PATCH] some ugly code to filter XMLparsedAsHTMLWarning from BS4 --- ansicat.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ansicat.py b/ansicat.py index 0bb924d..7a5e62f 100755 --- a/ansicat.py +++ b/ansicat.py @@ -23,6 +23,21 @@ except ModuleNotFoundError: try: from bs4 import BeautifulSoup from bs4 import Comment + #if bs4 version >= 4.9.1, we need to silent some xml warnings + import bs4 + version = bs4.__version__.split(".") + recent = False + if int(version[0]) > 4: + recent = True + elif int(version[0]) == 4: + if int(version[1]) > 9: + recent = True + elif int(version[1]) == 9: + recent = version[2] >= 1 + if recent: + from bs4 import XMLParsedAsHTMLWarning + import warnings + warnings.filterwarnings("ignore", category=XMLParsedAsHTMLWarning) _HAS_SOUP = True except ModuleNotFoundError: _HAS_SOUP = False