mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
Patch #449815: Set filesystemencoding based on CODESET.
This commit is contained in:
parent
044d95e9f7
commit
7c82a3e0fc
3 changed files with 40 additions and 3 deletions
|
|
@ -6,8 +6,20 @@ import os
|
|||
from test_support import verify, TestSkipped, TESTFN_UNICODE
|
||||
try:
|
||||
from test_support import TESTFN_ENCODING
|
||||
oldlocale = None
|
||||
except ImportError:
|
||||
raise TestSkipped("No Unicode filesystem semantics on this platform.")
|
||||
import locale
|
||||
# try to run the test in an UTF-8 locale. If this locale is not
|
||||
# available, avoid running the test since the locale's encoding
|
||||
# might not support TESTFN_UNICODE. Likewise, if the system does
|
||||
# not support locale.CODESET, Unicode file semantics is not
|
||||
# available, either.
|
||||
oldlocale = locale.setlocale(locale.LC_CTYPE)
|
||||
try:
|
||||
locale.setlocale(locale.LC_CTYPE,"en_US.UTF-8")
|
||||
TESTFN_ENCODING = locale.nl_langinfo(locale.CODESET)
|
||||
except (locale.Error, AttributeError):
|
||||
raise TestSkipped("No Unicode filesystem semantics on this platform.")
|
||||
|
||||
TESTFN_ENCODED = TESTFN_UNICODE.encode(TESTFN_ENCODING)
|
||||
|
||||
|
|
@ -79,3 +91,5 @@ finally:
|
|||
os.chdir(cwd)
|
||||
os.rmdir(abs_encoded)
|
||||
print "All the Unicode tests appeared to work"
|
||||
if oldlocale:
|
||||
locale.setlocale(locale.LC_CTYPE, oldlocale)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue