Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec1a498

Browse files
committed
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.
1 parent db4220e commit ec1a498

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ Core and Builtins
8181
Library
8282
-------
8383

84+
- Issue #24684: socket.socket.getaddrinfo() now calls
85+
PyUnicode_AsEncodedString() instead of calling the encode() method of the
86+
host, to handle correctly custom string with an encode() method which doesn't
87+
return a byte string. The encoder of the IDNA codec is now called directly
88+
instead of calling the encode() method of the string.
89+
8490
- Issue #24982: shutil.make_archive() with the "zip" format now adds entries
8591
for directories (including empty directories) in ZIP file.
8692

Modules/socketmodule.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5213,9 +5213,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
52135213
if (hobj == Py_None) {
52145214
hptr = NULL;
52155215
} else if (PyUnicode_Check(hobj)) {
5216-
_Py_IDENTIFIER(encode);
5217-
5218-
idna = _PyObject_CallMethodId(hobj, &PyId_encode, "s", "idna");
5216+
idna = PyUnicode_AsEncodedString(hobj, "idna", NULL);
52195217
if (!idna)
52205218
return NULL;
52215219
assert(PyBytes_Check(idna));

0 commit comments

Comments
 (0)