Fix #2614 (Multiple errors after "WARNING: content length not a multiple of block size")

This commit is contained in:
Kovid Goyal 2009-06-17 15:58:58 -07:00
parent 78cd647c6e
commit 30af7f26db
5 changed files with 18 additions and 9 deletions

View File

@ -407,7 +407,8 @@ def preserve(function):
class LitFile(object): class LitFile(object):
PIECE_SIZE = 16 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'): if hasattr(filename_or_stream, 'read'):
self.stream = filename_or_stream self.stream = filename_or_stream
else: else:
@ -428,7 +429,7 @@ class LitFile(object):
self.read_drm() self.read_drm()
def warn(self, msg): def warn(self, msg):
print "WARNING: %s" % (msg,) self._warn(msg)
def magic(): def magic():
@preserve @preserve
@ -844,8 +845,9 @@ class LitFile(object):
class LitContainer(object): class LitContainer(object):
"""Simple Container-interface, read-only accessor for LIT files.""" """Simple Container-interface, read-only accessor for LIT files."""
def __init__(self, filename_or_stream): def __init__(self, filename_or_stream, log):
self._litfile = LitFile(filename_or_stream) self._litfile = LitFile(filename_or_stream, log)
self.log = log
def namelist(self): def namelist(self):
return self._litfile.paths.keys() return self._litfile.paths.keys()

View File

@ -11,7 +11,8 @@ from calibre.ebooks.metadata.opf2 import OPF
def get_metadata(stream): def get_metadata(stream):
from calibre.ebooks.lit.reader import LitContainer 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') src = litfile.get_metadata().encode('utf-8')
litfile = litfile._litfile litfile = litfile._litfile
opf = OPF(cStringIO.StringIO(src), os.getcwd()) opf = OPF(cStringIO.StringIO(src), os.getcwd())

View File

@ -375,6 +375,10 @@ class NullContainer(object):
For use with book formats which do not support container-like access. For use with book formats which do not support container-like access.
""" """
def __init__(self, log):
self.log = log
def read(self, path): def read(self, path):
raise OEBError('Attempt to read from NullContainer') raise OEBError('Attempt to read from NullContainer')
@ -390,7 +394,8 @@ class NullContainer(object):
class DirContainer(object): class DirContainer(object):
"""Filesystem directory container.""" """Filesystem directory container."""
def __init__(self, path): def __init__(self, path, log):
self.log = log
path = unicode(path) path = unicode(path)
ext = os.path.splitext(path)[1].lower() ext = os.path.splitext(path)[1].lower()
if ext == '.opf': if ext == '.opf':
@ -1632,7 +1637,7 @@ class OEBBook(object):
self.pretty_print = pretty_print self.pretty_print = pretty_print
self.logger = self.log = logger self.logger = self.log = logger
self.version = '2.0' self.version = '2.0'
self.container = NullContainer() self.container = NullContainer(self.log)
self.metadata = Metadata(self) self.metadata = Metadata(self)
self.uid = None self.uid = None
self.manifest = Manifest(self) self.manifest = Manifest(self)

View File

@ -66,7 +66,8 @@ class OEBReader(object):
""" """
self.oeb = oeb self.oeb = oeb
self.logger = self.log = oeb.logger 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() opf = self._read_opf()
self._all_from_opf(opf) self._all_from_opf(opf)
return oeb return oeb

View File

@ -59,7 +59,7 @@ class OEBWriter(object):
path = os.path.dirname(path) path = os.path.dirname(path)
if not os.path.isdir(path): if not os.path.isdir(path):
os.mkdir(path) os.mkdir(path)
output = DirContainer(path) output = DirContainer(path, oeb.log)
for item in oeb.manifest.values(): for item in oeb.manifest.values():
output.write(item.href, str(item)) output.write(item.href, str(item))
if version == 1: if version == 1: