[Python-checkins] cpython (3.4): Issue #24684: socket.socket.getaddrinfo() now calls

victor.stinner python-checkins at python.org
Fri Sep 11 12:43:07 CEST 2015


https://hg.python.org/cpython/rev/2bff115e6ba0
changeset:   97911:2bff115e6ba0
branch:      3.4
parent:      97901:0ca216f5276e
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Sep 11 12:37:30 2015 +0200
summary:
  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.

files:
  Misc/NEWS              |  6 ++++++
  Modules/socketmodule.c |  4 +---
  2 files changed, 7 insertions(+), 3 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -81,6 +81,12 @@
 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.
 
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -5213,9 +5213,7 @@
     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));

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list