Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 2 Include/coreconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ typedef struct {
highest priority;
* PYTHONIOENCODING environment variable;
* The UTF-8 Mode uses UTF-8/surrogateescape;
* If Python forces the usage of the ASCII encoding (ex: C locale
or POSIX locale on FreeBSD or HP-UX), use ASCII/surrogateescape;
* locale encoding: ANSI code page on Windows, UTF-8 on Android,
LC_CTYPE locale encoding on other platforms;
* On Windows, "surrogateescape" error handler;
Expand Down
42 changes: 22 additions & 20 deletions 42 Python/coreconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,44 +1164,46 @@ config_init_fs_encoding(_PyCoreConfig *config)
}
}

/* Windows defaults to utf-8/surrogatepass (PEP 529) */
/* Windows defaults to utf-8/surrogatepass (PEP 529).

Note: UTF-8 Mode takes the same code path and the Legacy Windows FS
encoding has the priortiy over UTF-8 Mode. */
if (config->filesystem_encoding == NULL) {
config->filesystem_encoding = _PyMem_RawStrdup("utf-8");
if (config->filesystem_encoding == NULL) {
return _Py_INIT_NO_MEMORY();
}
}

if (config->filesystem_errors == NULL) {
config->filesystem_errors = _PyMem_RawStrdup("surrogatepass");
if (config->filesystem_errors == NULL) {
return _Py_INIT_NO_MEMORY();
}
}
#else
if (config->utf8_mode) {
/* UTF-8 Mode use: utf-8/surrogateescape */
if (config->filesystem_encoding == NULL) {
if (config->filesystem_encoding == NULL) {
if (config->utf8_mode) {
/* UTF-8 Mode use: utf-8/surrogateescape */
config->filesystem_encoding = _PyMem_RawStrdup("utf-8");
if (config->filesystem_encoding == NULL) {
return _Py_INIT_NO_MEMORY();
}
/* errors defaults to surrogateescape above */
}
/* errors defaults to surrogateescape above */
}

if (config->filesystem_encoding == NULL) {
/* macOS and Android use UTF-8, other platforms use
the locale encoding. */
char *locale_encoding;
else if (_Py_GetForceASCII()) {
config->filesystem_encoding = _PyMem_RawStrdup("ascii");
}
else {
/* macOS and Android use UTF-8,
other platforms use the locale encoding. */
#if defined(__APPLE__) || defined(__ANDROID__)
locale_encoding = "UTF-8";
config->filesystem_encoding = _PyMem_RawStrdup("utf-8");
#else
_PyInitError err = get_locale_encoding(&locale_encoding);
if (_Py_INIT_FAILED(err)) {
return err;
}
_PyInitError err = get_locale_encoding(&config->filesystem_encoding);
if (_Py_INIT_FAILED(err)) {
return err;
}
#endif
config->filesystem_encoding = _PyMem_RawStrdup(locale_encoding);
}

if (config->filesystem_encoding == NULL) {
return _Py_INIT_NO_MEMORY();
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.