diff options
-rw-r--r-- | mediagoblin/gmg_commands/addmedia.py | 2 | ||||
-rw-r--r-- | mediagoblin/media_types/ascii/processing.py | 6 | ||||
-rw-r--r-- | mediagoblin/media_types/image/processing.py | 2 | ||||
-rw-r--r-- | mediagoblin/storage/__init__.py | 4 | ||||
-rw-r--r-- | mediagoblin/storage/cloudfiles.py | 4 | ||||
-rw-r--r-- | mediagoblin/tests/test_pluginapi.py | 6 | ||||
-rw-r--r-- | mediagoblin/tests/test_storage.py | 12 | ||||
-rw-r--r-- | mediagoblin/tools/exif.py | 2 |
8 files changed, 19 insertions, 19 deletions
diff --git a/mediagoblin/gmg_commands/addmedia.py b/mediagoblin/gmg_commands/addmedia.py index 34add88b..b741b96f 100644 --- a/mediagoblin/gmg_commands/addmedia.py +++ b/mediagoblin/gmg_commands/addmedia.py @@ -95,7 +95,7 @@ def addmedia(args): submit_media( mg_app=app, user=user, - submitted_file=file(abs_filename, 'r'), filename=filename, + submitted_file=open(abs_filename, 'r'), filename=filename, title=maybe_unicodeify(args.title), description=maybe_unicodeify(args.description), license=maybe_unicodeify(args.license), diff --git a/mediagoblin/media_types/ascii/processing.py b/mediagoblin/media_types/ascii/processing.py index 6f388573..712b0692 100644 --- a/mediagoblin/media_types/ascii/processing.py +++ b/mediagoblin/media_types/ascii/processing.py @@ -95,7 +95,7 @@ class CommonAsciiProcessor(MediaProcessor): orig_file.seek(0) 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) unicode_filepath = create_pub_filepath(self.entry, 'ascii-portable.txt') @@ -114,7 +114,7 @@ class CommonAsciiProcessor(MediaProcessor): self.entry.media_files['unicode'] = unicode_filepath 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 not font: font = self.ascii_config.get('thumbnail_font', None) @@ -143,7 +143,7 @@ class CommonAsciiProcessor(MediaProcessor): thumb = converter._create_image( orig_file.read()) - with file(tmp_thumb, 'w') as thumb_file: + with open(tmp_thumb, 'w') as thumb_file: thumb.thumbnail( thumb_size, Image.ANTIALIAS) diff --git a/mediagoblin/media_types/image/processing.py b/mediagoblin/media_types/image/processing.py index ae9ece24..dc6a275e 100644 --- a/mediagoblin/media_types/image/processing.py +++ b/mediagoblin/media_types/image/processing.py @@ -76,7 +76,7 @@ def resize_image(entry, resized, keyname, target_name, new_size, # Copy the new file to the conversion subdir, then remotely. 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) store_public(entry, keyname, tmp_resized_filename, target_name) diff --git a/mediagoblin/storage/__init__.py b/mediagoblin/storage/__init__.py index 8462e08e..14f13bd3 100644 --- a/mediagoblin/storage/__init__.py +++ b/mediagoblin/storage/__init__.py @@ -178,7 +178,7 @@ class StorageInterface(object): shutil.copy(self.get_local_path(filepath), dest_path) else: 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 shutil.copyfileobj(source_file, dest_file, length=4*1048576) @@ -191,7 +191,7 @@ class StorageInterface(object): your storage system. """ 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 shutil.copyfileobj(source_file, dest_file, length=4*1048576) diff --git a/mediagoblin/storage/cloudfiles.py b/mediagoblin/storage/cloudfiles.py index 47c81ad6..532e5bac 100644 --- a/mediagoblin/storage/cloudfiles.py +++ b/mediagoblin/storage/cloudfiles.py @@ -143,7 +143,7 @@ class CloudFilesStorage(StorageInterface): """ # Override this method, using the "stream" iterator for efficient streaming 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: dest_file.write(data) @@ -164,7 +164,7 @@ class CloudFilesStorage(StorageInterface): # TODO: Fixing write() still seems worthwhile though. _log.debug('Sending {0} to cloudfiles...'.format(filepath)) 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 dest_file.send(source_file) diff --git a/mediagoblin/tests/test_pluginapi.py b/mediagoblin/tests/test_pluginapi.py index eae0ce15..5a3d41e6 100644 --- a/mediagoblin/tests/test_pluginapi.py +++ b/mediagoblin/tests/test_pluginapi.py @@ -421,7 +421,7 @@ def test_plugin_assetlink(static_plugin_app): junk_file_path = os.path.join( linked_assets_dir.rstrip(os.path.sep), 'junk.txt') - with file(junk_file_path, 'w') as junk_file: + with open(junk_file_path, 'w') as junk_file: junk_file.write('barf') os.unlink(plugin_link_dir) @@ -440,14 +440,14 @@ to: # link dir exists, but is a non-symlink 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!') result = run_assetlink().collection[0] assert result == 'Could not link "staticstuff": %s exists and is not a symlink\n' % ( 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!' diff --git a/mediagoblin/tests/test_storage.py b/mediagoblin/tests/test_storage.py index 21947415..9b96ecbe 100644 --- a/mediagoblin/tests/test_storage.py +++ b/mediagoblin/tests/test_storage.py @@ -174,7 +174,7 @@ def test_basic_storage_get_file(): with this_storage.get_file(filepath, 'r') as our_file: assert our_file.read() == 'First file' 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' # 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: assert our_file.read() == 'Second file' 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' # Read from an existing file manually_written_file = os.makedirs( 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.') 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.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.rmdir(dest_tmpdir) @@ -297,7 +297,7 @@ def test_basic_storage_copy_locally(): def _test_copy_local_to_storage_works(tmpdir, this_storage): local_filename = tempfile.mktemp() - with file(local_filename, 'w') as tmpfile: + with open(local_filename, 'w') as tmpfile: tmpfile.write('haha') this_storage.copy_local_to_storage( @@ -305,7 +305,7 @@ def _test_copy_local_to_storage_works(tmpdir, this_storage): os.remove(local_filename) - assert file( + assert open( os.path.join(tmpdir, 'dir1/dir2/copiedto.txt'), 'r').read() == 'haha' diff --git a/mediagoblin/tools/exif.py b/mediagoblin/tools/exif.py index 736bae7d..691d3a2b 100644 --- a/mediagoblin/tools/exif.py +++ b/mediagoblin/tools/exif.py @@ -77,7 +77,7 @@ def extract_exif(filename): Returns EXIF tags found in file at ``filename`` """ try: - with file(filename) as image: + with open(filename, 'rb') as image: return process_file(image, details=False) except IOError: raise BadMediaFail(_('Could not read the image file.')) |