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.
This commit is contained in:
Mark Hammond 2002-10-08 02:44:31 +00:00
parent 20eae69a9f
commit 8696ebcd28
11 changed files with 101 additions and 11 deletions

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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']

View 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)

View File

@ -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

View 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