diff options
author | Mark Hammond <mhammond@skippinet.com.au> | 2002-10-08 02:44:31 (GMT) |
---|---|---|
committer | Mark Hammond <mhammond@skippinet.com.au> | 2002-10-08 02:44:31 (GMT) |
commit | 8696ebcd28d38f74ee0ffa2cd82d9db1c0bad8df (patch) | |
tree | 1d688f1ea3f3b785a19760dd1477b796370c698d | |
parent | 20eae69a9fb5b5453f9ddf01600f99fd6ffffed7 (diff) | |
download | cpython-8696ebcd28d38f74ee0ffa2cd82d9db1c0bad8df.zip cpython-8696ebcd28d38f74ee0ffa2cd82d9db1c0bad8df.tar.gz cpython-8696ebcd28d38f74ee0ffa2cd82d9db1c0bad8df.tar.bz2 |
Add os.path.supports_unicode_filenames for all platforms,
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.
-rw-r--r-- | Doc/lib/libposixpath.tex | 7 | ||||
-rw-r--r-- | Doc/lib/libsys.tex | 26 | ||||
-rw-r--r-- | Lib/dospath.py | 4 | ||||
-rw-r--r-- | Lib/macpath.py | 5 | ||||
-rw-r--r-- | Lib/ntpath.py | 6 | ||||
-rw-r--r-- | Lib/os2emxpath.py | 5 | ||||
-rw-r--r-- | Lib/posixpath.py | 5 | ||||
-rw-r--r-- | Lib/test/output/test_pep277 | 2 | ||||
-rw-r--r-- | Lib/test/test_pep277.py | 9 | ||||
-rw-r--r-- | Misc/NEWS | 6 | ||||
-rw-r--r-- | Python/sysmodule.c | 37 |
11 files changed, 101 insertions, 11 deletions
diff --git a/Doc/lib/libposixpath.tex b/Doc/lib/libposixpath.tex index 7ad19e3..c5f992b 100644 --- a/Doc/lib/libposixpath.tex +++ b/Doc/lib/libposixpath.tex @@ -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 diff --git a/Doc/lib/libsys.tex b/Doc/lib/libsys.tex index eec02e0..3f8f7b6 100644 --- a/Doc/lib/libsys.tex +++ b/Doc/lib/libsys.tex @@ -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 diff --git a/Lib/dospath.py b/Lib/dospath.py index f613a63..345b940 100644 --- a/Lib/dospath.py +++ b/Lib/dospath.py @@ -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 diff --git a/Lib/macpath.py b/Lib/macpath.py index 8546892..f19b4f7 100644 --- a/Lib/macpath.py +++ b/Lib/macpath.py @@ -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 diff --git a/Lib/ntpath.py b/Lib/ntpath.py index d376065..73b7a2f 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -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 diff --git a/Lib/os2emxpath.py b/Lib/os2emxpath.py index a539a82..616d474 100644 --- a/Lib/os2emxpath.py +++ b/Lib/os2emxpath.py @@ -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 diff --git a/Lib/posixpath.py b/Lib/posixpath.py index d5d2621..bf15390 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -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 + diff --git a/Lib/test/output/test_pep277 b/Lib/test/output/test_pep277 index 717b707..43bd9e1 100644 --- a/Lib/test/output/test_pep277 +++ b/Lib/test/output/test_pep277 @@ -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'] diff --git a/Lib/test/test_pep277.py b/Lib/test/test_pep277.py index 480fe00..9c4aa05 100644 --- a/Lib/test/test_pep277.py +++ b/Lib/test/test_pep277.py @@ -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) @@ -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 diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 9057938..751d147 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -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 |