From 615303a143ed8dd787145439e81bea79a87b5871 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 1 Mar 2016 18:32:38 +0530 Subject: [PATCH] ... --- src/calibre/ebooks/oeb/transforms/flatcss.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/oeb/transforms/flatcss.py b/src/calibre/ebooks/oeb/transforms/flatcss.py index 0d0ec908b6..54f53762b0 100644 --- a/src/calibre/ebooks/oeb/transforms/flatcss.py +++ b/src/calibre/ebooks/oeb/transforms/flatcss.py @@ -523,10 +523,17 @@ class CSSFlattener(object): def flatten_head(self, item, href, global_href): html = item.data head = html.find(XHTML('head')) + def safe_lower(x): + try: + x = x.lower() + except Exception: + pass + return x + for node in html.xpath('//*[local-name()="style" or local-name()="link"]'): if node.tag == XHTML('link') \ - and node.get('rel', 'stylesheet') == 'stylesheet' \ - and node.get('type', CSS_MIME) in OEB_STYLES: + and safe_lower(node.get('rel', 'stylesheet')) == 'stylesheet' \ + and safe_lower(node.get('type', CSS_MIME)) in OEB_STYLES: node.getparent().remove(node) elif node.tag == XHTML('style') \ and node.get('type', CSS_MIME) in OEB_STYLES: