From 30af7f26dbb989b4dbeddfb546679c5ff122a4bf Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 17 Jun 2009 15:58:58 -0700 Subject: [PATCH] Fix #2614 (Multiple errors after "WARNING: content length not a multiple of block size") --- src/calibre/ebooks/lit/reader.py | 10 ++++++---- src/calibre/ebooks/metadata/lit.py | 3 ++- src/calibre/ebooks/oeb/base.py | 9 +++++++-- src/calibre/ebooks/oeb/reader.py | 3 ++- src/calibre/ebooks/oeb/writer.py | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/calibre/ebooks/lit/reader.py b/src/calibre/ebooks/lit/reader.py index cccc04063f..ec7d858107 100644 --- a/src/calibre/ebooks/lit/reader.py +++ b/src/calibre/ebooks/lit/reader.py @@ -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() diff --git a/src/calibre/ebooks/metadata/lit.py b/src/calibre/ebooks/metadata/lit.py index 0a37b6c768..1a267b6858 100644 --- a/src/calibre/ebooks/metadata/lit.py +++ b/src/calibre/ebooks/metadata/lit.py @@ -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()) diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index 9f43ff7d8b..3f890dedf4 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -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) diff --git a/src/calibre/ebooks/oeb/reader.py b/src/calibre/ebooks/oeb/reader.py index eccc1016bb..4ccc1eeed1 100644 --- a/src/calibre/ebooks/oeb/reader.py +++ b/src/calibre/ebooks/oeb/reader.py @@ -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 diff --git a/src/calibre/ebooks/oeb/writer.py b/src/calibre/ebooks/oeb/writer.py index f71eb88ea5..3dcc81552c 100644 --- a/src/calibre/ebooks/oeb/writer.py +++ b/src/calibre/ebooks/oeb/writer.py @@ -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: