]> granicus.if.org Git - python/commitdiff
Feature request #935915: Add os.path.devnull.
authorMartin v. Löwis <martin@v.loewis.de>
Tue, 8 Jun 2004 08:29:33 +0000 (08:29 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Tue, 8 Jun 2004 08:29:33 +0000 (08:29 +0000)
Doc/lib/libos.tex
Lib/macpath.py
Lib/ntpath.py
Lib/os.py
Lib/os2emxpath.py
Lib/posixpath.py
Lib/test/test_os.py
Misc/NEWS

index 7fc7fabe6b6d15efcc1b7a55ccc65a420a3a33c1..73630e89f18ce8dedad6244b0d91e6b55afba6ae 100644 (file)
@@ -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}
index 695fac913289d77fe93aa9bb43b88e63fc776cd9..1d3fa5644819a254e5196909861db008b09340f7 100644 (file)
@@ -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.
 
index 687d88513e2051dab276bb4fe3f1b7d83c7b85dd..549c35ea696b9ff426f2ab1782c629be891dc2b8 100644 (file)
@@ -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
index c037ea90c4f93e21754bb62fefc833efbfddaf1b..5b79981dffe525be4f6dd03e2eed8cd6f21dbbf3 100644 (file)
--- 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
 
index 09982aadc1656a77dd3f9da44f1b26720de93f1c..9f8a1dd12c6c6783f23e65e31e7bc1384e190cc4 100644 (file)
@@ -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
index dcd5a638c045bc4e5c5e7b8633ebc2946c6902b6..c117c89934074c9e59e40f4d07edee99ed1b85f9 100644 (file)
@@ -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
index 4cdc29db720732547e63ec731702c865901cea67..b05bffc438d07902272dcefa8d2c1ca4391f0eb9 100644 (file)
@@ -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__":
index a07d887d18dbccfb6aa166a8ca13a6b9f5b65a85..b7cf4b40b526939aee73588c1fcb93e786adb197 100644 (file)
--- 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.