mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-19 12:43:35 +02:00
Removed superfluous lopen builtin
This commit is contained in:
@@ -195,7 +195,7 @@ def case_preserving_open_file(path, mode='wb', mkdir_mode=0o777):
|
||||
ans = fpath = cpath
|
||||
else:
|
||||
fname = components[-1]
|
||||
ans = lopen(os.path.join(cpath, fname), mode)
|
||||
ans = open(os.path.join(cpath, fname), mode)
|
||||
# Ensure file and all its metadata is written to disk so that subsequent
|
||||
# listdir() has file name in it. I don't know if this is actually
|
||||
# necessary, but given the diversity of platforms, best to be safe.
|
||||
@@ -434,7 +434,7 @@ class WindowsAtomicFolderMove(object):
|
||||
pass
|
||||
|
||||
win32file.SetFilePointer(handle, 0, win32file.FILE_BEGIN)
|
||||
with lopen(dest, 'wb') as f:
|
||||
with open(dest, 'wb') as f:
|
||||
while True:
|
||||
hr, raw = win32file.ReadFile(handle, 1024*1024)
|
||||
if hr != 0:
|
||||
|
||||
@@ -245,7 +245,7 @@ class FontScanner(Thread):
|
||||
path = font_or_path
|
||||
if isinstance(font_or_path, dict):
|
||||
path = font_or_path['path']
|
||||
with lopen(path, 'rb') as f:
|
||||
with open(path, 'rb') as f:
|
||||
return f.read()
|
||||
|
||||
def find_font_for_text(self, text, allowed_families={'serif', 'sans-serif'},
|
||||
@@ -366,7 +366,7 @@ class FontScanner(Thread):
|
||||
self.write_cache()
|
||||
|
||||
def read_font_metadata(self, path, fileid):
|
||||
with lopen(path, 'rb') as f:
|
||||
with open(path, 'rb') as f:
|
||||
try:
|
||||
fm = FontMetadata(f)
|
||||
except UnsupportedFont:
|
||||
|
||||
@@ -441,7 +441,7 @@ def get_font_for_text(text, candidate_font_data=None):
|
||||
from ebook_converter.utils.fonts.scanner import font_scanner
|
||||
family, faces = font_scanner.find_font_for_text(text)
|
||||
if faces:
|
||||
with lopen(faces[0]['path'], 'rb') as f:
|
||||
with open(faces[0]['path'], 'rb') as f:
|
||||
candidate_font_data = f.read()
|
||||
return candidate_font_data
|
||||
|
||||
|
||||
@@ -49,11 +49,11 @@ def load_jxr_data(data):
|
||||
with TemporaryDirectory() as tdir:
|
||||
if iswindows and isinstance(tdir, str):
|
||||
tdir = tdir.encode('mbcs')
|
||||
with lopen(os.path.join(tdir, 'input.jxr'), 'wb') as f:
|
||||
with open(os.path.join(tdir, 'input.jxr'), 'wb') as f:
|
||||
f.write(data)
|
||||
cmd = [get_exe_path('JxrDecApp'), '-i', 'input.jxr', '-o', 'output.tif']
|
||||
creationflags = 0x08 if iswindows else 0
|
||||
subprocess.Popen(cmd, cwd=tdir, stdout=lopen(os.devnull, 'wb'), stderr=subprocess.STDOUT, creationflags=creationflags).wait()
|
||||
subprocess.Popen(cmd, cwd=tdir, stdout=open(os.devnull, 'wb'), stderr=subprocess.STDOUT, creationflags=creationflags).wait()
|
||||
i = QImage()
|
||||
if not i.load(os.path.join(tdir, 'output.tif')):
|
||||
raise NotImage('Failed to convert JPEG-XR image')
|
||||
@@ -124,7 +124,7 @@ def image_from_data(data):
|
||||
|
||||
def image_from_path(path):
|
||||
' Load an image from the specified path. '
|
||||
with lopen(path, 'rb') as f:
|
||||
with open(path, 'rb') as f:
|
||||
return image_from_data(f.read())
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ def save_image(img, path, **kw):
|
||||
`image_to_data()` function. '''
|
||||
fmt = path.rpartition('.')[-1]
|
||||
kw['fmt'] = kw.get('fmt', fmt)
|
||||
with lopen(path, 'wb') as f:
|
||||
with open(path, 'wb') as f:
|
||||
f.write(image_to_data(image_from_data(img), **kw))
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ def save_cover_data_to(
|
||||
changed = True
|
||||
if path is None:
|
||||
return image_to_data(img, compression_quality, fmt, compression_quality // 10) if changed else data
|
||||
with lopen(path, 'wb') as f:
|
||||
with open(path, 'wb') as f:
|
||||
f.write(image_to_data(img, compression_quality, fmt, compression_quality // 10) if changed else data)
|
||||
# }}}
|
||||
|
||||
@@ -667,7 +667,7 @@ def test(): # {{{
|
||||
if __name__ == '__main__': # {{{
|
||||
args = sys.argv[1:]
|
||||
infile = args.pop(0)
|
||||
img = image_from_data(lopen(infile, 'rb').read())
|
||||
img = image_from_data(open(infile, 'rb').read())
|
||||
func = globals()[args[0]]
|
||||
kw = {}
|
||||
args.pop(0)
|
||||
@@ -692,6 +692,6 @@ if __name__ == '__main__': # {{{
|
||||
bn = os.path.basename(infile)
|
||||
outf = bn.rpartition('.')[0] + '.' + '-output' + bn.rpartition('.')[-1]
|
||||
img = func(img, **kw)
|
||||
with lopen(outf, 'wb') as f:
|
||||
with open(outf, 'wb') as f:
|
||||
f.write(image_to_data(img, fmt=outf.rpartition('.')[-1]))
|
||||
# }}}
|
||||
|
||||
@@ -15,7 +15,7 @@ def what(file, h=None):
|
||||
' Recognize image headers '
|
||||
if h is None:
|
||||
if isinstance(file, (str, bytes)):
|
||||
with lopen(file, 'rb') as f:
|
||||
with open(file, 'rb') as f:
|
||||
h = f.read(HSIZE)
|
||||
else:
|
||||
location = file.tell()
|
||||
@@ -41,7 +41,7 @@ def identify(src):
|
||||
width = height = -1
|
||||
|
||||
if isinstance(src, str):
|
||||
stream = lopen(src, 'rb')
|
||||
stream = open(src, 'rb')
|
||||
elif isinstance(src, bytes):
|
||||
stream = ReadOnlyFileBuffer(src)
|
||||
else:
|
||||
|
||||
@@ -7,7 +7,7 @@ import json
|
||||
from gettext import GNUTranslations, NullTranslations
|
||||
import pkg_resources
|
||||
|
||||
from ebook_converter.polyglot.builtins import is_py3, iteritems
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
|
||||
_available_translations = None
|
||||
|
||||
|
||||
@@ -190,7 +190,7 @@ else:
|
||||
def create_single_instance_mutex(name, per_user=True):
|
||||
from ebook_converter.utils.ipc import eintr_retry_call
|
||||
path = singleinstance_path(name, per_user)
|
||||
f = lopen(path, 'w')
|
||||
f = open(path, 'w')
|
||||
try:
|
||||
eintr_retry_call(fcntl.lockf, f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
return partial(_clean_lock_file, f)
|
||||
|
||||
Reference in New Issue
Block a user