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

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


https://hg.python.org/cpython/rev/0c13674cf8b5
changeset:   97914:0c13674cf8b5
branch:      2.7
parent:      97902:77784422da4d
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Sep 11 12:42:13 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 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.

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


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

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


More information about the Python-checkins mailing list