Commit fce7fd64 authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #9549: sys.setdefaultencoding() and PyUnicode_SetDefaultEncoding()

are now removed, since their effect was inexistent in 3.x (the default
encoding is hardcoded to utf-8 and cannot be changed).
parent b0fa831d
...@@ -712,18 +712,6 @@ always available. ...@@ -712,18 +712,6 @@ always available.
:func:`setswitchinterval` instead. :func:`setswitchinterval` instead.
.. function:: setdefaultencoding(name)
Set the current default string encoding used by the Unicode implementation. If
*name* does not match any available encoding, :exc:`LookupError` is raised.
This function is only intended to be used by the :mod:`site` module
implementation and, where needed, by :mod:`sitecustomize`. Once used by the
:mod:`site` module, it is removed from the :mod:`sys` module's namespace.
.. Note that :mod:`site` is not imported if the :option:`-S` option is passed
to the interpreter, in which case this function will remain available.
.. function:: setdlopenflags(n) .. function:: setdlopenflags(n)
Set the flags used by the interpreter for :cfunc:`dlopen` calls, such as when Set the flags used by the interpreter for :cfunc:`dlopen` calls, such as when
......
...@@ -212,7 +212,6 @@ typedef PY_UNICODE_TYPE Py_UNICODE; ...@@ -212,7 +212,6 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define PyUnicode_Replace PyUnicodeUCS2_Replace # define PyUnicode_Replace PyUnicodeUCS2_Replace
# define PyUnicode_Resize PyUnicodeUCS2_Resize # define PyUnicode_Resize PyUnicodeUCS2_Resize
# define PyUnicode_RichCompare PyUnicodeUCS2_RichCompare # define PyUnicode_RichCompare PyUnicodeUCS2_RichCompare
# define PyUnicode_SetDefaultEncoding PyUnicodeUCS2_SetDefaultEncoding
# define PyUnicode_Split PyUnicodeUCS2_Split # define PyUnicode_Split PyUnicodeUCS2_Split
# define PyUnicode_Splitlines PyUnicodeUCS2_Splitlines # define PyUnicode_Splitlines PyUnicodeUCS2_Splitlines
# define PyUnicode_Tailmatch PyUnicodeUCS2_Tailmatch # define PyUnicode_Tailmatch PyUnicodeUCS2_Tailmatch
...@@ -295,7 +294,6 @@ typedef PY_UNICODE_TYPE Py_UNICODE; ...@@ -295,7 +294,6 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
# define PyUnicode_Replace PyUnicodeUCS4_Replace # define PyUnicode_Replace PyUnicodeUCS4_Replace
# define PyUnicode_Resize PyUnicodeUCS4_Resize # define PyUnicode_Resize PyUnicodeUCS4_Resize
# define PyUnicode_RichCompare PyUnicodeUCS4_RichCompare # define PyUnicode_RichCompare PyUnicodeUCS4_RichCompare
# define PyUnicode_SetDefaultEncoding PyUnicodeUCS4_SetDefaultEncoding
# define PyUnicode_Split PyUnicodeUCS4_Split # define PyUnicode_Split PyUnicodeUCS4_Split
# define PyUnicode_Splitlines PyUnicodeUCS4_Splitlines # define PyUnicode_Splitlines PyUnicodeUCS4_Splitlines
# define PyUnicode_Tailmatch PyUnicodeUCS4_Tailmatch # define PyUnicode_Tailmatch PyUnicodeUCS4_Tailmatch
...@@ -708,16 +706,6 @@ PyAPI_FUNC(char *) _PyUnicode_AsString(PyObject *unicode); ...@@ -708,16 +706,6 @@ PyAPI_FUNC(char *) _PyUnicode_AsString(PyObject *unicode);
PyAPI_FUNC(const char*) PyUnicode_GetDefaultEncoding(void); PyAPI_FUNC(const char*) PyUnicode_GetDefaultEncoding(void);
/* Sets the currently active default encoding.
Returns 0 on success, -1 in case of an error.
*/
PyAPI_FUNC(int) PyUnicode_SetDefaultEncoding(
const char *encoding /* Encoding name in standard form */
);
/* --- Generic Codecs ----------------------------------------------------- */ /* --- Generic Codecs ----------------------------------------------------- */
/* Create a Unicode object by decoding the encoded string s of the /* Create a Unicode object by decoding the encoded string s of the
......
...@@ -460,25 +460,6 @@ def aliasmbcs(): ...@@ -460,25 +460,6 @@ def aliasmbcs():
encodings._cache[enc] = encodings._unknown encodings._cache[enc] = encodings._unknown
encodings.aliases.aliases[enc] = 'mbcs' encodings.aliases.aliases[enc] = 'mbcs'
def setencoding():
"""Set the string encoding used by the Unicode implementation. The
default is 'ascii', but if you're willing to experiment, you can
change this."""
encoding = "ascii" # Default value set by _PyUnicode_Init()
if 0:
# Enable to support locale aware default string encodings.
import locale
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]
if 0:
# Enable to switch off string to Unicode coercion and implicit
# Unicode to string conversion.
encoding = "undefined"
if encoding != "ascii":
# On Non-Unicode builds this will raise an AttributeError...
sys.setdefaultencoding(encoding) # Needs Python Unicode build !
def execsitecustomize(): def execsitecustomize():
"""Run custom site specific code, if available.""" """Run custom site specific code, if available."""
...@@ -527,15 +508,9 @@ def main(): ...@@ -527,15 +508,9 @@ def main():
setcopyright() setcopyright()
sethelper() sethelper()
aliasmbcs() aliasmbcs()
setencoding()
execsitecustomize() execsitecustomize()
if ENABLE_USER_SITE: if ENABLE_USER_SITE:
execusercustomize() execusercustomize()
# Remove sys.setdefaultencoding() so that users cannot change the
# encoding after initialization. The test for presence is needed when
# this module is run as a script, because this code is executed twice.
if hasattr(sys, "setdefaultencoding"):
del sys.setdefaultencoding
main() main()
......
...@@ -29,10 +29,6 @@ if not os.path.isdir(site.USER_SITE): ...@@ -29,10 +29,6 @@ if not os.path.isdir(site.USER_SITE):
class HelperFunctionsTests(unittest.TestCase): class HelperFunctionsTests(unittest.TestCase):
"""Tests for helper functions. """Tests for helper functions.
The setting of the encoding (set using sys.setdefaultencoding) used by
the Unicode implementation is not tested.
""" """
def setUp(self): def setUp(self):
...@@ -333,10 +329,6 @@ class ImportSideEffectTests(unittest.TestCase): ...@@ -333,10 +329,6 @@ class ImportSideEffectTests(unittest.TestCase):
else: else:
self.fail("did not alias mbcs") self.fail("did not alias mbcs")
def test_setdefaultencoding_removed(self):
# Make sure sys.setdefaultencoding is gone
self.assertTrue(not hasattr(sys, "setdefaultencoding"))
def test_sitecustomize_executed(self): def test_sitecustomize_executed(self):
# If sitecustomize is available, it should have been imported. # If sitecustomize is available, it should have been imported.
if "sitecustomize" not in sys.modules: if "sitecustomize" not in sys.modules:
......
...@@ -12,6 +12,10 @@ What's New in Python 3.2 Alpha 2? ...@@ -12,6 +12,10 @@ What's New in Python 3.2 Alpha 2?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #9549: sys.setdefaultencoding() and PyUnicode_SetDefaultEncoding()
are now removed, since their effect was inexistent in 3.x (the default
encoding is hardcoded to utf-8 and cannot be changed).
- Issue #7415: PyUnicode_FromEncodedObject() now uses the new buffer API - Issue #7415: PyUnicode_FromEncodedObject() now uses the new buffer API
properly. Patch by Stefan Behnel. properly. Patch by Stefan Behnel.
......
...@@ -1326,8 +1326,6 @@ setprofile(func) Sets a profile function for performance profiling. ...@@ -1326,8 +1326,6 @@ setprofile(func) Sets a profile function for performance profiling.
exc_info() traceback return value to a local variable in a exc_info() traceback return value to a local variable in a
function handling an exception will cause a circular function handling an exception will cause a circular
reference. reference.
setdefaultencoding Change default Unicode encoding - defaults to 7-bit ASCII.
(encoding)
getrecursionlimit Retrieve maximum recursion depth. getrecursionlimit Retrieve maximum recursion depth.
() ()
setrecursionlimit Set maximum recursion depth. (Defaults to 1000.) setrecursionlimit Set maximum recursion depth. (Defaults to 1000.)
......
...@@ -1784,17 +1784,6 @@ const char *PyUnicode_GetDefaultEncoding(void) ...@@ -1784,17 +1784,6 @@ const char *PyUnicode_GetDefaultEncoding(void)
return unicode_default_encoding; return unicode_default_encoding;
} }
int PyUnicode_SetDefaultEncoding(const char *encoding)
{
if (strcmp(encoding, unicode_default_encoding) != 0) {
PyErr_Format(PyExc_ValueError,
"Can only set default encoding to %s",
unicode_default_encoding);
return -1;
}
return 0;
}
/* create or adjust a UnicodeDecodeError */ /* create or adjust a UnicodeDecodeError */
static void static void
make_decode_exception(PyObject **exceptionObject, make_decode_exception(PyObject **exceptionObject,
......
...@@ -182,24 +182,6 @@ Return the current default string encoding used by the Unicode \n\ ...@@ -182,24 +182,6 @@ Return the current default string encoding used by the Unicode \n\
implementation." implementation."
); );
static PyObject *
sys_setdefaultencoding(PyObject *self, PyObject *args)
{
char *encoding;
if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding))
return NULL;
if (PyUnicode_SetDefaultEncoding(encoding))
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
PyDoc_STRVAR(setdefaultencoding_doc,
"setdefaultencoding(encoding)\n\
\n\
Set the current default string encoding used by the Unicode implementation."
);
static PyObject * static PyObject *
sys_getfilesystemencoding(PyObject *self) sys_getfilesystemencoding(PyObject *self)
{ {
...@@ -1030,8 +1012,6 @@ static PyMethodDef sys_methods[] = { ...@@ -1030,8 +1012,6 @@ static PyMethodDef sys_methods[] = {
#ifdef USE_MALLOPT #ifdef USE_MALLOPT
{"mdebug", sys_mdebug, METH_VARARGS}, {"mdebug", sys_mdebug, METH_VARARGS},
#endif #endif
{"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS,
setdefaultencoding_doc},
{"setfilesystemencoding", sys_setfilesystemencoding, METH_VARARGS, {"setfilesystemencoding", sys_setfilesystemencoding, METH_VARARGS,
setfilesystemencoding_doc}, setfilesystemencoding_doc},
{"setcheckinterval", sys_setcheckinterval, METH_VARARGS, {"setcheckinterval", sys_setcheckinterval, METH_VARARGS,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment