Nicer error message when user tries to convert/view a Topaz book with a .prc extension

This commit is contained in:
Kovid Goyal 2010-04-30 08:48:20 -06:00
parent 90446f0632
commit 78339374d8

View File

@ -254,6 +254,8 @@ class MobiReader(object):
stream = open(filename_or_stream, 'rb') stream = open(filename_or_stream, 'rb')
raw = stream.read() raw = stream.read()
if raw.startswith('TPZ'):
raise ValueError(_('This is an Amazon Topaz book. It cannot be processed.'))
self.header = raw[0:72] self.header = raw[0:72]
self.name = self.header[:32].replace('\x00', '') self.name = self.header[:32].replace('\x00', '')
@ -261,7 +263,7 @@ class MobiReader(object):
self.ident = self.header[0x3C:0x3C + 8].upper() self.ident = self.header[0x3C:0x3C + 8].upper()
if self.ident not in ['BOOKMOBI', 'TEXTREAD']: if self.ident not in ['BOOKMOBI', 'TEXTREAD']:
raise MobiError('Unknown book type: %s' % self.ident) raise MobiError('Unknown book type: %s' % repr(self.ident))
self.sections = [] self.sections = []
self.section_headers = [] self.section_headers = []