1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-29 02:04:05 +02:00

Removed superfluous lopen builtin

This commit is contained in:
2020-04-20 21:12:22 +02:00
parent 3ca3f08054
commit 9e076e0af4
38 changed files with 107 additions and 195 deletions
@@ -175,7 +175,7 @@ class CHMInput(InputFormatPlugin):
return htmlpath, toc
def _read_file(self, name):
with lopen(name, 'rb') as f:
with open(name, 'rb') as f:
data = f.read()
return data
@@ -22,7 +22,7 @@ def decrypt_font_data(key, data, algorithm):
def decrypt_font(key, path, algorithm):
with lopen(path, 'r+b') as f:
with open(path, 'r+b') as f:
data = decrypt_font_data(key, f.read(), algorithm)
f.seek(0), f.truncate(), f.write(data)
@@ -221,7 +221,7 @@ class EPUBInput(InputFormatPlugin):
if os.path.exists(guide_cover):
renderer = render_html_svg_workaround(guide_cover, log)
if renderer is not None:
with lopen('calibre_raster_cover.jpg', 'wb') as f:
with open('calibre_raster_cover.jpg', 'wb') as f:
f.write(renderer)
# Set the titlepage guide entry
@@ -236,7 +236,7 @@ class EPUBInput(InputFormatPlugin):
if k.endswith(attr):
return v
try:
with lopen('META-INF/container.xml', 'rb') as f:
with open('META-INF/container.xml', 'rb') as f:
root = safe_xml_fromstring(f.read())
for r in root.xpath('//*[local-name()="rootfile"]'):
if attr(r, 'media-type') != "application/oebps-package+xml":
@@ -343,7 +343,7 @@ class EPUBInput(InputFormatPlugin):
if len(list(opf.iterspine())) == 0:
raise ValueError('No valid entries in the spine of this EPUB')
with lopen('content.opf', 'wb') as nopf:
with open('content.opf', 'wb') as nopf:
nopf.write(opf.render())
return os.path.abspath('content.opf')
@@ -356,7 +356,7 @@ class EPUBInput(InputFormatPlugin):
from ebook_converter.ebooks.oeb.polish.toc import first_child
from ebook_converter.utils.xml_parse import safe_xml_fromstring
from tempfile import NamedTemporaryFile
with lopen(nav_path, 'rb') as f:
with open(nav_path, 'rb') as f:
raw = f.read()
raw = xml_to_unicode(raw, strip_encoding_pats=True, assume_utf8=True)[0]
root = parse(raw, log=log)
@@ -420,7 +420,7 @@ class EPUBInput(InputFormatPlugin):
changed = True
elem.set('data-calibre-removed-titlepage', '1')
if changed:
with lopen(nav_path, 'wb') as f:
with open(nav_path, 'wb') as f:
f.write(serialize(root, 'application/xhtml+xml'))
def postprocess_book(self, oeb, opts, log):
@@ -328,7 +328,7 @@ class EPUBOutput(OutputFormatPlugin):
uris.pop(uri)
continue
self.log.debug('Encrypting font:', uri)
with lopen(path, 'r+b') as f:
with open(path, 'r+b') as f:
data = f.read(1024)
if len(data) >= 1024:
data = bytearray(data)
@@ -189,7 +189,7 @@ class FB2Output(OutputFormatPlugin):
close = True
if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path) != '':
os.makedirs(os.path.dirname(output_path))
out_stream = lopen(output_path, 'wb')
out_stream = open(output_path, 'wb')
else:
out_stream = output_path
@@ -113,7 +113,7 @@ class HTMLZOutput(OutputFormatPlugin):
if cover_data:
from ebook_converter.utils.img import save_cover_data_to
cover_path = os.path.join(tdir, u'cover.jpg')
with lopen(cover_path, 'w') as cf:
with open(cover_path, 'w') as cf:
cf.write('')
save_cover_data_to(cover_data, cover_path)
except:
@@ -51,14 +51,14 @@ class MOBIInput(InputFormatPlugin):
if raw:
if isinstance(raw, str):
raw = raw.encode('utf-8')
with lopen('debug-raw.html', 'wb') as f:
with open('debug-raw.html', 'wb') as f:
f.write(raw)
from ebook_converter.ebooks.oeb.base import close_self_closing_tags
for f, root in parse_cache.items():
raw = html.tostring(root, encoding='utf-8', method='xml',
include_meta_content_type=False)
raw = close_self_closing_tags(raw)
with lopen(f, 'wb') as q:
with open(f, 'wb') as q:
q.write(raw)
accelerators['pagebreaks'] = '//h:div[@class="mbp_pagebreak"]'
return mr.created_opf_path
@@ -53,7 +53,7 @@ class OEBOutput(OutputFormatPlugin):
# Needed as I can't get lxml to output opf:role and
# not output <opf:metadata> as well
raw = re.sub(br'(<[/]{0,1})opf:', br'\1', raw)
with lopen(href, 'wb') as f:
with open(href, 'wb') as f:
f.write(raw)
for item in oeb_book.manifest:
@@ -65,7 +65,7 @@ class OEBOutput(OutputFormatPlugin):
dir = os.path.dirname(path)
if not os.path.exists(dir):
os.makedirs(dir)
with lopen(path, 'wb') as f:
with open(path, 'wb') as f:
f.write(item.bytes_representation)
item.unload_data_from_memory(memory=path)
@@ -39,7 +39,7 @@ class PDBOutput(OutputFormatPlugin):
close = True
if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path):
os.makedirs(os.path.dirname(output_path))
out_stream = lopen(output_path, 'wb')
out_stream = open(output_path, 'wb')
else:
out_stream = output_path
@@ -34,7 +34,7 @@ class PDFInput(InputFormatPlugin):
from ebook_converter.ebooks.pdf.reflow import PDFDocument
pdftohtml(os.getcwd(), stream.name, self.opts.no_images, as_xml=True)
with lopen('index.xml', 'rb') as f:
with open('index.xml', 'rb') as f:
xml = clean_ascii_chars(f.read())
PDFDocument(xml, self.opts, self.log)
return os.path.join(os.getcwd(), 'metadata.opf')
@@ -66,12 +66,12 @@ class PDFInput(InputFormatPlugin):
opf.create_spine(['index.html'])
log.debug('Rendering manifest...')
with lopen('metadata.opf', 'wb') as opffile:
with open('metadata.opf', 'wb') as opffile:
opf.render(opffile)
if os.path.exists('toc.ncx'):
ncxid = opf.manifest.id_for_path('toc.ncx')
if ncxid:
with lopen('metadata.opf', 'r+b') as f:
with open('metadata.opf', 'r+b') as f:
raw = f.read().replace(b'<spine', b'<spine toc="%s"' % as_bytes(ncxid))
f.seek(0)
f.write(raw)
@@ -27,14 +27,14 @@ class PMLInput(InputFormatPlugin):
hclose = False
if not hasattr(pml_path, 'read'):
pml_stream = lopen(pml_path, 'rb')
pml_stream = open(pml_path, 'rb')
pclose = True
else:
pml_stream = pml_path
pml_stream.seek(0)
if not hasattr(html_path, 'write'):
html_stream = lopen(html_path, 'wb')
html_stream = open(html_path, 'wb')
hclose = True
else:
html_stream = html_path
@@ -135,8 +135,8 @@ class PMLInput(InputFormatPlugin):
opf.create_manifest(manifest_items)
opf.create_spine(pages)
opf.set_toc(toc)
with lopen('metadata.opf', 'wb') as opffile:
with lopen('toc.ncx', 'wb') as tocfile:
with open('metadata.opf', 'wb') as opffile:
with open('toc.ncx', 'wb') as tocfile:
opf.render(opffile, tocfile, 'toc.ncx')
return os.path.join(os.getcwd(), 'metadata.opf')
@@ -40,7 +40,7 @@ class PMLOutput(OutputFormatPlugin):
with TemporaryDirectory('_pmlz_output') as tdir:
pmlmlizer = PMLMLizer(log)
pml = str(pmlmlizer.extract_content(oeb_book, opts))
with lopen(os.path.join(tdir, 'index.pml'), 'wb') as out:
with open(os.path.join(tdir, 'index.pml'), 'wb') as out:
out.write(pml.encode(opts.pml_output_encoding, 'replace'))
img_path = os.path.join(tdir, 'index_img')
@@ -70,5 +70,5 @@ class PMLOutput(OutputFormatPlugin):
path = os.path.join(out_dir, image_hrefs[item.href])
with lopen(path, 'wb') as out:
with open(path, 'wb') as out:
out.write(data)
@@ -28,7 +28,7 @@ class RBOutput(OutputFormatPlugin):
close = True
if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path):
os.makedirs(os.path.dirname(output_path))
out_stream = lopen(output_path, 'wb')
out_stream = open(output_path, 'wb')
else:
out_stream = output_path
@@ -61,7 +61,7 @@ class RecipeInput(InputFormatPlugin):
zf = ZipFile(recipe_or_file, 'r')
zf.extractall()
zf.close()
with lopen('download.recipe', 'rb') as f:
with open('download.recipe', 'rb') as f:
self.recipe_source = f.read()
recipe = compile_recipe(self.recipe_source)
recipe.needs_subscription = False
@@ -84,7 +84,7 @@ class RecipeInput(InputFormatPlugin):
self.recipe_source = self.recipe_source.encode('utf-8')
recipe = compile_recipe(self.recipe_source)
elif os.access(recipe_or_file, os.R_OK):
with lopen(recipe_or_file, 'rb') as f:
with open(recipe_or_file, 'rb') as f:
self.recipe_source = f.read()
recipe = compile_recipe(self.recipe_source)
log('Using custom recipe')
@@ -173,7 +173,7 @@ class RTFInput(InputFormatPlugin):
' Use Microsoft Word or OpenOffice to save this RTF file'
' as HTML and convert that in calibre.')
name = name.replace('.wmf', '.jpg')
with lopen(name, 'wb') as f:
with open(name, 'wb') as f:
f.write(self.default_img)
return name
@@ -26,7 +26,7 @@ class RTFOutput(OutputFormatPlugin):
close = True
if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path) != '':
os.makedirs(os.path.dirname(output_path))
out_stream = lopen(output_path, 'wb')
out_stream = open(output_path, 'wb')
else:
out_stream = output_path
@@ -242,7 +242,7 @@ class SNBOutput(OutputFormatPlugin):
# img = img.rotate(90)
# x,y = y,x
img = resize_image(img, x // scale, y // scale)
with lopen(imagePath, 'wb') as f:
with open(imagePath, 'wb') as f:
f.write(image_to_data(img, fmt=imagePath.rpartition('.')[-1]))
@@ -31,7 +31,7 @@ class TCROutput(OutputFormatPlugin):
close = True
if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path):
os.makedirs(os.path.dirname(output_path))
out_stream = lopen(output_path, 'wb')
out_stream = open(output_path, 'wb')
else:
out_stream = output_path
+4 -4
View File
@@ -945,7 +945,7 @@ OptionRecommendation(name='search_replace',
if self.opts.read_metadata_from_opf is not None:
self.opts.read_metadata_from_opf = os.path.abspath(
self.opts.read_metadata_from_opf)
with lopen(self.opts.read_metadata_from_opf, 'rb') as stream:
with open(self.opts.read_metadata_from_opf, 'rb') as stream:
opf = OPF(stream, os.path.dirname(self.opts.read_metadata_from_opf))
mi = opf.to_book_metadata()
self.opts_to_mi(mi)
@@ -955,7 +955,7 @@ OptionRecommendation(name='search_replace',
ext = mi.cover.rpartition('.')[-1].lower().strip()
if ext not in ('png', 'jpg', 'jpeg', 'gif'):
ext = 'jpg'
with lopen(mi.cover, 'rb') as stream:
with open(mi.cover, 'rb') as stream:
mi.cover_data = (ext, stream.read())
mi.cover = None
self.user_metadata = mi
@@ -1061,7 +1061,7 @@ OptionRecommendation(name='search_replace',
self.opts.debug_pipeline = os.path.abspath(self.opts.debug_pipeline)
if not os.path.exists(self.opts.debug_pipeline):
os.makedirs(self.opts.debug_pipeline)
with lopen(os.path.join(self.opts.debug_pipeline, 'README.txt'), 'wb') as f:
with open(os.path.join(self.opts.debug_pipeline, 'README.txt'), 'wb') as f:
f.write(DEBUG_README)
for x in ('input', 'parsed', 'structure', 'processed'):
x = os.path.join(self.opts.debug_pipeline, x)
@@ -1079,7 +1079,7 @@ OptionRecommendation(name='search_replace',
tdir = PersistentTemporaryDirectory('_plumber')
stream = self.input if self.input_fmt == 'recipe' else \
lopen(self.input, 'rb')
open(self.input, 'rb')
if self.input_fmt == 'recipe':
self.opts.original_recipe_input_arg = self.original_input_arg
+1 -1
View File
@@ -217,7 +217,7 @@ def cleanup_markup(log, root, styles, dest_dir, detect_cover, XPath):
if os.path.exists(path) and before_count(root, img, limit=10) < 5:
from ebook_converter.utils.imghdr import identify
try:
with lopen(path, 'rb') as imf:
with open(path, 'rb') as imf:
fmt, width, height = identify(imf)
except:
width, height, fmt = 0, 0, None # noqa
+3 -3
View File
@@ -372,11 +372,11 @@ class Convert(object):
def write(self, doc):
toc = create_toc(doc, self.body, self.resolved_link_map, self.styles, self.object_map, self.log, self.namespace)
raw = html.tostring(self.html, encoding='utf-8', doctype='<!DOCTYPE html>')
with lopen(os.path.join(self.dest_dir, 'index.html'), 'wb') as f:
with open(os.path.join(self.dest_dir, 'index.html'), 'wb') as f:
f.write(raw)
css = self.styles.generate_css(self.dest_dir, self.docx, self.notes_nopb, self.nosupsub)
if css:
with lopen(os.path.join(self.dest_dir, 'docx.css'), 'wb') as f:
with open(os.path.join(self.dest_dir, 'docx.css'), 'wb') as f:
f.write(css.encode('utf-8'))
opf = OPFCreator(self.dest_dir, self.mi)
@@ -394,7 +394,7 @@ class Convert(object):
guide.append(E.reference(
href='index.html#' + self.toc_anchor, title=_('Table of Contents'), type='toc'))
toc_file = os.path.join(self.dest_dir, 'toc.ncx')
with lopen(os.path.join(self.dest_dir, 'metadata.opf'), 'wb') as of, open(toc_file, 'wb') as ncx:
with open(os.path.join(self.dest_dir, 'metadata.opf'), 'wb') as of, open(toc_file, 'wb') as ncx:
opf.render(of, ncx, 'toc.ncx', process_guide=process_guide)
if os.path.getsize(toc_file) == 0:
os.remove(toc_file)
+5 -5
View File
@@ -48,7 +48,7 @@ def _metadata_from_formats(formats, force_read_metadata=False, pattern=None):
return mi2
for path, ext in zip(formats, extensions):
with lopen(path, 'rb') as stream:
with open(path, 'rb') as stream:
try:
newmi = get_metadata(stream, stream_type=ext,
use_libprs_metadata=True,
@@ -223,19 +223,19 @@ def opf_metadata(opfpath):
def forked_read_metadata(path, tdir):
from ebook_converter.ebooks.metadata.opf2 import metadata_to_opf
with lopen(path, 'rb') as f:
with open(path, 'rb') as f:
fmt = os.path.splitext(path)[1][1:].lower()
f.seek(0, 2)
sz = f.tell()
with lopen(os.path.join(tdir, 'size.txt'), 'wb') as s:
with open(os.path.join(tdir, 'size.txt'), 'wb') as s:
s.write(str(sz).encode('ascii'))
f.seek(0)
mi = get_metadata(f, fmt)
if mi.cover_data and mi.cover_data[1]:
with lopen(os.path.join(tdir, 'cover.jpg'), 'wb') as f:
with open(os.path.join(tdir, 'cover.jpg'), 'wb') as f:
f.write(mi.cover_data[1])
mi.cover_data = (None, None)
mi.cover = 'cover.jpg'
opf = metadata_to_opf(mi, default_lang='und')
with lopen(os.path.join(tdir, 'metadata.opf'), 'wb') as f:
with open(os.path.join(tdir, 'metadata.opf'), 'wb') as f:
f.write(opf)
+1 -1
View File
@@ -230,7 +230,7 @@ class TOC(list):
def read_html_toc(self, toc):
self.base_path = os.path.dirname(toc)
with lopen(toc, 'rb') as f:
with open(toc, 'rb') as f:
parsed_toc = parse_html_toc(f.read())
for href, fragment, txt in parsed_toc:
add = True
+2 -2
View File
@@ -289,7 +289,7 @@ class MobiReader(object):
def write_as_utf8(path, data):
if isinstance(data, str):
data = data.encode('utf-8')
with lopen(path, 'wb') as f:
with open(path, 'wb') as f:
f.write(data)
parse_cache[htmlfile] = root
@@ -297,7 +297,7 @@ class MobiReader(object):
ncx = io.BytesIO()
opf, ncx_manifest_entry = self.create_opf(htmlfile, guide, root)
self.created_opf_path = os.path.splitext(htmlfile)[0] + '.opf'
opf.render(lopen(self.created_opf_path, 'wb'), ncx,
opf.render(open(self.created_opf_path, 'wb'), ncx,
ncx_manifest_entry=ncx_manifest_entry)
ncx = ncx.getvalue()
if ncx:
@@ -60,7 +60,7 @@ class Resources(object):
try:
from ebook_converter.utils.img import optimize_png
optimize_png(pt.name)
data = lopen(pt.name, 'rb').read()
data = open(pt.name, 'rb').read()
finally:
os.remove(pt.name)
return func(data)
+2 -2
View File
@@ -575,7 +575,7 @@ class DirContainer(object):
if path is None:
path = self.opfname
path = os.path.join(self.rootdir, self._unquote(path))
with lopen(path, 'rb') as f:
with open(path, 'rb') as f:
return f.read()
def write(self, path, data):
@@ -583,7 +583,7 @@ class DirContainer(object):
dir = os.path.dirname(path)
if not os.path.isdir(dir):
os.makedirs(dir)
with lopen(path, 'wb') as f:
with open(path, 'wb') as f:
return f.write(data)
def exists(self, path):
+11 -11
View File
@@ -367,7 +367,7 @@ class Container(ContainerBase): # {{{
base = os.path.dirname(path)
if not os.path.exists(base):
os.makedirs(base)
with lopen(path, 'wb') as f:
with open(path, 'wb') as f:
if hasattr(data, 'read'):
shutil.copyfileobj(data, f)
else:
@@ -579,7 +579,7 @@ class Container(ContainerBase): # {{{
return set()
def parse(self, path, mime):
with lopen(path, 'rb') as src:
with open(path, 'rb') as src:
data = src.read()
if mime in OEB_DOCS:
data = self.parse_xhtml(data, self.relpath(path))
@@ -959,7 +959,7 @@ class Container(ContainerBase): # {{{
base = os.path.dirname(path)
if not os.path.exists(base):
os.makedirs(base)
lopen(path, 'wb').close()
open(path, 'wb').close()
return item
def format_opf(self):
@@ -1014,7 +1014,7 @@ class Container(ContainerBase): # {{{
if self.cloned and nlinks_file(dest) > 1:
# Decouple this file from its links
os.unlink(dest)
with lopen(dest, 'wb') as f:
with open(dest, 'wb') as f:
f.write(data)
def filesize(self, name):
@@ -1055,7 +1055,7 @@ class Container(ContainerBase): # {{{
this will commit the file if it is dirtied and remove it from the parse
cache. You must finish with this file before accessing the parsed
version of it again, or bad things will happen. '''
return lopen(self.get_file_path_for_processing(name, mode not in {'r', 'rb'}), mode)
return open(self.get_file_path_for_processing(name, mode not in {'r', 'rb'}), mode)
def commit(self, outpath=None, keep_parsed=False):
'''
@@ -1073,7 +1073,7 @@ class Container(ContainerBase): # {{{
mismatches = []
for name, path in iteritems(self.name_path_map):
opath = other.name_path_map[name]
with lopen(path, 'rb') as f1, lopen(opath, 'rb') as f2:
with open(path, 'rb') as f1, open(opath, 'rb') as f2:
if f1.read() != f2.read():
mismatches.append('The file %s is not the same'%name)
return '\n'.join(mismatches)
@@ -1146,7 +1146,7 @@ class EpubContainer(Container):
if fname is not None:
shutil.copy(os.path.join(dirpath, fname), os.path.join(base, fname))
else:
with lopen(self.pathtoepub, 'rb') as stream:
with open(self.pathtoepub, 'rb') as stream:
try:
zf = ZipFile(stream)
zf.extractall(tdir)
@@ -1363,12 +1363,12 @@ class EpubContainer(Container):
if err.errno != errno.EEXIST:
raise
for fname in filenames:
with lopen(os.path.join(dirpath, fname), 'rb') as src, lopen(os.path.join(base, fname), 'wb') as dest:
with open(os.path.join(dirpath, fname), 'rb') as src, open(os.path.join(base, fname), 'wb') as dest:
shutil.copyfileobj(src, dest)
else:
from ebook_converter.ebooks.tweak import zip_rebuilder
with lopen(join(self.root, 'mimetype'), 'wb') as f:
with open(join(self.root, 'mimetype'), 'wb') as f:
et = guess_type('a.epub')
if not isinstance(et, bytes):
et = et.encode('ascii')
@@ -1398,7 +1398,7 @@ class InvalidMobi(InvalidBook):
def do_explode(path, dest):
from ebook_converter.ebooks.mobi.reader.mobi6 import MobiReader
from ebook_converter.ebooks.mobi.reader.mobi8 import Mobi8Reader
with lopen(path, 'rb') as stream:
with open(path, 'rb') as stream:
mr = MobiReader(stream, default_log, None, None)
with CurrentDir(dest):
@@ -1456,7 +1456,7 @@ class AZW3Container(Container):
tdir = PersistentTemporaryDirectory('_azw3_container')
tdir = os.path.abspath(os.path.realpath(tdir))
self.root = tdir
with lopen(pathtoazw3, 'rb') as stream:
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.'))
+3 -3
View File
@@ -412,7 +412,7 @@ class Reader(FormatReader):
for col in row:
if col not in images:
raise Exception('Image with uid: %s missing.' % col)
w, h = identify(lopen('%s.jpg' % col, 'rb'))[1:]
w, h = identify(open('%s.jpg' % col, 'rb'))[1:]
row_width += w
if col_height < h:
col_height = h
@@ -427,14 +427,14 @@ class Reader(FormatReader):
x_off = 0
largest_height = 0
for col in row:
im = image_from_data(lopen('%s.jpg' % col, 'rb').read())
im = image_from_data(open('%s.jpg' % col, 'rb').read())
canvas.compose(im, x_off, y_off)
w, h = im.width(), im.height()
x_off += w
if largest_height < h:
largest_height = h
y_off += largest_height
with lopen('%s.jpg' % uid) as out:
with open('%s.jpg' % uid) as out:
out.write(canvas.export(compression_quality=70))
self.log.debug('Wrote composite image with uid %s to images/%s.jpg' % (uid, uid))
except Exception as e:
+4 -4
View File
@@ -47,7 +47,7 @@ def pdftohtml(output_dir, pdf_path, no_images, as_xml=False):
pdfsrc = os.path.join(output_dir, 'src.pdf')
index = os.path.join(output_dir, 'index.'+('xml' if as_xml else 'html'))
with lopen(pdf_path, 'rb') as src, lopen(pdfsrc, 'wb') as dest:
with open(pdf_path, 'rb') as src, open(pdfsrc, 'wb') as dest:
shutil.copyfileobj(src, dest)
with CurrentDir(output_dir):
@@ -79,7 +79,7 @@ def pdftohtml(output_dir, pdf_path, no_images, as_xml=False):
ret = eintr_retry_call(p.wait)
logf.flush()
logf.close()
out = lopen(logf.name, 'rb').read().decode('utf-8', 'replace').strip()
out = open(logf.name, 'rb').read().decode('utf-8', 'replace').strip()
if ret != 0:
raise ConversionError('pdftohtml failed with return code: %d\n%s' % (ret, out))
if out:
@@ -89,7 +89,7 @@ def pdftohtml(output_dir, pdf_path, no_images, as_xml=False):
raise DRMError()
if not as_xml:
with lopen(index, 'r+b') as i:
with open(index, 'r+b') as i:
raw = i.read().decode('utf-8', 'replace')
raw = flip_images(raw)
raw = raw.replace('<head', '<!-- created by ebook-converter\'s pdftohtml -->\n <head', 1)
@@ -151,7 +151,7 @@ def parse_outline(raw, output_dir):
def flip_image(img, flip):
from ebook_converter.utils.img import flip_image, image_and_format_from_data, image_to_data
with lopen(img, 'r+b') as f:
with open(img, 'r+b') as f:
img, fmt = image_and_format_from_data(f.read())
img = flip_image(img, horizontal='x' in flip, vertical='y' in flip)
f.seek(0), f.truncate()
+1 -1
View File
@@ -228,7 +228,7 @@ def opf_writer(path, opf_name, manifest, spine, mi):
opf = OPFCreator(path, mi)
opf.create_manifest(manifest)
opf.create_spine(spine)
with lopen(os.path.join(path, opf_name), 'wb') as opffile:
with open(os.path.join(path, opf_name), 'wb') as opffile:
opf.render(opffile)