summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2009-07-13 20:23:49 (GMT)
committerMarc-André Lemburg <mal@egenix.com>2009-07-13 20:23:49 (GMT)
commit19e5b3f9d103d7fd45557b1842d9ea87facf9e15 (patch)
treea8cd3f961be2a0dad14e953c1068923c970e7a2f /Lib
parent9d11fefe1b3dfffc48872df690305e9a7128c897 (diff)
downloadcpython-19e5b3f9d103d7fd45557b1842d9ea87facf9e15.zip
cpython-19e5b3f9d103d7fd45557b1842d9ea87facf9e15.tar.gz
cpython-19e5b3f9d103d7fd45557b1842d9ea87facf9e15.tar.bz2
Use a new global DEV_NULL instead of hard-coding /dev/null into the system
command helper functions. See #6479 for some motivation.
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/platform.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/Lib/platform.py b/Lib/platform.py
index 7a6f339..95a3a74 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -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@lemburg.com
- Copyright (c) 2000-2008, eGenix.com Software GmbH; mailto:info@egenix.com
+ Copyright (c) 2000-2009, eGenix.com Software GmbH; mailto:info@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 @@ __copyright__ = """
"""
-__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 @@ def _syscmd_uname(option,default=''):
# 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 @@ def _syscmd_file(target,default=''):
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())