From 19e5b3f9d103d7fd45557b1842d9ea87facf9e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lemburg?= Date: Mon, 13 Jul 2009 20:23:49 +0000 Subject: [PATCH] Use a new global DEV_NULL instead of hard-coding /dev/null into the system command helper functions. See #6479 for some motivation. --- Lib/platform.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Lib/platform.py b/Lib/platform.py index 7a6f339147e..95a3a748151 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -34,6 +34,7 @@ # # # +# 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())