Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8696ebc

Browse files
committed
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.
1 parent 20eae69 commit 8696ebc

11 files changed

Lines changed: 101 additions & 11 deletions

File tree

Doc/lib/libposixpath.tex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ \section{\module{os.path} ---
219219
\var{names} must be modified in place, using \keyword{del} or slice
220220
assignment.)
221221

222+
\begin{datadesc}{supports_unicode_filenames}
223+
True if arbitrary Unicode strings can be used as file names (within
224+
limitations imposed by the file system), and if os.listdir returns
225+
Unicode strings for a Unicode argument.
226+
\versionadded{2.3}
227+
\end{datadesc}
228+
222229
\begin{notice}
223230
Symbolic links to directories are not treated as subdirectories, and
224231
that \function{walk()} therefore will not visit them. To visit linked

Doc/lib/libsys.tex

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,32 @@ \section{\module{sys} ---
216216
only.
217217
\end{funcdesc}
218218

219+
\begin{funcdesc}{getwindowsversion}{}
220+
Return a tuple containing five components, describing the Windows
221+
version currently running. The elements are \var{major}, \var{minor},
222+
\var{build}, \var{platform}, and \var{text}. \var{text} contains
223+
a string while all other values are integers.
224+
225+
\var{platform} may be one of the following values:
226+
\begin{list}{}{\leftmargin 0.7in \labelwidth 0.65in}
227+
\item[0 (\constant{VER_PLATFORM_WIN32s})]
228+
Win32s on Windows 3.1.
229+
\item[1 (\constant{VER_PLATFORM_WIN32_WINDOWS})]
230+
Windows 95/98/ME
231+
\item[2 (\constant{VER_PLATFORM_WIN32_NT})]
232+
Windows NT/2000/XP
233+
\item[3 (\constant{VER_PLATFORM_WIN32_CE})]
234+
Windows CE.
235+
\end{list}
236+
237+
This function wraps the Win32 \function{GetVersionEx()} function;
238+
see the Microsoft Documentation for more information about these
239+
fields.
240+
241+
Availability: Windows.
242+
\versionadded{2.3}
243+
\end{funcdesc}
244+
219245
\begin{datadesc}{hexversion}
220246
The version number encoded as a single integer. This is guaranteed
221247
to increase with each version, including proper support for

Lib/dospath.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
77
"basename","dirname","commonprefix","getsize","getmtime",
88
"getatime","islink","exists","isdir","isfile","ismount",
9-
"walk","expanduser","expandvars","normpath","abspath"]
9+
"walk","expanduser","expandvars","normpath","abspath",
10+
"supports_unicode_filenames"]
1011

