mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Fix #2614 (Multiple errors after "WARNING: content length not a multiple of block size")
This commit is contained in:
parent
78cd647c6e
commit
30af7f26db
@ -407,7 +407,8 @@ def preserve(function):
|
||||
class LitFile(object):
|
||||
PIECE_SIZE = 16
|
||||
|
||||
def __init__(self, filename_or_stream):
|
||||
def __init__(self, filename_or_stream, log):
|
||||
self._warn = log.warn
|
||||
if hasattr(filename_or_stream, 'read'):
|
||||
self.stream = filename_or_stream
|
||||
else:
|
||||
@ -428,7 +429,7 @@ class LitFile(object):
|
||||
self.read_drm()
|
||||
|
||||
def warn(self, msg):
|
||||
print "WARNING: %s" % (msg,)
|
||||
self._warn(msg)
|
||||
|
||||
def magic():
|
||||
@preserve
|
||||
@ -844,8 +845,9 @@ class LitFile(object):
|
||||
class LitContainer(object):
|
||||
"""Simple Container-interface, read-only accessor for LIT files."""
|
||||
|
||||
def __init__(self, filename_or_stream):
|
||||
self._litfile = LitFile(filename_or_stream)
|
||||
def __init__(self, filename_or_stream, log):
|
||||
self._litfile = LitFile(filename_or_stream, log)
|
||||
self.log = log
|
||||
|
||||
def namelist(self):
|
||||
return self._litfile.paths.keys()
|
||||
|
@ -11,7 +11,8 @@ from calibre.ebooks.metadata.opf2 import OPF
|
||||
|
||||
def get_metadata(stream):
|
||||
from calibre.ebooks.lit.reader import LitContainer
|
||||
litfile = LitContainer(stream)
|
||||
from calibre.utils.logging import Log
|
||||
litfile = LitContainer(stream, Log())
|
||||
src = litfile.get_metadata().encode('utf-8')
|
||||
litfile = litfile._litfile
|
||||
opf = OPF(cStringIO.StringIO(src), os.getcwd())
|
||||
|
@ -375,6 +375,10 @@ class NullContainer(object):
|
||||
|
||||
For use with book formats which do not support container-like access.
|
||||
"""
|
||||
|
||||
def __init__(self, log):
|
||||
self.log = log
|
||||
|
||||
def read(self, path):
|
||||
raise OEBError('Attempt to read from NullContainer')
|
||||
|
||||
@ -390,7 +394,8 @@ class NullContainer(object):
|
||||
class DirContainer(object):
|
||||
"""Filesystem directory container."""
|
||||
|
||||
def __init__(self, path):
|
||||
def __init__(self, path, log):
|
||||
self.log = log
|
||||
path = unicode(path)
|
||||
ext = os.path.splitext(path)[1].lower()
|
||||
if ext == '.opf':
|
||||
@ -1632,7 +1637,7 @@ class OEBBook(object):
|
||||
self.pretty_print = pretty_print
|
||||
self.logger = self.log = logger
|
||||
self.version = '2.0'
|
||||
self.container = NullContainer()
|
||||
self.container = NullContainer(self.log)
|
||||
self.metadata = Metadata(self)
|
||||
self.uid = None
|
||||
self.manifest = Manifest(self)
|
||||
|
@ -66,7 +66,8 @@ class OEBReader(object):
|
||||
"""
|
||||
self.oeb = oeb
|
||||
self.logger = self.log = oeb.logger
|
||||
oeb.container = self.Container(path)
|
||||
oeb.container = self.Container(path, self.logger)
|
||||
oeb.container.log = oeb.log
|
||||
opf = self._read_opf()
|
||||
self._all_from_opf(opf)
|
||||
return oeb
|
||||
|
@ -59,7 +59,7 @@ class OEBWriter(object):
|
||||
path = os.path.dirname(path)
|
||||
if not os.path.isdir(path):
|
||||
os.mkdir(path)
|
||||
output = DirContainer(path)
|
||||
output = DirContainer(path, oeb.log)
|
||||
for item in oeb.manifest.values():
|
||||
output.write(item.href, str(item))
|
||||
if version == 1:
|
||||
|
Loading…
x
Reference in New Issue
Block a user