diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-03-25 00:35:51 +0000 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-03-25 00:35:51 +0000 |
commit | d8805b2bb8f5e25641153776c6a01c5653417ec9 (patch) | |
tree | 43cabe2b2863ce8cddc2c1707ac75a0e4fac0cf1 | |
parent | 2f927fc61b56ba55548d71070bf73f3bb1d2b86a (diff) | |
download | cpython-git-d8805b2bb8f5e25641153776c6a01c5653417ec9.tar.gz |
Merged revisions 79393 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r79393 | victor.stinner | 2010-03-25 01:30:28 +0100 (jeu., 25 mars 2010) | 3 lines
Issue #8226: sys.setfilesystemencoding() raises a LookupError if the encoding
is unknown.
........
-rw-r--r-- | Lib/test/test_sys.py | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Python/bltinmodule.c | 6 |
3 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index d7b9cd8874..73ef6f553b 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -758,6 +758,7 @@ class SizeofTest(unittest.TestCase): old = sys.getfilesystemencoding() sys.setfilesystemencoding("iso-8859-1") self.assertEqual(sys.getfilesystemencoding(), "iso-8859-1") + self.assertRaises(LookupError, sys.setfilesystemencoding, "xxx") sys.setfilesystemencoding(old) def test_main(): @@ -12,6 +12,9 @@ What's New in Python 3.1.3? Core and Builtins ----------------- +- Issue #8226: sys.setfilesystemencoding() raises a LookupError if the encoding + is unknown + - Issue #1583863: An str subclass can now override the __str__ method Library diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 069d7908c7..10527c1428 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -29,7 +29,7 @@ int Py_HasFileSystemDefaultEncoding = 0; int _Py_SetFileSystemEncoding(PyObject *s) { - PyObject *defenc; + PyObject *defenc, *codec; if (!PyUnicode_Check(s)) { PyErr_BadInternalCall(); return -1; @@ -37,6 +37,10 @@ _Py_SetFileSystemEncoding(PyObject *s) defenc = _PyUnicode_AsDefaultEncodedString(s, NULL); if (!defenc) return -1; + codec = _PyCodec_Lookup(PyBytes_AsString(defenc)); + if (codec == NULL) + return -1; + Py_DECREF(codec); if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) /* A file system encoding was set at run-time */ free((char*)Py_FileSystemDefaultEncoding); |