]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #24684: socket.socket.getaddrinfo() now calls
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 11 Sep 2015 10:42:13 +0000 (12:42 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 11 Sep 2015 10:42:13 +0000 (12:42 +0200)
PyUnicode_AsEncodedString() instead of calling the encode() method of the
host, to handle correctly custom unicode string with an encode() method which
doesn't return a byte string. The encoder of the IDNA codec is now called
directly instead of calling the encode() method of the string.

Misc/NEWS
Modules/socketmodule.c

index e17910854d04d4be9011b000745f951bd8f1be51..f1b5ff951b4f707c8bd33e7001e392108338c5a0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,12 @@ Core and Builtins
 Library
 -------
 
+- Issue #24684: socket.socket.getaddrinfo() now calls
+  PyUnicode_AsEncodedString() instead of calling the encode() method of the
+  host, to handle correctly custom unicode string with an encode() method
+  which doesn't return a byte string. The encoder of the IDNA codec is now
+  called directly instead of calling the encode() method of the string.
+
 - Issue #24982: shutil.make_archive() with the "zip" format now adds entries
   for directories (including empty directories) in ZIP file.
 
index 5def531c4a3918705a772b8eb613129ef677d0f2..ced93433e57a0567db54a92e759dd5a02cc32f02 100644 (file)
@@ -4158,7 +4158,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
     if (hobj == Py_None) {
         hptr = NULL;
     } else if (PyUnicode_Check(hobj)) {
-        idna = PyObject_CallMethod(hobj, "encode", "s", "idna");
+        idna = PyUnicode_AsEncodedString(hobj, "idna", NULL);
         if (!idna)
             return NULL;
         hptr = PyString_AsString(idna);