mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-28 04:19:59 +00:00
Handle error on uploading a book with lxml too new and no bleach, nh3 installation
This commit is contained in:
parent
e591211b57
commit
3a603cec22
@ -493,7 +493,8 @@ def autodetect_calibre_binaries():
|
|||||||
for element in calibre_path:
|
for element in calibre_path:
|
||||||
supported_binary_paths = [os.path.join(element, binary) for binary in constants.SUPPORTED_CALIBRE_BINARIES.values()]
|
supported_binary_paths = [os.path.join(element, binary) for binary in constants.SUPPORTED_CALIBRE_BINARIES.values()]
|
||||||
if all(os.path.isfile(binary_path) and os.access(binary_path, os.X_OK) for binary_path in supported_binary_paths):
|
if all(os.path.isfile(binary_path) and os.access(binary_path, os.X_OK) for binary_path in supported_binary_paths):
|
||||||
values = [process_wait([binary_path, "--version"], pattern='\(calibre (.*)\)') for binary_path in supported_binary_paths]
|
values = [process_wait([binary_path, "--version"],
|
||||||
|
pattern=r'\(calibre (.*)\)') for binary_path in supported_binary_paths]
|
||||||
if all(values):
|
if all(values):
|
||||||
version = values[0].group(1)
|
version = values[0].group(1)
|
||||||
log.debug("calibre version %s", version)
|
log.debug("calibre version %s", version)
|
||||||
|
@ -35,12 +35,12 @@ try:
|
|||||||
BLEACH = True
|
BLEACH = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from nh3 import clean as clean_html
|
|
||||||
BLEACH = False
|
BLEACH = False
|
||||||
|
from nh3 import clean as clean_html
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from lxml.html.clean import clean_html
|
|
||||||
BLEACH = False
|
BLEACH = False
|
||||||
|
from lxml.html.clean import clean_html
|
||||||
except ImportError:
|
except ImportError:
|
||||||
clean_html = None
|
clean_html = None
|
||||||
|
|
||||||
@ -1012,6 +1012,9 @@ def edit_book_comments(comments, book):
|
|||||||
except ParserError as e:
|
except ParserError as e:
|
||||||
log.error("Comments of book {} are corrupted: {}".format(book.id, e))
|
log.error("Comments of book {} are corrupted: {}".format(book.id, e))
|
||||||
comments = ""
|
comments = ""
|
||||||
|
except TypeError as e:
|
||||||
|
log.error("Comments can't be parsed, maybe 'lxml' is too new, try installing 'bleach': {}".format(e))
|
||||||
|
comments = ""
|
||||||
if len(book.comments):
|
if len(book.comments):
|
||||||
if book.comments[0].text != comments:
|
if book.comments[0].text != comments:
|
||||||
book.comments[0].text = comments
|
book.comments[0].text = comments
|
||||||
@ -1069,7 +1072,18 @@ def edit_cc_data_value(book_id, book, c, to_save, cc_db_value, cc_string):
|
|||||||
elif c.datatype == 'comments':
|
elif c.datatype == 'comments':
|
||||||
to_save[cc_string] = Markup(to_save[cc_string]).unescape()
|
to_save[cc_string] = Markup(to_save[cc_string]).unescape()
|
||||||
if to_save[cc_string]:
|
if to_save[cc_string]:
|
||||||
to_save[cc_string] = clean_html(to_save[cc_string])
|
try:
|
||||||
|
if BLEACH:
|
||||||
|
to_save[cc_string] = clean_html(to_save[cc_string], tags=set(), attributes=set())
|
||||||
|
else:
|
||||||
|
to_save[cc_string] = clean_html(to_save[cc_string])
|
||||||
|
except ParserError as e:
|
||||||
|
log.error("Customs Comments of book {} are corrupted: {}".format(book_id, e))
|
||||||
|
to_save[cc_string] = ""
|
||||||
|
except TypeError as e:
|
||||||
|
to_save[cc_string] = ""
|
||||||
|
log.error("Customs Comments can't be parsed, maybe 'lxml' is too new, "
|
||||||
|
"try installing 'bleach': {}".format(e))
|
||||||
elif c.datatype == 'datetime':
|
elif c.datatype == 'datetime':
|
||||||
try:
|
try:
|
||||||
to_save[cc_string] = datetime.strptime(to_save[cc_string], "%Y-%m-%d")
|
to_save[cc_string] = datetime.strptime(to_save[cc_string], "%Y-%m-%d")
|
||||||
|
Loading…
Reference in New Issue
Block a user