From 539a4d0355afa9aa8e37aa45862345e6728f65f6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 2 Jul 2010 17:55:43 -0600 Subject: [PATCH] Only parse the default css stylesheet on demand --- src/calibre/ebooks/oeb/stylizer.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index 3c84252ff4..4789899fbf 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -25,10 +25,17 @@ from calibre.ebooks.oeb.base import XHTML, XHTML_NS, CSS_MIME, OEB_STYLES from calibre.ebooks.oeb.base import XPNSMAP, xpath, urlnormalize from calibre.ebooks.oeb.profile import PROFILES -html_css = open(P('templates/html.css'), 'rb').read() +_html_css_stylesheet = None + +def html_css_stylesheet(): + global _html_css_stylesheet + if _html_css_stylesheet is None: + html_css = open(P('templates/html.css'), 'rb').read() + _html_css_stylesheet = cssutils.parseString(html_css) + _html_css_stylesheet.namespaces['h'] = XHTML_NS + return _html_css_stylesheet + XHTML_CSS_NAMESPACE = '@namespace "%s";\n' % XHTML_NS -HTML_CSS_STYLESHEET = cssutils.parseString(html_css) -HTML_CSS_STYLESHEET.namespaces['h'] = XHTML_NS INHERITED = set(['azimuth', 'border-collapse', 'border-spacing', 'caption-side', 'color', 'cursor', 'direction', 'elevation', @@ -120,7 +127,7 @@ class Stylizer(object): item = oeb.manifest.hrefs[path] basename = os.path.basename(path) cssname = os.path.splitext(basename)[0] + '.css' - stylesheets = [HTML_CSS_STYLESHEET] + stylesheets = [html_css_stylesheet()] head = xpath(tree, '/h:html/h:head') if head: head = head[0]