]> granicus.if.org Git - python/commitdiff
Issue #24684: socket.socket.getaddrinfo() now calls
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 11 Sep 2015 10:37:30 +0000 (12:37 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 11 Sep 2015 10:37:30 +0000 (12:37 +0200)
PyUnicode_AsEncodedString() instead of calling the encode() method of the
host, to handle correctly custom 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 db250cd378bcef13c4bbfe85848f01f580a864be..e9fe6c7c9810d949edd1e4e07f92c21083335ac3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -81,6 +81,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 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 b6f2bf53ab8140167b0aed7ce3a151f887010e00..23019ee9a7af3df79f03d889fb02a47d9be77002 100644 (file)
@@ -5213,9 +5213,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
     if (hobj == Py_None) {
         hptr = NULL;
     } else if (PyUnicode_Check(hobj)) {
-        _Py_IDENTIFIER(encode);
-
-        idna = _PyObject_CallMethodId(hobj, &PyId_encode, "s", "idna");
+        idna = PyUnicode_AsEncodedString(hobj, "idna", NULL);
         if (!idna)
             return NULL;
         assert(PyBytes_Check(idna));