mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
DRYer
This commit is contained in:
parent
37946153d0
commit
031049ea9d
@ -117,12 +117,13 @@ def simple_text(f):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
def items_with_property(root, q, prefixes):
|
def items_with_property(root, q, prefixes):
|
||||||
q = expand_prefix(q, prefixes)
|
q = expand_prefix(q, prefixes).lower()
|
||||||
for item in XPath("./opf:manifest/opf:item[@properties]")(root):
|
for item in XPath("./opf:manifest/opf:item[@properties]")(root):
|
||||||
for prop in (item.get('properties') or '').split():
|
for prop in (item.get('properties') or '').lower().split():
|
||||||
prop = expand_prefix(prop, prefixes)
|
prop = expand_prefix(prop, prefixes)
|
||||||
if prop == q:
|
if prop == q:
|
||||||
yield item
|
yield item
|
||||||
|
break
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ from calibre.ebooks.chardet import xml_to_unicode
|
|||||||
from calibre.ebooks.conversion.plugins.epub_input import (
|
from calibre.ebooks.conversion.plugins.epub_input import (
|
||||||
ADOBE_OBFUSCATION, IDPF_OBFUSCATION, decrypt_font_data)
|
ADOBE_OBFUSCATION, IDPF_OBFUSCATION, decrypt_font_data)
|
||||||
from calibre.ebooks.conversion.preprocess import HTMLPreProcessor, CSSPreProcessor as cssp
|
from calibre.ebooks.conversion.preprocess import HTMLPreProcessor, CSSPreProcessor as cssp
|
||||||
from calibre.ebooks.metadata.opf3 import read_prefixes, expand_prefix, ensure_prefix, CALIBRE_PREFIX
|
from calibre.ebooks.metadata.opf3 import read_prefixes, items_with_property, ensure_prefix, CALIBRE_PREFIX
|
||||||
from calibre.ebooks.metadata.utils import parse_opf_version
|
from calibre.ebooks.metadata.utils import parse_opf_version
|
||||||
from calibre.ebooks.mobi import MobiError
|
from calibre.ebooks.mobi import MobiError
|
||||||
from calibre.ebooks.mobi.reader.headers import MetadataHeader
|
from calibre.ebooks.mobi.reader.headers import MetadataHeader
|
||||||
@ -614,14 +614,10 @@ class Container(ContainerBase): # {{{
|
|||||||
def manifest_items_with_property(self, property_name):
|
def manifest_items_with_property(self, property_name):
|
||||||
' All manifest items that have the specified property '
|
' All manifest items that have the specified property '
|
||||||
prefixes = read_prefixes(self.opf)
|
prefixes = read_prefixes(self.opf)
|
||||||
q = expand_prefix(property_name, prefixes).lower()
|
for item in items_with_property(self.opf, property_name, prefixes):
|
||||||
for item in self.opf_xpath('//opf:manifest/opf:item[@href and @properties]'):
|
href = item.get('href')
|
||||||
props = (item.get('properties') or '').lower().split()
|
if href:
|
||||||
for p in props:
|
yield self.href_to_name(item.get('href'), self.opf_name)
|
||||||
pq = expand_prefix(p, prefixes).lower()
|
|
||||||
if pq == q:
|
|
||||||
yield self.href_to_name(item.get('href'), self.opf_name)
|
|
||||||
break
|
|
||||||
|
|
||||||
def manifest_items_of_type(self, predicate):
|
def manifest_items_of_type(self, predicate):
|
||||||
''' The names of all manifest items whose media-type matches predicate.
|
''' The names of all manifest items whose media-type matches predicate.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user