From ec1a498a01da2b4df22413ff778529d84111c2ee Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 11 Sep 2015 12:37:30 +0200 Subject: 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. --- Misc/NEWS | 6 ++++++ Modules/socketmodule.c | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index db250cd..e9fe6c7 100644 --- 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. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index b6f2bf5..23019ee 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -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)); -- cgit v0.12