Revert "bpo-34589: Add -X coerce_c_locale command line option (GH-9378)" (GH-9430)

* Revert "bpo-34589: Add -X coerce_c_locale command line option (GH-9378)"

This reverts commit dbdee0073c.

* Revert "bpo-34589: C locale coercion off by default (GH-9073)"

This reverts commit 7a0791b699.

* Revert "bpo-34589: Make _PyCoreConfig.coerce_c_locale private (GH-9371)"

This reverts commit 188ebfa475.
This commit is contained in:
Victor Stinner 2018-09-19 14:56:36 -07:00 committed by GitHub
parent 76531e2e82
commit 06e7608207
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 87 additions and 242 deletions

View file

@ -303,8 +303,8 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
COPY_ATTR(dump_refs);
COPY_ATTR(malloc_stats);
COPY_ATTR(_coerce_c_locale);
COPY_ATTR(_coerce_c_locale_warn);
COPY_ATTR(coerce_c_locale);
COPY_ATTR(coerce_c_locale_warn);
COPY_ATTR(utf8_mode);
COPY_WSTR_ATTR(pycache_prefix);
@ -705,17 +705,6 @@ config_init_utf8_mode(_PyCoreConfig *config)
return _Py_INIT_OK();
}
#ifndef MS_WINDOWS
/* The C locale and the POSIX locale enable the UTF-8 Mode (PEP 540) */
const char *ctype_loc = setlocale(LC_CTYPE, NULL);
if (ctype_loc != NULL
&& (strcmp(ctype_loc, "C") == 0 || strcmp(ctype_loc, "POSIX") == 0))
{
config->utf8_mode = 1;
return _Py_INIT_OK();
}
#endif
return _Py_INIT_OK();
}
@ -819,6 +808,23 @@ config_read_env_vars(_PyCoreConfig *config)
config->malloc_stats = 1;
}
const char *env = _PyCoreConfig_GetEnv(config, "PYTHONCOERCECLOCALE");
if (env) {
if (strcmp(env, "0") == 0) {
if (config->coerce_c_locale < 0) {
config->coerce_c_locale = 0;
}
}
else if (strcmp(env, "warn") == 0) {
config->coerce_c_locale_warn = 1;
}
else {
if (config->coerce_c_locale < 0) {
config->coerce_c_locale = 1;
}
}
}
wchar_t *path;
int res = _PyCoreConfig_GetEnvDup(config, &path,
L"PYTHONPATH", "PYTHONPATH");
@ -958,76 +964,28 @@ config_read_complex_options(_PyCoreConfig *config)
}
static _PyInitError
config_init_coerce_c_locale(_PyCoreConfig *config)
static void
config_init_locale(_PyCoreConfig *config)
{
const wchar_t *xopt = config_get_xoption(config, L"coerce_c_locale");
if (xopt) {
wchar_t *sep = wcschr(xopt, L'=');
if (sep) {
xopt = sep + 1;
if (wcscmp(xopt, L"1") == 0) {
if (config->_coerce_c_locale < 0) {
config->_coerce_c_locale = 1;
}
}
else if (wcscmp(xopt, L"0") == 0) {
if (config->_coerce_c_locale < 0) {
config->_coerce_c_locale = 0;
}
}
else if (wcscmp(xopt, L"warn") == 0) {
if (config->_coerce_c_locale_warn < 0) {
config->_coerce_c_locale_warn = 1;
}
}
else {
return _Py_INIT_USER_ERR("invalid -X coerce_c_locale option value");
}
}
else {
if (config->_coerce_c_locale < 0) {
config->_coerce_c_locale = 1;
}
}
if (config->_coerce_c_locale_warn < 0) {
config->_coerce_c_locale_warn = 0;
}
}
const char *env = _PyCoreConfig_GetEnv(config, "PYTHONCOERCECLOCALE");
if (env) {
if (strcmp(env, "0") == 0) {
if (config->_coerce_c_locale < 0) {
config->_coerce_c_locale = 0;
}
}
else if (strcmp(env, "warn") == 0) {
if (config->_coerce_c_locale_warn < 0) {
config->_coerce_c_locale_warn = 1;
}
}
else {
if (config->_coerce_c_locale < 0) {
config->_coerce_c_locale = 1;
}
}
if (config->_coerce_c_locale_warn < 0) {
config->_coerce_c_locale_warn = 0;
}
}
if (config->_coerce_c_locale < 0) {
if (config->coerce_c_locale < 0) {
/* The C locale enables the C locale coercion (PEP 538) */
if (_Py_LegacyLocaleDetected()) {
config->_coerce_c_locale = 1;
return _Py_INIT_OK();
config->coerce_c_locale = 1;
}
}
return _Py_INIT_OK();
#ifndef MS_WINDOWS
if (config->utf8_mode < 0) {
/* The C locale and the POSIX locale enable the UTF-8 Mode (PEP 540) */
const char *ctype_loc = setlocale(LC_CTYPE, NULL);
if (ctype_loc != NULL
&& (strcmp(ctype_loc, "C") == 0
|| strcmp(ctype_loc, "POSIX") == 0))
{
config->utf8_mode = 1;
}
}
#endif
}
@ -1333,11 +1291,8 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
}
}
if (config->_coerce_c_locale < 0 || config->_coerce_c_locale_warn < 0) {
err = config_init_coerce_c_locale(config);
if (_Py_INIT_FAILED(err)) {
return err;
}
if (config->utf8_mode < 0 || config->coerce_c_locale < 0) {
config_init_locale(config);
}
if (config->_install_importlib) {
@ -1366,11 +1321,8 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
if (config->tracemalloc < 0) {
config->tracemalloc = 0;
}
if (config->_coerce_c_locale < 0) {
config->_coerce_c_locale = 0;
}
if (config->_coerce_c_locale_warn < 0) {
config->_coerce_c_locale_warn = 0;
if (config->coerce_c_locale < 0) {
config->coerce_c_locale = 0;
}
if (config->utf8_mode < 0) {
config->utf8_mode = 0;
@ -1391,8 +1343,7 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
return err;
}
assert(config->_coerce_c_locale >= 0);
assert(config->_coerce_c_locale_warn >= 0);
assert(config->coerce_c_locale >= 0);
assert(config->use_environment >= 0);
assert(config->filesystem_encoding != NULL);
assert(config->filesystem_errors != NULL);