Cache Stylizer stylesheets based on Manifest.Item, not book-internal path

This commit is contained in:
Marshall T. Vandegrift 2009-02-08 09:04:00 -05:00
parent 65887df713
commit c2527cebe3

View File

@ -17,6 +17,7 @@ import types
import re
import copy
from itertools import izip
from weakref import WeakKeyDictionary
from xml.dom import SyntaxErr as CSSSyntaxError
import cssutils
from cssutils.css import CSSStyleRule, CSSPageRule, CSSStyleDeclaration, \
@ -107,7 +108,7 @@ class CSSSelector(etree.XPath):
class Stylizer(object):
STYLESHEETS = {}
STYLESHEETS = WeakKeyDictionary()
def __init__(self, tree, path, oeb, profile=PROFILES['PRS505']):
self.oeb = oeb
@ -132,18 +133,19 @@ class Stylizer(object):
and elem.get('type', CSS_MIME) in OEB_STYLES:
href = urlnormalize(elem.attrib['href'])
path = item.abshref(href)
if path not in oeb.manifest.hrefs:
sitem = oeb.manifest.hrefs.get(path, None)
if sitem is None:
self.logger.warn(
'Stylesheet %r referenced by file %r not in manifest' %
(path, item.href))
continue
if path in self.STYLESHEETS:
stylesheet = self.STYLESHEETS[path]
if sitem in self.STYLESHEETS:
stylesheet = self.STYLESHEETS[sitem]
else:
data = self._fetch_css_file(path)[1]
stylesheet = parser.parseString(data, href=path)
stylesheet.namespaces['h'] = XHTML_NS
self.STYLESHEETS[path] = stylesheet
self.STYLESHEETS[sitem] = stylesheet
stylesheets.append(stylesheet)
rules = []
index = 0