]> granicus.if.org Git - python/commitdiff
Add os.path.supports_unicode_filenames for all platforms,
authorMark Hammond <mhammond@skippinet.com.au>
Tue, 8 Oct 2002 02:44:31 +0000 (02:44 +0000)
committerMark Hammond <mhammond@skippinet.com.au>
Tue, 8 Oct 2002 02:44:31 +0000 (02:44 +0000)
sys.getwindowsversion() on Windows (new enahanced Tim-proof <wink>
version), and fix test_pep277.py in a few minor ways.
Including doc and NEWS entries.

Doc/lib/libposixpath.tex
Doc/lib/libsys.tex
Lib/dospath.py
Lib/macpath.py
Lib/ntpath.py
Lib/os2emxpath.py
Lib/posixpath.py
Lib/test/output/test_pep277
Lib/test/test_pep277.py
Misc/NEWS
Python/sysmodule.c

index 7ad19e3bacbc2002030ec1180c4a2643280b036f..c5f992b0d37b68ff594b8e92979783031dd4f73d 100644 (file)
@@ -219,6 +219,13 @@ avoid visiting certain parts of the tree.  (The object referred to by
 \var{names} must be modified in place, using \keyword{del} or slice
 assignment.)
 
+\begin{datadesc}{supports_unicode_filenames}
+True if arbitrary Unicode strings can be used as file names (within
+limitations imposed by the file system), and if os.listdir returns
+Unicode strings for a Unicode argument.
+\versionadded{2.3}
+\end{datadesc}
+
 \begin{notice}
 Symbolic links to directories are not treated as subdirectories, and
 that \function{walk()} therefore will not visit them. To visit linked
index eec02e0636aabbe315d0e1ed533e85a0be547fcf..3f8f7b6a777de18de9b08e3aefbf8d7996e9ea81 100644 (file)
@@ -216,6 +216,32 @@ It is always available.
   only.
 \end{funcdesc}
 
+\begin{funcdesc}{getwindowsversion}{}
+  Return a tuple containing five components, describing the Windows 
+  version currently running.  The elements are \var{major}, \var{minor}, 
+  \var{build}, \var{platform}, and \var{text}.  \var{text} contains
+  a string while all other values are integers.
+
+  \var{platform} may be one of the following values:
+  \begin{list}{}{\leftmargin 0.7in \labelwidth 0.65in}
+    \item[0 (\constant{VER_PLATFORM_WIN32s})]
+      Win32s on Windows 3.1.
+    \item[1 (\constant{VER_PLATFORM_WIN32_WINDOWS})] 
+      Windows 95/98/ME
+    \item[2 (\constant{VER_PLATFORM_WIN32_NT})] 
+      Windows NT/2000/XP
+    \item[3 (\constant{VER_PLATFORM_WIN32_CE})] 
+      Windows CE.
+  \end{list}
+  
+  This function wraps the Win32 \function{GetVersionEx()} function;
+  see the Microsoft Documentation for more information about these
+  fields.
+
+  Availability: Windows.
+  \versionadded{2.3}
+\end{funcdesc}
+
 \begin{datadesc}{hexversion}
   The version number encoded as a single integer.  This is guaranteed
   to increase with each version, including proper support for
index f613a633f7d249ed6648e4f735ec75af4a3c2f4e..345b940e4357c5eb466114225e9a500f99aac45f 100644 (file)
@@ -6,7 +6,8 @@ import stat
 __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
            "basename","dirname","commonprefix","getsize","getmtime",
            "getatime","islink","exists","isdir","isfile","ismount",
