[Python-checkins] r79394 - in python/branches/release31-maint: Lib/test/test_sys.py Misc/NEWS Python/bltinmodule.c

victor.stinner python-checkins at python.org
Thu Mar 25 01:35:52 CET 2010


Author: victor.stinner
Date: Thu Mar 25 01:35:51 2010
New Revision: 79394

Log:
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.
........


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Lib/test/test_sys.py
   python/branches/release31-maint/Misc/NEWS
   python/branches/release31-maint/Python/bltinmodule.c

Modified: python/branches/release31-maint/Lib/test/test_sys.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_sys.py	(original)
+++ python/branches/release31-maint/Lib/test/test_sys.py	Thu Mar 25 01:35:51 2010
@@ -758,6 +758,7 @@
         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():

Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS	(original)
+++ python/branches/release31-maint/Misc/NEWS	Thu Mar 25 01:35:51 2010
@@ -12,6 +12,9 @@
 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

Modified: python/branches/release31-maint/Python/bltinmodule.c
==============================================================================
--- python/branches/release31-maint/Python/bltinmodule.c	(original)
+++ python/branches/release31-maint/Python/bltinmodule.c	Thu Mar 25 01:35:51 2010
@@ -29,7 +29,7 @@
 int
 _Py_SetFileSystemEncoding(PyObject *s)
 {
-	PyObject *defenc;
+	PyObject *defenc, *codec;
 	if (!PyUnicode_Check(s)) {
 		PyErr_BadInternalCall();
 		return -1;
@@ -37,6 +37,10 @@
 	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);


More information about the Python-checkins mailing list