Make bleach mandatory

This commit is contained in:
Ozzie Isaacs
2024-06-15 08:18:38 +02:00
parent 7aa122e6cd
commit f7d5480811
3 changed files with 7 additions and 35 deletions
+5 -18
View File
@@ -19,31 +19,18 @@
from . import logger
from lxml.etree import ParserError
log = logger.create()
try:
# at least bleach 6.0 is needed -> incomplatible change from list arguments to set arguments
from bleach import clean_text as clean_html
BLEACH = True
from bleach import clean as clean_html
except ImportError:
try:
BLEACH = False
from nh3 import clean as clean_html
except ImportError:
try:
BLEACH = False
from lxml.html.clean import clean_html
except ImportError:
clean_html = None
log = logger.create()
from nh3 import clean as clean_html
def clean_string(unsafe_text, book_id=0):
try:
if BLEACH:
safe_text = clean_html(unsafe_text, tags=set(), attributes=set())
else:
safe_text = clean_html(unsafe_text)
safe_text = clean_html(unsafe_text)
except ParserError as e:
log.error("Comments of book {} are corrupted: {}".format(book_id, e))
safe_text = ""