-           "walk","expanduser","expandvars","normpath","abspath"]
+           "walk","expanduser","expandvars","normpath","abspath",
+           "supports_unicode_filenames"]
 
 def normcase(s):
     """Normalize the case of a pathname.
@@ -336,3 +337,4 @@ def abspath(path):
 
 # realpath is a no-op on systems without islink support
 realpath = abspath
+supports_unicode_filenames = False
index 85468928770fbd97446bbd67274f7575356c8fee..f19b4f7652f50387d733654e020d141b967d3d0c 100644 (file)
@@ -6,7 +6,8 @@ from stat import *
 __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
            "basename","dirname","commonprefix","getsize","getmtime",
            "getatime","islink","exists","isdir","isfile",
-           "walk","expanduser","expandvars","normpath","abspath"]
+           "walk","expanduser","expandvars","normpath","abspath",
+           "supports_unicode_filenames"]
 
 # Normalize the case of a pathname.  Dummy in Posix, but <s>.lower() here.
 
@@ -248,3 +249,5 @@ def realpath(path):
         path = join(path, c)
         path = macfs.ResolveAliasFile(path)[0].as_pathname()
     return path
+
+supports_unicode_filenames = False
index d376065a2376e4dede32c94d6d174850901810cd..73b7a2fdca05300588a267f6a88a7210eaba3baa 100644 (file)
@@ -7,11 +7,13 @@ module as os.path.
 
 import os
 import stat
+import sys
 
 __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
            "basename","dirname","commonprefix","getsize","getmtime",
            "getatime","islink","exists","isdir","isfile","ismount",
-           "walk","expanduser","expandvars","normpath","abspath","splitunc"]
+           "walk","expanduser","expandvars","normpath","abspath","splitunc",
+           "supports_unicode_filenames"]
 
 # Normalize the case of a pathname and map slashes to backslashes.
 # Other normalizations (such as optimizing '../' away) are not done
@@ -476,3 +478,5 @@ def abspath(path):
 
 # realpath is a no-op on systems without islink support
 realpath = abspath
+# Win9x family and earlier have no Unicode filename support.
+supports_unicode_filenames = sys.getwindowsversion()[3] >= 2
index a539a826092fbe9ceb5fd959bf1b1bc24a3d80db..616d474c65c539bf6a3d2a2e304875ccb1a33b7c 100644 (file)
@@ -11,7 +11,8 @@ import stat
 __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
            "basename","dirname","commonprefix","getsize","getmtime",
            "getatime","islink","exists","isdir","isfile","ismount",
-           "walk","expanduser","expandvars","normpath","abspath","splitunc"]
+           "walk","expanduser","expandvars","normpath","abspath","splitunc",
+           "supports_unicode_filenames"]
 
 # Normalize the case of a pathname and map slashes to backslashes.
 # Other normalizations (such as optimizing '../' away) are not done
@@ -400,3 +401,5 @@ def abspath(path):
     if not isabs(path):
         path = join(os.getcwd(), path)
     return normpath(path)
+
+supports_unicode_filenames = False
index d5d2621c54d0dc84f3f93946d70ce31d5aa67e80..bf153906b4769c750b7eb51564cccab69fb5a707 100644 (file)
@@ -17,7 +17,7 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
            "basename","dirname","commonprefix","getsize","getmtime",
            "getatime","islink","exists","isdir","isfile","ismount",
            "walk","expanduser","expandvars","normpath","abspath",
-           "samefile","sameopenfile","samestat"]
+           "samefile","sameopenfile","samestat","supports_unicode_filenames"]
 
 # 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
@@ -409,3 +409,6 @@ symbolic links encountered in the path."""
             return realpath(newpath)
 
     return filename
+
+supports_unicode_filenames = False
+
index 717b707844abe1a9b75cecf222b545d098e3eec7..43bd9e1bbb28fec862541c5e1186723adb335deb 100644 (file)
@@ -1,4 +1,4 @@
 test_pep277
-u'F:\\src\\python-cvs\\Lib\\test\\@test\\Gr\xfc\xdf-\u66e8\u66e9\u66eb\\\xdf-\u66e8\u66e9\u66eb'
+u'\xdf-\u66e8\u66e9\u66eb'
 ['???', '???', '??????', '????????????', '????G\xdf', 'Ge??-sa?', 'Gr\xfc\xdf-Gott', 'abc', 'ascii']
 [u'Gr\xfc\xdf-Gott', u'abc', u'ascii', u'\u0393\u03b5\u03b9\u03ac-\u03c3\u03b1\u03c2', u'\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435', u'\u05d4\u05e9\u05e7\u05e6\u05e5\u05e1', u'\u306b\u307d\u3093', u'\u66e8\u05e9\u3093\u0434\u0393\xdf', u'\u66e8\u66e9\u66eb']
index 480fe0096e16336c159395d991c2fd06946b67dc..9c4aa05251b5069975c7a93188c1e2054040c6f3 100644 (file)
@@ -2,9 +2,7 @@
 # open, os.open, os.stat. os.listdir, os.rename, os.remove, os.mkdir, os.chdir, os.rmdir
 import os, unittest
 from test.test_support import TESTFN, TestSkipped, TestFailed, run_suite
