[Python-checkins] cpython (2.7): Use os.devnull instead of hardcoded '/dev/null'.

serhiy.storchaka python-checkins at python.org
Sun Feb 15 13:39:23 CET 2015


https://hg.python.org/cpython/rev/7d2018774925
changeset:   94626:7d2018774925
branch:      2.7
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Feb 15 13:57:49 2015 +0200
summary:
  Use os.devnull instead of hardcoded '/dev/null'.

files:
  Lib/test/test_cgi.py       |  4 ++--
  Lib/test/test_sysconfig.py |  4 ++--
  Tools/compiler/compile.py  |  7 ++-----
  3 files changed, 6 insertions(+), 9 deletions(-)


diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py
--- a/Lib/test/test_cgi.py
+++ b/Lib/test/test_cgi.py
@@ -194,9 +194,9 @@
         cgi.initlog("%s", "Testing initlog 1")
         cgi.log("%s", "Testing log 2")
         self.assertEqual(cgi.logfp.getvalue(), "Testing initlog 1\nTesting log 2\n")
-        if os.path.exists("/dev/null"):
+        if os.path.exists(os.devnull):
             cgi.logfp = None
-            cgi.logfile = "/dev/null"
+            cgi.logfile = os.devnull
             cgi.initlog("%s", "Testing log 3")
             cgi.log("Testing log 4")
 
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -294,7 +294,7 @@
         if 'MACOSX_DEPLOYMENT_TARGET' in env:
             del env['MACOSX_DEPLOYMENT_TARGET']
 
-        with open('/dev/null', 'w') as devnull_fp:
+        with open(os.devnull, 'w') as devnull_fp:
             p = subprocess.Popen([
                     sys.executable, '-c',
                    'import sysconfig; print(sysconfig.get_platform())',
@@ -320,7 +320,7 @@
                 'import sysconfig; print(sysconfig.get_platform())',
             ],
             stdout=subprocess.PIPE,
-            stderr=open('/dev/null'),
+            stderr=open(os.devnull),
             env=env)
         test_platform = p.communicate()[0].strip()
         test_platform = test_platform.decode('utf-8')
diff --git a/Tools/compiler/compile.py b/Tools/compiler/compile.py
--- a/Tools/compiler/compile.py
+++ b/Tools/compiler/compile.py
@@ -1,3 +1,4 @@
+import os
 import sys
 import getopt
 
@@ -16,11 +17,7 @@
             VERBOSE = 1
             visitor.ASTVisitor.VERBOSE = visitor.ASTVisitor.VERBOSE + 1
         if k == '-q':
-            if sys.platform[:3]=="win":
-                f = open('nul', 'wb') # /dev/null fails on Windows...
-            else:
-                f = open('/dev/null', 'wb')
-            sys.stdout = f
+            sys.stdout = open(os.devnull, 'wb')
         if k == '-d':
             DISPLAY = 1
         if k == '-c':

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


More information about the Python-checkins mailing list