From 5ee7a620ea1afcdc74b586089829c440b02869f7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 14 Jun 2014 09:08:26 +0530 Subject: [PATCH] Remove unused css: Prevent failure when book has invalid items marked as stylesheets --- src/calibre/ebooks/oeb/polish/css.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/oeb/polish/css.py b/src/calibre/ebooks/oeb/polish/css.py index 8fd885861f..2ad7154d80 100644 --- a/src/calibre/ebooks/oeb/polish/css.py +++ b/src/calibre/ebooks/oeb/polish/css.py @@ -120,7 +120,13 @@ def preserve_htmlns_prefix(sheet, prefix): def remove_unused_css(container, report): from cssutils.css import CSSRule - sheets = {name:container.parsed(name) for name, mt in container.mime_map.iteritems() if mt in OEB_STYLES} + def safe_parse(name): + try: + return container.parsed(name) + except TypeError: + pass + sheets = {name:safe_parse(name) for name, mt in container.mime_map.iteritems() if mt in OEB_STYLES} + sheets = {k:v for k, v in sheets.iteritems() if v is not None} sheet_namespace = {} for sheet in sheets.itervalues(): sheet_namespace[sheet] = process_namespaces(sheet)