Patch #449815: Set filesystemencoding based on CODESET.

This commit is contained in:
Martin v. Löwis 2001-09-05 17:09:48 +00:00
parent 044d95e9f7
commit 7c82a3e0fc
3 changed files with 40 additions and 3 deletions

View file

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