1112
def normcase(s):
1213
"""Normalize the case of a pathname.
@@ -336,3 +337,4 @@ def abspath(path):
336337

337338
# realpath is a no-op on systems without islink support
338339
realpath = abspath
340+
supports_unicode_filenames = False

Lib/macpath.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
77
"basename","dirname","commonprefix","getsize","getmtime",
88
"getatime","islink","exists","isdir","isfile",
9-
"walk","expanduser","expandvars","normpath","abspath"]
9+
"walk","expanduser","expandvars","normpath","abspath",
10+
"supports_unicode_filenames"]
1011

1112
# Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.
1213

@@ -248,3 +249,5 @@ def realpath(path):
248249
path = join(path, c)
249250
path = macfs.ResolveAliasFile(path)[0].as_pathname()
250251
return path
252+
253+
supports_unicode_filenames = False

Lib/ntpath.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
import os
99
import stat
10+
import sys
1011

1112
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
1213
"basename","dirname","commonprefix","getsize","getmtime",
1314
"getatime","islink","exists","isdir","isfile","ismount",
14-
"walk","expanduser","expandvars","normpath","abspath","splitunc"]
15+
"walk","expanduser","expandvars","normpath","abspath","splitunc",
16+
"supports_unicode_filenames"]
1517

1618
# Normalize the case of a pathname and map slashes to backslashes.
1719
# Other normalizations (such as optimizing '../' away) are not done
@@ -476,3 +478,5 @@ def _abspath(path):
476478

477479
# realpath is a no-op on systems without islink support
478480
realpath = abspath
481+
# Win9x family and earlier have no Unicode filename support.
482+
supports_unicode_filenames = sys.getwindowsversion()[3] >= 2

Lib/os2emxpath.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
1212
"basename","dirname","commonprefix","getsize","getmtime",
1313
"getatime","islink","exists","isdir","isfile","ismount",
14-
"walk","expanduser","expandvars","normpath","abspath","splitunc"]
14+
"walk","expanduser","expandvars","normpath","abspath","splitunc",
15+
"supports_unicode_filenames"]
1516

1617
# Normalize the case of a pathname and map slashes to backslashes.
1718
# Other normalizations (such as optimizing '../' away) are not done
@@ -400,3 +401,5 @@ def abspath(path):
400401
if not isabs(path):
401402
path = join(os.getcwd(), path)
402403
return normpath(path)
404+
405+
supports_unicode_filenames = False

Lib/posixpath.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"basename","dirname","commonprefix","getsize","getmtime",
1818
"getatime","islink","exists","isdir","isfile","ismount",
1919
"walk","expanduser","expandvars","normpath","abspath",
20-
"samefile","sameopenfile","samestat"]
20+
"samefile","sameopenfile","samestat","supports_unicode_filenames"]
2121

2222
# Normalize the case of a pathname. Trivial in Posix, string.lower on Mac.
2323
# On MS-DOS this may also turn slashes into backslashes; however, other
@@ -409,3 +409,6 @@ def realpath(filename):
409409
return realpath(newpath)
410410

411411
return filename
412+
413+
supports_unicode_filenames = False
414+

Lib/test/output/test_pep277

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
test_pep277
2-
u'F:\\src\\python-cvs\\Lib\\test\\@test\\Gr\xfc\xdf-\u66e8\u66e9\u66eb\\\xdf-\u66e8\u66e9\u66eb'
2+
u'\xdf-\u66e8\u66e9\u66eb'
33
['???', '???', '??????', '????????????', '????G\xdf', 'Ge??-sa?', 'Gr\xfc\xdf-Gott', 'abc', 'ascii']
44
[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']

Lib/test/test_pep277.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# open, os.open, os.stat. os.listdir, os.rename, os.remove, os.mkdir, os.chdir, os.rmdir
33
import os, unittest
44
from test.test_support import TESTFN, TestSkipped, TestFailed, run_suite
5-
try:
6-
from nt import _getfullpathname
7-
except ImportError:
5+
if not os.path.supports_unicode_filenames:
86
raise TestSkipped, "test works only on NT+"
97

108
filenames = [
@@ -24,7 +22,8 @@ def deltree(dirname):
2422
# Don't hide legitimate errors: if one of these suckers exists, it's
2523
# an error if we can't remove it.
2624
if os.path.exists(dirname):
27-
for fname in os.listdir(dirname):
25+
# must pass unicode to os.listdir() so we get back unicode results.
26+
for fname in os.listdir(unicode(dirname)):
2827
os.unlink(os.path.join(dirname, fname))
2928
os.rmdir(dirname)
3029

@@ -99,7 +98,7 @@ def test_directory(self):
9998
f = open(filename, 'w')
10099
f.write((filename + '\n').encode("utf-8"))
101100
f.close()
102-
print repr(_getfullpathname(filename))
101+
print repr(filename)
103102
os.remove(filename)
104103
os.chdir(oldwd)
105104
os.rmdir(dirname)

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Core and builtins
6767
-----------------
6868

6969
- Unicode file name processing for Windows (PEP 277) is implemented.
70+
All platforms now have an os.path.supports_unicode_filenames attribute,
71+
which is set to True on Windows NT/2000/XP, and False elsewhere.
7072

7173
- Codec error handling callbacks (PEP 293) are implemented.
7274
Error handling in unicode.encode or str.decode can now be customized.
@@ -193,6 +195,10 @@ Core and builtins
193195
reliably) are also interrupted (as generally happens on for Linux/Unix.)
194196
[SF bugs 231273, 439992 and 581232]
195197

198+
- sys.getwindowsversion() has been added on Windows. This
199+
returns a tuple with information about the version of Windows
200+
currently running.
201+
196202
- Slices and repetitions of buffer objects now consistently return
197203
a string. Formerly, strings would be returned most of the time,
198204
but a buffer object would be returned when the repetition count

0 commit comments

Comments
 (0)