[Python-checkins] r74002 - python/trunk/Lib/platform.py

marc-andre.lemburg python-checkins at python.org
Mon Jul 13 22:23:49 CEST 2009


Author: marc-andre.lemburg
Date: Mon Jul 13 22:23:49 2009
New Revision: 74002

Log:
Use a new global DEV_NULL instead of hard-coding /dev/null into the system
command helper functions.

See #6479 for some motivation.



Modified:
   python/trunk/Lib/platform.py

Modified: python/trunk/Lib/platform.py
==============================================================================
--- python/trunk/Lib/platform.py	(original)
+++ python/trunk/Lib/platform.py	Mon Jul 13 22:23:49 2009
@@ -34,6 +34,7 @@
 #
 #    <see CVS and SVN checkin messages for history>
 #
+#    1.0.7 - added DEV_NULL
 #    1.0.6 - added linux_distribution()
 #    1.0.5 - fixed Java support to allow running the module on Jython
 #    1.0.4 - added IronPython support
@@ -91,7 +92,7 @@
 
 __copyright__ = """
     Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal at lemburg.com
-    Copyright (c) 2000-2008, eGenix.com Software GmbH; mailto:info at egenix.com
+    Copyright (c) 2000-2009, eGenix.com Software GmbH; mailto:info at egenix.com
 
     Permission to use, copy, modify, and distribute this software and its
     documentation for any purpose and without fee or royalty is hereby granted,
@@ -110,10 +111,25 @@
 
 """
 
-__version__ = '1.0.6'
+__version__ = '1.0.7'
 
 import sys,string,os,re
 
+### Globals & Constants
+
+# Determine the platform's /dev/null device
+try:
+    DEV_NULL = os.devnull
+except AttributeError:
+    # os.devnull was added in Python 2.4, so emulate it for earlier
+    # Python versions
+    if sys.platform in ('dos','win32','win16','os2'):
+        # Use the old CP/M NUL as device name
+        DEV_NULL = 'NUL'
+    else:
+        # Standard Unix uses /dev/null
+        DEV_NULL = '/dev/null'
+
 ### Platform specific APIs
 
 _libc_search = re.compile(r'(__libc_init)'
@@ -926,7 +942,7 @@
         # XXX Others too ?
         return default
     try:
-        f = os.popen('uname %s 2> /dev/null' % option)
+        f = os.popen('uname %s 2> %s' % (option, DEV_NULL))
     except (AttributeError,os.error):
         return default
     output = string.strip(f.read())
@@ -951,7 +967,7 @@
         return default
     target = _follow_symlinks(target)
     try:
-        f = os.popen('file "%s" 2> /dev/null' % target)
+        f = os.popen('file "%s" 2> %s' % (target, DEV_NULL))
     except (AttributeError,os.error):
         return default
     output = string.strip(f.read())


More information about the Python-checkins mailing list