mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add exists() method to the LitReader (qua OEB-archive).
This commit is contained in:
parent
46c52b3bb5
commit
1f6eda3ff1
@ -12,6 +12,7 @@ import functools
|
|||||||
import re
|
import re
|
||||||
from urlparse import urldefrag
|
from urlparse import urldefrag
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
from urllib import unquote as urlunquote
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from calibre.ebooks.lit import LitError
|
from calibre.ebooks.lit import LitError
|
||||||
from calibre.ebooks.lit.maps import OPF_MAP, HTML_MAP
|
from calibre.ebooks.lit.maps import OPF_MAP, HTML_MAP
|
||||||
@ -812,8 +813,11 @@ class LitReader(object):
|
|||||||
def namelist(self):
|
def namelist(self):
|
||||||
return self._litfile.paths.keys()
|
return self._litfile.paths.keys()
|
||||||
|
|
||||||
|
def exists(self, name):
|
||||||
|
return urlunquote(name) in self._litfile.paths
|
||||||
|
|
||||||
def read_xml(self, name):
|
def read_xml(self, name):
|
||||||
entry = self._litfile.paths[name] if name else None
|
entry = self._litfile.paths[urlunquote(name)] if name else None
|
||||||
if entry is None:
|
if entry is None:
|
||||||
content = self._read_meta()
|
content = self._read_meta()
|
||||||
elif 'spine' in entry.state:
|
elif 'spine' in entry.state:
|
||||||
@ -826,7 +830,7 @@ class LitReader(object):
|
|||||||
return content
|
return content
|
||||||
|
|
||||||
def read(self, name, pretty_print=False):
|
def read(self, name, pretty_print=False):
|
||||||
entry = self._litfile.paths[name] if name else None
|
entry = self._litfile.paths[urlunquote(name)] if name else None
|
||||||
if entry is None:
|
if entry is None:
|
||||||
meta = self._read_meta()
|
meta = self._read_meta()
|
||||||
content = OPF_DECL + etree.tostring(
|
content = OPF_DECL + etree.tostring(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user