summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2004-06-08 08:29:33 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2004-06-08 08:29:33 (GMT)
commitbdec50f0277971830e307aff8090c1494a69f4ce (patch)
tree19ae2f89e1b093efd1062a997d9139c781b9d9a9
parentf30d60edbc0d5047a2fdd01e25868e4b814107e2 (diff)
downloadcpython-bdec50f0277971830e307aff8090c1494a69f4ce.zip
cpython-bdec50f0277971830e307aff8090c1494a69f4ce.tar.gz
cpython-bdec50f0277971830e307aff8090c1494a69f4ce.tar.bz2
Feature request #935915: Add os.path.devnull.
-rw-r--r--Doc/lib/libos.tex8
-rw-r--r--Lib/macpath.py3
-rw-r--r--Lib/ntpath.py3
-rw-r--r--Lib/os.py6
-rw-r--r--Lib/os2emxpath.py3
-rw-r--r--Lib/posixpath.py3
-rw-r--r--Lib/test/test_os.py9
-rw-r--r--Misc/NEWS2
8 files changed, 31 insertions, 6 deletions
diff --git a/Doc/lib/libos.tex b/Doc/lib/libos.tex
index 7fc7fabe..73630e8 100644
--- a/Doc/lib/libos.tex
+++ b/Doc/lib/libos.tex
@@ -1808,3 +1808,11 @@ current platform. This may be a single character, such as \code{'\e
n'} for \POSIX{} or \code{'\e r'} for Mac OS, or multiple characters,
for example, \code{'\e r\e n'} for Windows.
\end{datadesc}
+
+\begin{datadesc}{devnull}
+The file path of the null device.
+For example: \code{'/dev/null'} for \POSIX{} or \code{'Dev:Nul'} for the
+Macintosh.
+Also available via \module{os.path}.
+\versionadded{2.4}
+\end{datadesc}
diff --git a/Lib/macpath.py b/Lib/macpath.py
index 695fac9..1d3fa56 100644
--- a/Lib/macpath.py
+++ b/Lib/macpath.py
@@ -8,7 +8,7 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"getatime","getctime", "islink","exists","isdir","isfile",
"walk","expanduser","expandvars","normpath","abspath",
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
- "realpath","supports_unicode_filenames"]
+ "devnull","realpath","supports_unicode_filenames"]
# strings representing various path-related bits and pieces
curdir = ':'
@@ -18,6 +18,7 @@ sep = ':'
pathsep = '\n'
defpath = ':'
altsep = None
+devnull = 'Dev:Null'
# Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index 687d885..549c35e 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -14,7 +14,7 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"getatime","getctime", "islink","exists","isdir","isfile","ismount",
"walk","expanduser","expandvars","normpath","abspath","splitunc",
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
- "realpath","supports_unicode_filenames"]
+ "devnull","realpath","supports_unicode_filenames"]
# strings representing various path-related bits and pieces
curdir = '.'
@@ -29,6 +29,7 @@ if 'ce' in sys.builtin_module_names:
elif 'os2' in sys.builtin_module_names:
# OS/2 w/ VACPP
altsep = '/'
+devnull = 'nul'
# Normalize the case of a pathname and map slashes to backslashes.
# Other normalizations (such as optimizing '../' away) are not done
diff --git a/Lib/os.py b/Lib/os.py
index c037ea9..5b79981 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -12,6 +12,7 @@ This exports:
- os.pathsep is the component separator used in $PATH etc
- os.linesep is the line separator in text files ('\r' or '\n' or '\r\n')
- os.defpath is the default search path for executables
+ - os.devnull is the file path of the null device ('/dev/null', etc.)
Programs that import and use 'os' stand a better chance of being
portable between different platforms. Of course, they must then
@@ -28,7 +29,7 @@ _names = sys.builtin_module_names
# Note: more names are added to __all__ later.
__all__ = ["altsep", "curdir", "pardir", "sep", "pathsep", "linesep",
- "defpath", "name", "path"]
+ "defpath", "name", "path", "devnull"]
def _get_exports_list(module):
try:
@@ -129,7 +130,8 @@ else:
raise ImportError, 'no os specific module found'
sys.modules['os.path'] = path
-from os.path import curdir, pardir, sep, pathsep, defpath, extsep, altsep
+from os.path import curdir, pardir, sep, pathsep, defpath, extsep, altsep, \
+ devnull
del _names
diff --git a/Lib/os2emxpath.py b/Lib/os2emxpath.py
index 09982aa..9f8a1dd 100644
--- a/Lib/os2emxpath.py
+++ b/Lib/os2emxpath.py
@@ -13,7 +13,7 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"getatime","getctime", "islink","exists","isdir","isfile","ismount",
"walk","expanduser","expandvars","normpath","abspath","splitunc",
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
- "realpath","supports_unicode_filenames"]
+ "devnull","realpath","supports_unicode_filenames"]
# strings representing various path-related bits and pieces
curdir = '.'
@@ -23,6 +23,7 @@ sep = '/'
altsep = '\\'
pathsep = ';'
defpath = '.;C:\\bin'
+devnull = 'nul'
# Normalize the case of a pathname and map slashes to backslashes.
# Other normalizations (such as optimizing '../' away) are not done
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index dcd5a63..c117c89 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -19,7 +19,7 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"walk","expanduser","expandvars","normpath","abspath",
"samefile","sameopenfile","samestat",
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
- "realpath","supports_unicode_filenames"]
+ "devnull","realpath","supports_unicode_filenames"]
# strings representing various path-related bits and pieces
curdir = '.'
@@ -29,6 +29,7 @@ sep = '/'
pathsep = ':'
defpath = ':/bin:/usr/bin'
altsep = None
+devnull = '/dev/null'
# Normalize the case of a pathname. Trivial in Posix, string.lower on Mac.
# On MS-DOS this may also turn slashes into backslashes; however, other
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 4cdc29d..b05bffc 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -334,6 +334,14 @@ class MakedirTests (unittest.TestCase):
os.removedirs(path)
+class DevNullTests (unittest.TestCase):
+ def test_devnull(self):
+ f = file(os.devnull, 'w')
+ f.write('hello')
+ f.close()
+ f = file(os.devnull, 'r')
+ assert f.read() == ''
+ f.close()
def test_main():
test_support.run_unittest(
@@ -342,6 +350,7 @@ def test_main():
EnvironTests,
WalkTests,
MakedirTests,
+ DevNullTests,
)
if __name__ == "__main__":
diff --git a/Misc/NEWS b/Misc/NEWS
index a07d887..b7cf4b4 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -328,6 +328,8 @@ Extension modules
Library
-------
+- os.path.devnull has been added for all supported platforms.
+
- Fixed #877165: distutils now picks the right C++ compiler command
on cygwin and mingw32.