[Python-checkins] cpython: package: replace open(fn, 'w').close() by open(fn, 'wb').close()

victor.stinner python-checkins at python.org
Thu May 19 15:53:40 CEST 2011


http://hg.python.org/cpython/rev/946baaeb1d10
changeset:   70203:946baaeb1d10
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Thu May 19 15:52:59 2011 +0200
summary:
  package: replace open(fn, 'w').close() by open(fn, 'wb').close()

We don't need to open the files in text mode just to create them (or update
their modification time).

files:
  Lib/packaging/command/install_distinfo.py    |  2 +-
  Lib/packaging/tests/test_command_build_py.py |  4 ++--
  Lib/packaging/tests/test_database.py         |  2 +-
  Lib/packaging/tests/test_install.py          |  2 +-
  Lib/packaging/util.py                        |  2 +-
  5 files changed, 6 insertions(+), 6 deletions(-)


diff --git a/Lib/packaging/command/install_distinfo.py b/Lib/packaging/command/install_distinfo.py
--- a/Lib/packaging/command/install_distinfo.py
+++ b/Lib/packaging/command/install_distinfo.py
@@ -98,7 +98,7 @@
             if self.requested:
                 requested_path = os.path.join(self.distinfo_dir, 'REQUESTED')
                 logger.info('creating %s', requested_path)
-                open(requested_path, 'w').close()
+                open(requested_path, 'wb').close()
                 self.outputs.append(requested_path)
 
 
diff --git a/Lib/packaging/tests/test_command_build_py.py b/Lib/packaging/tests/test_command_build_py.py
--- a/Lib/packaging/tests/test_command_build_py.py
+++ b/Lib/packaging/tests/test_command_build_py.py
@@ -72,10 +72,10 @@
         sources = self.mkdtemp()
         pkg = os.path.join(sources, 'pkg')
         os.mkdir(pkg)
-        open(os.path.join(pkg, "__init__.py"), "w").close()
+        open(os.path.join(pkg, "__init__.py"), "wb").close()
         testdir = os.path.join(pkg, "doc")
         os.mkdir(testdir)
-        open(os.path.join(testdir, "testfile"), "w").close()
+        open(os.path.join(testdir, "testfile"), "wb").close()
 
         os.chdir(sources)
         old_stdout = sys.stdout
diff --git a/Lib/packaging/tests/test_database.py b/Lib/packaging/tests/test_database.py
--- a/Lib/packaging/tests/test_database.py
+++ b/Lib/packaging/tests/test_database.py
@@ -133,7 +133,7 @@
     def tearDown(self):
         for distinfo_dir in self.dirs:
             record_file = os.path.join(distinfo_dir, 'RECORD')
-            open(record_file, 'w').close()
+            open(record_file, 'wb').close()
         super(TestDistribution, self).tearDown()
 
     def test_instantiation(self):
diff --git a/Lib/packaging/tests/test_install.py b/Lib/packaging/tests/test_install.py
--- a/Lib/packaging/tests/test_install.py
+++ b/Lib/packaging/tests/test_install.py
@@ -227,7 +227,7 @@
         newpath = self.mkdtemp()
         files = [os.path.join(path, str(x)) for x in range(1, 20)]
         for f in files:
-            open(f, 'a+').close()
+            open(f, 'ab+').close()
         output = [o for o in install._move_files(files, newpath)]
 
         # check that output return the list of old/new places
diff --git a/Lib/packaging/util.py b/Lib/packaging/util.py
--- a/Lib/packaging/util.py
+++ b/Lib/packaging/util.py
@@ -1201,7 +1201,7 @@
     if requested:
         requested_path = distinfo['requested_path']
         logger.info('creating %s', requested_path)
-        open(requested_path, 'w').close()
+        open(requested_path, 'wb').close()
         distinfo['installed'].append(requested_path)
 
     record_path = distinfo['record_path']

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list