1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-28 09:34: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
+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.'))