def __init__(self, pathtoazw3, log, clone_data=None, tdir=None): if clone_data is not None: super(AZW3Container, self).__init__(None, None, log, clone_data=clone_data) for x in ('pathtoazw3', 'obfuscated_fonts'): setattr(self, x, clone_data[x]) return self.pathtoazw3 = pathtoazw3 if tdir is None: tdir = PersistentTemporaryDirectory('_azw3_container') tdir = os.path.abspath(os.path.realpath(tdir)) self.root = tdir with open(pathtoazw3, 'rb') as stream: raw = stream.read(3) if raw == b'TPZ': raise InvalidMobi( _('This is not a MOBI file. It is a Topaz file.')) try: header = MetadataHeader(stream, default_log) except MobiError: raise InvalidMobi(_('This is not a MOBI file.')) if header.encryption_type != 0: raise DRMError() kf8_type = header.kf8_type if kf8_type is None: raise InvalidMobi( _('This MOBI file does not contain a KF8 format ' 'book. KF8 is the new format from Amazon. calibre can ' 'only edit MOBI files that contain KF8 books. Older ' 'MOBI files without KF8 are not editable.')) if kf8_type == 'joint': raise InvalidMobi( _('This MOBI file contains both KF8 and ' 'older Mobi6 data. calibre can only edit MOBI files ' 'that contain only KF8 data.')) try: opf_path, obfuscated_fonts = fork_job( 'calibre.ebooks.oeb.polish.container', 'do_explode', args=(pathtoazw3, tdir), no_output=True)['result'] except WorkerError as e: log(e.orig_tb) raise InvalidMobi('Failed to explode MOBI') super(AZW3Container, self).__init__(tdir, opf_path, log) self.obfuscated_fonts = { x.replace(os.sep, '/') for x in obfuscated_fonts }
def __init__(self, pathtoazw3, log, clone_data=None, tdir=None): if clone_data is not None: super(AZW3Container, self).__init__(None, None, log, clone_data=clone_data) for x in ("pathtoazw3", "obfuscated_fonts"): setattr(self, x, clone_data[x]) return self.pathtoazw3 = pathtoazw3 if tdir is None: tdir = PersistentTemporaryDirectory("_azw3_container") tdir = os.path.abspath(os.path.realpath(tdir)) self.root = tdir with open(pathtoazw3, "rb") as stream: raw = stream.read(3) if raw == b"TPZ": raise InvalidMobi(_("This is not a MOBI file. It is a Topaz file.")) try: header = MetadataHeader(stream, default_log) except MobiError: raise InvalidMobi(_("This is not a MOBI file.")) if header.encryption_type != 0: raise DRMError() kf8_type = header.kf8_type if kf8_type is None: raise InvalidMobi( _( "This MOBI file does not contain a KF8 format " "book. KF8 is the new format from Amazon. calibre can " "only edit MOBI files that contain KF8 books. Older " "MOBI files without KF8 are not editable." ) ) if kf8_type == "joint": raise InvalidMobi( _( "This MOBI file contains both KF8 and " "older Mobi6 data. calibre can only edit MOBI files " "that contain only KF8 data." ) ) try: opf_path, obfuscated_fonts = fork_job( "calibre.ebooks.oeb.polish.container", "do_explode", args=(pathtoazw3, tdir), no_output=True )["result"] except WorkerError as e: log(e.orig_tb) raise InvalidMobi("Failed to explode MOBI") super(AZW3Container, self).__init__(tdir, opf_path, log) self.obfuscated_fonts = {x.replace(os.sep, "/") for x in obfuscated_fonts}
def __init__(self, pathtoazw3, log, clone_data=None, tdir=None): if clone_data is not None: super(AZW3Container, self).__init__(None, None, log, clone_data=clone_data) for x in ('pathtoazw3', 'obfuscated_fonts'): setattr(self, x, clone_data[x]) return self.pathtoazw3 = pathtoazw3 if tdir is None: tdir = PersistentTemporaryDirectory('_azw3_container') tdir = os.path.abspath(os.path.realpath(tdir)) self.root = tdir with open(pathtoazw3, 'rb') as stream: raw = stream.read(3) if raw == b'TPZ': raise InvalidMobi(_('This is not a MOBI file. It is a Topaz file.')) try: header = MetadataHeader(stream, default_log) except MobiError: raise InvalidMobi(_('This is not a MOBI file.')) if header.encryption_type != 0: raise DRMError() kf8_type = header.kf8_type if kf8_type is None: raise InvalidMobi(_('This MOBI file does not contain a KF8 format ' 'book. KF8 is the new format from Amazon. calibre can ' 'only edit MOBI files that contain KF8 books. Older ' 'MOBI files without KF8 are not editable.')) if kf8_type == 'joint': raise InvalidMobi(_('This MOBI file contains both KF8 and ' 'older Mobi6 data. calibre can only edit MOBI files ' 'that contain only KF8 data.')) try: opf_path, obfuscated_fonts = fork_job( 'calibre.ebooks.oeb.polish.container', 'do_explode', args=(pathtoazw3, tdir), no_output=True)['result'] except WorkerError as e: log(e.orig_tb) raise InvalidMobi('Failed to explode MOBI') super(AZW3Container, self).__init__(tdir, opf_path, log) self.obfuscated_fonts = {x.replace(os.sep, '/') for x in obfuscated_fonts}