A spot of minor refactoring

This commit is contained in:
Kovid Goyal 2016-07-06 10:47:34 +05:30
parent 4f317375f4
commit 614e304029
2 changed files with 13 additions and 7 deletions

View File

@ -1152,6 +1152,15 @@ class OPF(object): # {{{
if os.access(os.path.join(self.base_dir, prefix+suffix), os.R_OK):
return cpath
@property
def epub3_raster_cover(self):
for item in self.itermanifest():
props = set((item.get('properties') or '').lower().split())
if 'cover-image' in props:
mt = item.get('media-type', '')
if mt and 'xml' not in mt and 'html' not in mt:
return item.get('href', None)
@property
def raster_cover(self):
covers = self.raster_cover_path(self.metadata)
@ -1168,12 +1177,7 @@ class OPF(object): # {{{
if mt and 'xml' not in mt and 'html' not in mt:
return item.get('href', None)
elif self.package_version >= 3.0:
for item in self.itermanifest():
props = set((item.get('properties') or '').lower().split())
if 'cover-image' in props:
mt = item.get('media-type', '')
if mt and 'xml' not in mt and 'html' not in mt:
return item.get('href', None)
return self.epub3_raster_cover
@property
def guide_raster_cover(self):

View File

@ -116,7 +116,9 @@ def simple_text(f):
return normalize_whitespace(f(*args, **kw))
return wrapper
def items_with_property(root, q, prefixes):
def items_with_property(root, q, prefixes=None):
if prefixes is None:
prefixes = read_prefixes(root)
q = expand_prefix(q, known_prefixes).lower()
for item in XPath("./opf:manifest/opf:item[@properties]")(root):
for prop in (item.get('properties') or '').lower().split():