summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-03-25 00:30:28 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-03-25 00:30:28 (GMT)
commit120c21227af4e54ec181da8fce6ae21b414aa2d0 (patch)
treedb310baf83e83a53241bcce9eca19b9d4ed336e8
parentcd4ec0e2734a4f59ba97a79cf54c2c161167b96f (diff)
downloadcpython-120c21227af4e54ec181da8fce6ae21b414aa2d0.zip
cpython-120c21227af4e54ec181da8fce6ae21b414aa2d0.tar.gz
cpython-120c21227af4e54ec181da8fce6ae21b414aa2d0.tar.bz2
Issue #8226: sys.setfilesystemencoding() raises a LookupError if the encoding
is unknown.
-rw-r--r--Lib/test/test_sys.py1
-rw-r--r--Misc/NEWS3
-rw-r--r--Python/bltinmodule.c6
3 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index eb7d1a4..23ec399 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -799,6 +799,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():
diff --git a/Misc/NEWS b/Misc/NEWS
index 0d316a0..8a63a22 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 3.2 Alpha 1?
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
- Issue #8014: Setting a T_UINT or T_PYSSIZET attribute of an object with
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index a928fc4..6b8600b 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);