changeset: 92259:97081a80f487 branch: 2.7 parent: 92256:3ae399c6ecf6 user: Benjamin Peterson date: Thu Aug 28 09:33:21 2014 -0400 files: Lib/test/test_ssl.py Modules/_ssl.c description: fix load_verify_locations on unicode paths (closes #22244) diff -r 3ae399c6ecf6 -r 97081a80f487 Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py Thu Aug 28 00:05:52 2014 -0400 +++ b/Lib/test/test_ssl.py Thu Aug 28 09:33:21 2014 -0400 @@ -850,11 +850,14 @@ ctx.load_verify_locations(cafile=CERTFILE, capath=None) ctx.load_verify_locations(BYTES_CERTFILE) ctx.load_verify_locations(cafile=BYTES_CERTFILE, capath=None) + ctx.load_verify_locations(cafile=BYTES_CERTFILE.decode('utf-8')) self.assertRaises(TypeError, ctx.load_verify_locations) self.assertRaises(TypeError, ctx.load_verify_locations, None, None, None) with self.assertRaises(IOError) as cm: ctx.load_verify_locations(WRONGCERT) self.assertEqual(cm.exception.errno, errno.ENOENT) + with self.assertRaises(IOError): + ctx.load_verify_locations(u'') with self.assertRaisesRegexp(ssl.SSLError, "PEM lib"): ctx.load_verify_locations(BADCERT) ctx.load_verify_locations(CERTFILE, CAPATH) diff -r 3ae399c6ecf6 -r 97081a80f487 Modules/_ssl.c --- a/Modules/_ssl.c Thu Aug 28 00:05:52 2014 -0400 +++ b/Modules/_ssl.c Thu Aug 28 09:33:21 2014 -0400 @@ -2628,17 +2628,33 @@ } if (cafile) { - cafile_bytes = PyString_AsEncodedObject( - cafile, Py_FileSystemDefaultEncoding, "strict"); - if (!cafile_bytes) { - goto error; + if (PyString_Check(cafile)) { + Py_INCREF(cafile); + cafile_bytes = cafile; + } else { + PyObject *u = PyUnicode_FromObject(cafile); + if (!u) + goto error; + cafile_bytes = PyUnicode_AsEncodedString( + u, Py_FileSystemDefaultEncoding, NULL); + Py_DECREF(u); + if (!cafile_bytes) + goto error; } } if (capath) { - capath_bytes = PyString_AsEncodedObject( - capath, Py_FileSystemDefaultEncoding, "strict"); - if (!capath_bytes) { - goto error; + if (PyString_Check(capath)) { + Py_INCREF(capath); + capath_bytes = capath; + } else { + PyObject *u = PyUnicode_FromObject(capath); + if (!u) + goto error; + capath_bytes = PyUnicode_AsEncodedString( + u, Py_FileSystemDefaultEncoding, NULL); + Py_DECREF(u); + if (!capath_bytes) + goto error; } }