The file() builtin has been removed in Python 3. Use open() instead.
This commit is contained in:
parent
120fa4ae95
commit
d9aced73f1
@ -95,7 +95,7 @@ def addmedia(args):
|
|||||||
submit_media(
|
submit_media(
|
||||||
mg_app=app,
|
mg_app=app,
|
||||||
user=user,
|
user=user,
|
||||||
submitted_file=file(abs_filename, 'r'), filename=filename,
|
submitted_file=open(abs_filename, 'r'), filename=filename,
|
||||||
title=maybe_unicodeify(args.title),
|
title=maybe_unicodeify(args.title),
|
||||||
description=maybe_unicodeify(args.description),
|
description=maybe_unicodeify(args.description),
|
||||||
license=maybe_unicodeify(args.license),
|
license=maybe_unicodeify(args.license),
|
||||||
|
@ -95,7 +95,7 @@ class CommonAsciiProcessor(MediaProcessor):
|
|||||||
orig_file.seek(0)
|
orig_file.seek(0)
|
||||||
|
|
||||||
def store_unicode_file(self):
|
def store_unicode_file(self):
|
||||||
with file(self.process_filename, 'rb') as orig_file:
|
with open(self.process_filename, 'rb') as orig_file:
|
||||||
self._detect_charset(orig_file)
|
self._detect_charset(orig_file)
|
||||||
unicode_filepath = create_pub_filepath(self.entry,
|
unicode_filepath = create_pub_filepath(self.entry,
|
||||||
'ascii-portable.txt')
|
'ascii-portable.txt')
|
||||||
@ -114,7 +114,7 @@ class CommonAsciiProcessor(MediaProcessor):
|
|||||||
self.entry.media_files['unicode'] = unicode_filepath
|
self.entry.media_files['unicode'] = unicode_filepath
|
||||||
|
|
||||||
def generate_thumb(self, font=None, thumb_size=None):
|
def generate_thumb(self, font=None, thumb_size=None):
|
||||||
with file(self.process_filename, 'rb') as orig_file:
|
with open(self.process_filename, 'rb') as orig_file:
|
||||||
# If no font kwarg, check config
|
# If no font kwarg, check config
|
||||||
if not font:
|
if not font:
|
||||||
font = self.ascii_config.get('thumbnail_font', None)
|
font = self.ascii_config.get('thumbnail_font', None)
|
||||||
@ -143,7 +143,7 @@ class CommonAsciiProcessor(MediaProcessor):
|
|||||||
thumb = converter._create_image(
|
thumb = converter._create_image(
|
||||||
orig_file.read())
|
orig_file.read())
|
||||||
|
|
||||||
with file(tmp_thumb, 'w') as thumb_file:
|
with open(tmp_thumb, 'w') as thumb_file:
|
||||||
thumb.thumbnail(
|
thumb.thumbnail(
|
||||||
thumb_size,
|
thumb_size,
|
||||||
Image.ANTIALIAS)
|
Image.ANTIALIAS)
|
||||||
|
@ -76,7 +76,7 @@ def resize_image(entry, resized, keyname, target_name, new_size,
|
|||||||
|
|
||||||
# Copy the new file to the conversion subdir, then remotely.
|
# Copy the new file to the conversion subdir, then remotely.
|
||||||
tmp_resized_filename = os.path.join(workdir, target_name)
|
tmp_resized_filename = os.path.join(workdir, target_name)
|
||||||
with file(tmp_resized_filename, 'w') as resized_file:
|
with open(tmp_resized_filename, 'wb') as resized_file:
|
||||||
resized.save(resized_file, quality=quality)
|
resized.save(resized_file, quality=quality)
|
||||||
store_public(entry, keyname, tmp_resized_filename, target_name)
|
store_public(entry, keyname, tmp_resized_filename, target_name)
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ class StorageInterface(object):
|
|||||||
shutil.copy(self.get_local_path(filepath), dest_path)
|
shutil.copy(self.get_local_path(filepath), dest_path)
|
||||||
else:
|
else:
|
||||||
with self.get_file(filepath, 'rb') as source_file:
|
with self.get_file(filepath, 'rb') as source_file:
|
||||||
with file(dest_path, 'wb') as dest_file:
|
with open(dest_path, 'wb') as dest_file:
|
||||||
# Copy from remote storage in 4M chunks
|
# Copy from remote storage in 4M chunks
|
||||||
shutil.copyfileobj(source_file, dest_file, length=4*1048576)
|
shutil.copyfileobj(source_file, dest_file, length=4*1048576)
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ class StorageInterface(object):
|
|||||||
your storage system.
|
your storage system.
|
||||||
"""
|
"""
|
||||||
with self.get_file(filepath, 'wb') as dest_file:
|
with self.get_file(filepath, 'wb') as dest_file:
|
||||||
with file(filename, 'rb') as source_file:
|
with open(filename, 'rb') as source_file:
|
||||||
# Copy to storage system in 4M chunks
|
# Copy to storage system in 4M chunks
|
||||||
shutil.copyfileobj(source_file, dest_file, length=4*1048576)
|
shutil.copyfileobj(source_file, dest_file, length=4*1048576)
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ class CloudFilesStorage(StorageInterface):
|
|||||||
"""
|
"""
|
||||||
# Override this method, using the "stream" iterator for efficient streaming
|
# Override this method, using the "stream" iterator for efficient streaming
|
||||||
with self.get_file(filepath, 'rb') as source_file:
|
with self.get_file(filepath, 'rb') as source_file:
|
||||||
with file(dest_path, 'wb') as dest_file:
|
with open(dest_path, 'wb') as dest_file:
|
||||||
for data in source_file:
|
for data in source_file:
|
||||||
dest_file.write(data)
|
dest_file.write(data)
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ class CloudFilesStorage(StorageInterface):
|
|||||||
# TODO: Fixing write() still seems worthwhile though.
|
# TODO: Fixing write() still seems worthwhile though.
|
||||||
_log.debug('Sending {0} to cloudfiles...'.format(filepath))
|
_log.debug('Sending {0} to cloudfiles...'.format(filepath))
|
||||||
with self.get_file(filepath, 'wb') as dest_file:
|
with self.get_file(filepath, 'wb') as dest_file:
|
||||||
with file(filename, 'rb') as source_file:
|
with open(filename, 'rb') as source_file:
|
||||||
# Copy to storage system in 4096 byte chunks
|
# Copy to storage system in 4096 byte chunks
|
||||||
dest_file.send(source_file)
|
dest_file.send(source_file)
|
||||||
|
|
||||||
|
@ -421,7 +421,7 @@ def test_plugin_assetlink(static_plugin_app):
|
|||||||
junk_file_path = os.path.join(
|
junk_file_path = os.path.join(
|
||||||
linked_assets_dir.rstrip(os.path.sep),
|
linked_assets_dir.rstrip(os.path.sep),
|
||||||
'junk.txt')
|
'junk.txt')
|
||||||
with file(junk_file_path, 'w') as junk_file:
|
with open(junk_file_path, 'w') as junk_file:
|
||||||
junk_file.write('barf')
|
junk_file.write('barf')
|
||||||
|
|
||||||
os.unlink(plugin_link_dir)
|
os.unlink(plugin_link_dir)
|
||||||
@ -440,14 +440,14 @@ to:
|
|||||||
|
|
||||||
# link dir exists, but is a non-symlink
|
# link dir exists, but is a non-symlink
|
||||||
os.unlink(plugin_link_dir)
|
os.unlink(plugin_link_dir)
|
||||||
with file(plugin_link_dir, 'w') as clobber_file:
|
with open(plugin_link_dir, 'w') as clobber_file:
|
||||||
clobber_file.write('clobbered!')
|
clobber_file.write('clobbered!')
|
||||||
|
|
||||||
result = run_assetlink().collection[0]
|
result = run_assetlink().collection[0]
|
||||||
assert result == 'Could not link "staticstuff": %s exists and is not a symlink\n' % (
|
assert result == 'Could not link "staticstuff": %s exists and is not a symlink\n' % (
|
||||||
plugin_link_dir)
|
plugin_link_dir)
|
||||||
|
|
||||||
with file(plugin_link_dir, 'r') as clobber_file:
|
with open(plugin_link_dir, 'r') as clobber_file:
|
||||||
assert clobber_file.read() == 'clobbered!'
|
assert clobber_file.read() == 'clobbered!'
|
||||||
|
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ def test_basic_storage_get_file():
|
|||||||
with this_storage.get_file(filepath, 'r') as our_file:
|
with this_storage.get_file(filepath, 'r') as our_file:
|
||||||
assert our_file.read() == 'First file'
|
assert our_file.read() == 'First file'
|
||||||
assert os.path.exists(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt'))
|
assert os.path.exists(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt'))
|
||||||
with file(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt'), 'r') as our_file:
|
with open(os.path.join(tmpdir, 'dir1/dir2/ourfile.txt'), 'r') as our_file:
|
||||||
assert our_file.read() == 'First file'
|
assert our_file.read() == 'First file'
|
||||||
|
|
||||||
# Write to the same path but try to get a unique file.
|
# Write to the same path but try to get a unique file.
|
||||||
@ -186,13 +186,13 @@ def test_basic_storage_get_file():
|
|||||||
with this_storage.get_file(new_filepath, 'r') as our_file:
|
with this_storage.get_file(new_filepath, 'r') as our_file:
|
||||||
assert our_file.read() == 'Second file'
|
assert our_file.read() == 'Second file'
|
||||||
assert os.path.exists(os.path.join(tmpdir, *new_filepath))
|
assert os.path.exists(os.path.join(tmpdir, *new_filepath))
|
||||||
with file(os.path.join(tmpdir, *new_filepath), 'r') as our_file:
|
with open(os.path.join(tmpdir, *new_filepath), 'r') as our_file:
|
||||||
assert our_file.read() == 'Second file'
|
assert our_file.read() == 'Second file'
|
||||||
|
|
||||||
# Read from an existing file
|
# Read from an existing file
|
||||||
manually_written_file = os.makedirs(
|
manually_written_file = os.makedirs(
|
||||||
os.path.join(tmpdir, 'testydir'))
|
os.path.join(tmpdir, 'testydir'))
|
||||||
with file(os.path.join(tmpdir, 'testydir/testyfile.txt'), 'w') as testyfile:
|
with open(os.path.join(tmpdir, 'testydir/testyfile.txt'), 'w') as testyfile:
|
||||||
testyfile.write('testy file! so testy.')
|
testyfile.write('testy file! so testy.')
|
||||||
|
|
||||||
with this_storage.get_file(['testydir', 'testyfile.txt']) as testyfile:
|
with this_storage.get_file(['testydir', 'testyfile.txt']) as testyfile:
|
||||||
@ -288,7 +288,7 @@ def test_basic_storage_copy_locally():
|
|||||||
this_storage.copy_locally(filepath, new_file_dest)
|
this_storage.copy_locally(filepath, new_file_dest)
|
||||||
this_storage.delete_file(filepath)
|
this_storage.delete_file(filepath)
|
||||||
|
|
||||||
assert file(new_file_dest).read() == 'Testing this file'
|
assert open(new_file_dest).read() == 'Testing this file'
|
||||||
|
|
||||||
os.remove(new_file_dest)
|
os.remove(new_file_dest)
|
||||||
os.rmdir(dest_tmpdir)
|
os.rmdir(dest_tmpdir)
|
||||||
@ -297,7 +297,7 @@ def test_basic_storage_copy_locally():
|
|||||||
|
|
||||||
def _test_copy_local_to_storage_works(tmpdir, this_storage):
|
def _test_copy_local_to_storage_works(tmpdir, this_storage):
|
||||||
local_filename = tempfile.mktemp()
|
local_filename = tempfile.mktemp()
|
||||||
with file(local_filename, 'w') as tmpfile:
|
with open(local_filename, 'w') as tmpfile:
|
||||||
tmpfile.write('haha')
|
tmpfile.write('haha')
|
||||||
|
|
||||||
this_storage.copy_local_to_storage(
|
this_storage.copy_local_to_storage(
|
||||||
@ -305,7 +305,7 @@ def _test_copy_local_to_storage_works(tmpdir, this_storage):
|
|||||||
|
|
||||||
os.remove(local_filename)
|
os.remove(local_filename)
|
||||||
|
|
||||||
assert file(
|
assert open(
|
||||||
os.path.join(tmpdir, 'dir1/dir2/copiedto.txt'),
|
os.path.join(tmpdir, 'dir1/dir2/copiedto.txt'),
|
||||||
'r').read() == 'haha'
|
'r').read() == 'haha'
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ def extract_exif(filename):
|
|||||||
Returns EXIF tags found in file at ``filename``
|
Returns EXIF tags found in file at ``filename``
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with file(filename) as image:
|
with open(filename, 'rb') as image:
|
||||||
return process_file(image, details=False)
|
return process_file(image, details=False)
|
||||||
except IOError:
|
except IOError:
|
||||||
raise BadMediaFail(_('Could not read the image file.'))
|
raise BadMediaFail(_('Could not read the image file.'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user