-try:
-    from nt import _getfullpathname
-except ImportError:
+if not os.path.supports_unicode_filenames:
     raise TestSkipped, "test works only on NT+"
 
 filenames = [
@@ -24,7 +22,8 @@ def deltree(dirname):
     # Don't hide legitimate errors:  if one of these suckers exists, it's
     # an error if we can't remove it.
     if os.path.exists(dirname):
-        for fname in os.listdir(dirname):
+        # must pass unicode to os.listdir() so we get back unicode results.
+        for fname in os.listdir(unicode(dirname)):
             os.unlink(os.path.join(dirname, fname))
         os.rmdir(dirname)
 
@@ -99,7 +98,7 @@ class UnicodeFileTests(unittest.TestCase):
         f = open(filename, 'w')
         f.write((filename + '\n').encode("utf-8"))
         f.close()
-        print repr(_getfullpathname(filename))
+        print repr(filename)
         os.remove(filename)
         os.chdir(oldwd)
         os.rmdir(dirname)
index bc990e3b870e078124c6c91c026d056b29b9bccb..7ee918be3762a0caf421dec9c271c9923669f7c8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -67,6 +67,8 @@ Core and builtins
 -----------------
 
 - Unicode file name processing for Windows (PEP 277) is implemented.
+  All platforms now have an os.path.supports_unicode_filenames attribute,
+  which is set to True on Windows NT/2000/XP, and False elsewhere.
 
 - Codec error handling callbacks (PEP 293) are implemented.
   Error handling in unicode.encode or str.decode can now be customized.
@@ -193,6 +195,10 @@ Core and builtins
   reliably) are also interrupted (as generally happens on for Linux/Unix.)
   [SF bugs 231273, 439992 and 581232]
 
+- sys.getwindowsversion() has been added on Windows.  This
+  returns a tuple with information about the version of Windows
+  currently running.
+
 - Slices and repetitions of buffer objects now consistently return
   a string.  Formerly, strings would be returned most of the time,
   but a buffer object would be returned when the repetition count
index 9057938ddeda9affdbca692072c402a6e877d0d2..751d14758336cc809bb9cb3a5904a079ce76d978 100644 (file)
@@ -20,6 +20,11 @@ Data members:
 
 #include "osdefs.h"
 
+#ifdef MS_WINDOWS
+#define WIN32_LEAN_AND_MEAN
+#include "windows.h"
+#endif /* MS_WINDOWS */
+
 #ifdef MS_COREDLL
 extern void *PyWin_DLLhModule;
 /* A string loaded from the DLL at startup: */
@@ -404,6 +409,34 @@ of the Python interpreter stack.  This limit prevents infinite\n\
 recursion from causing an overflow of the C stack and crashing Python."
 );
 
+#ifdef MS_WINDOWS
+PyDoc_STRVAR(getwindowsversion_doc,
+"getwindowsversion()\n\
+\n\
+Return information about the running version of Windows.\n\
+The result is a tuple of (major, minor, build, platform, text)\n\
+All elements are numbers, except text which is a string.\n\
+Platform may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP\n\
+"
+);
+
+static PyObject *
+sys_getwindowsversion(PyObject *self)
+{
+       OSVERSIONINFO ver;
+       ver.dwOSVersionInfoSize = sizeof(ver);
+       if (!GetVersionEx(&ver))
+               return PyErr_SetFromWindowsErr(0);
+       return Py_BuildValue("HHHHs",
+                            ver.dwMajorVersion,
+                            ver.dwMinorVersion,
+                            ver.dwBuildNumber,
+                            ver.dwPlatformId,
+                            ver.szCSDVersion);
+}
+
+#endif /* MS_WINDOWS */
+
 #ifdef HAVE_DLOPEN
 static PyObject *
 sys_setdlopenflags(PyObject *self, PyObject *args)
@@ -570,6 +603,10 @@ static PyMethodDef sys_methods[] = {
        {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS,
         getrecursionlimit_doc},
        {"_getframe", sys_getframe, METH_VARARGS, getframe_doc},
+#ifdef MS_WINDOWS
+       {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS,
+        getwindowsversion_doc},
+#endif /* MS_WINDOWS */
 #ifdef USE_MALLOPT
        {"mdebug",      sys_mdebug, METH_VARARGS},
 #endif