as the ones of the builtin unicode() Unicode object constructor.
Setting encoding to NULL causes the default encoding to be used which
-is UTF-8.
+is \ASCII{}. The file system calls should use
+\var{Py_FileSystemDefaultEncoding} as the encoding for file
+names. This variable should be treated as read-only: On some systems,
+it will be a pointer to a static string, on others, it will change at
+run-time, e.g. when the application invokes setlocale.
Error handling is set by errors which may also be set to NULL meaning
to use the default handling defined for the codec. Default error
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)
os.chdir(cwd)
os.rmdir(abs_encoded)
print "All the Unicode tests appeared to work"
+if oldlocale:
+ locale.setlocale(locale.LC_CTYPE, oldlocale)
PyDict_SetItemString(string, "letters", ulo);
Py_DECREF(ulo);
}
-
+
+#if defined(HAVE_LANGINFO_H) && defined(CODESET)
+static int fileencoding_uses_locale = 0;
+#endif
static PyObject*
PyLocale_setlocale(PyObject* self, PyObject* args)
fixup_ulcase();
/* things that got wrong up to here are ignored */
PyErr_Clear();
+#if defined(HAVE_LANGINFO_H) && defined(CODESET)
+ if (Py_FileSystemDefaultEncoding == NULL)
+ fileencoding_uses_locale = 1;
+ if (fileencoding_uses_locale) {
+ char *codeset = nl_langinfo(CODESET);
+ PyObject *enc = NULL;
+ if (*codeset && (enc = PyCodec_Encoder(codeset))) {
+ /* Release previous file encoding */
+ if (Py_FileSystemDefaultEncoding)
+ free (Py_FileSystemDefaultEncoding);
+ Py_FileSystemDefaultEncoding = strdup(codeset);
+ Py_DECREF(enc);
+ } else
+ PyErr_Clear();
+ }
+#endif
} else {
/* get locale */
/* restore LC_NUMERIC first, if appropriate */