mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
Issue #8226: sys.setfilesystemencoding() raises a LookupError if the encoding
is unknown.
This commit is contained in:
parent
cd4ec0e273
commit
120c21227a
3 changed files with 9 additions and 1 deletions
|
@ -799,6 +799,7 @@ class SizeofTest(unittest.TestCase):
|
||||||
old = sys.getfilesystemencoding()
|
old = sys.getfilesystemencoding()
|
||||||
sys.setfilesystemencoding("iso-8859-1")
|
sys.setfilesystemencoding("iso-8859-1")
|
||||||
self.assertEqual(sys.getfilesystemencoding(), "iso-8859-1")
|
self.assertEqual(sys.getfilesystemencoding(), "iso-8859-1")
|
||||||
|
self.assertRaises(LookupError, sys.setfilesystemencoding, "xxx")
|
||||||
sys.setfilesystemencoding(old)
|
sys.setfilesystemencoding(old)
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
|
@ -12,6 +12,9 @@ What's New in Python 3.2 Alpha 1?
|
||||||
Core and Builtins
|
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 #1583863: An str subclass can now override the __str__ method
|
||||||
|
|
||||||
- Issue #8014: Setting a T_UINT or T_PYSSIZET attribute of an object with
|
- Issue #8014: Setting a T_UINT or T_PYSSIZET attribute of an object with
|
||||||
|
|
|
@ -29,7 +29,7 @@ int Py_HasFileSystemDefaultEncoding = 0;
|
||||||
int
|
int
|
||||||
_Py_SetFileSystemEncoding(PyObject *s)
|
_Py_SetFileSystemEncoding(PyObject *s)
|
||||||
{
|
{
|
||||||
PyObject *defenc;
|
PyObject *defenc, *codec;
|
||||||
if (!PyUnicode_Check(s)) {
|
if (!PyUnicode_Check(s)) {
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -37,6 +37,10 @@ _Py_SetFileSystemEncoding(PyObject *s)
|
||||||
defenc = _PyUnicode_AsDefaultEncodedString(s, NULL);
|
defenc = _PyUnicode_AsDefaultEncodedString(s, NULL);
|
||||||
if (!defenc)
|
if (!defenc)
|
||||||
return -1;
|
return -1;
|
||||||
|
codec = _PyCodec_Lookup(PyBytes_AsString(defenc));
|
||||||
|
if (codec == NULL)
|
||||||
|
return -1;
|
||||||
|
Py_DECREF(codec);
|
||||||
if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding)
|
if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding)
|
||||||
/* A file system encoding was set at run-time */
|
/* A file system encoding was set at run-time */
|
||||||
free((char*)Py_FileSystemDefaultEncoding);
|
free((char*)Py_FileSystemDefaultEncoding);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue