The file() builtin has been removed in Python 3. Use open() instead.
authorBerker Peksag <berker.peksag@gmail.com>
Sat, 7 Jun 2014 10:51:42 +0000 (13:51 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Sat, 7 Jun 2014 10:51:42 +0000 (13:51 +0300)
mediagoblin/gmg_commands/addmedia.py
mediagoblin/media_types/ascii/processing.py
mediagoblin/media_types/image/processing.py
mediagoblin/storage/__init__.py
mediagoblin/storage/cloudfiles.py
mediagoblin/tests/test_pluginapi.py
mediagoblin/tests/test_storage.py
mediagoblin/tools/exif.py

index 34add88b158247c6caced1240e336ce84ab1704d..b741b96f9a3080e9dbf8238ba779e52721a0e810 100644 (file)
@@ -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),
index 6f388573d525c8c1b91d1cfbda3a5d2a23c538c5..712b0692e5593d9747a544b065bde8c3ed2f58d0 100644 (file)
@@ -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)
index ae9ece2465e5e050cc219f713decfa53c4e2a380..dc6a275eed478a23d2f64c9c7f995130f8867462 100644 (file)
@@ -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)
 
index 8462e08ef1a55279a093ed392b60de112a1cdba9..14f13bd3e4cb1ead3f36ba8597022b93ea762cea 100644 (file)
@@ -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)
 
index 47c81ad6b42ff940aef51e25e29372787523c7c3..532e5bacab6a096862ba3a11f2513087b9d9bbff 100644 (file)
@@ -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)
 
index eae0ce15199ac6e97742b71abc91e11b7afc70a1..5a3d41e62d6b6d1959d44c4bac3e57fe2f8ee469 100644 (file)
@@ -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!'
 
 
index 2194741596135a2039ab941b101701a95e7b4b6d..9b96ecbe458fe1c5aa16ef21e7c910464c953280 100644 (file)
@@ -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'
 
index 736bae7dda66cb8d1d0be189c25d03f512157c22..691d3a2be84e20243de7a044f427134f7a982c6a 100644 (file)
@@ -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.'))