mirror of https://github.com/python/cpython
#8853: Allow port to be of type long for socket.getaddrinfo()
This commit is contained in:
parent
92014420d7
commit
ab7dd183f3
|
@ -644,9 +644,10 @@ class GeneralModuleTests(unittest.TestCase):
|
|||
if SUPPORTS_IPV6:
|
||||
socket.getaddrinfo('::1', 80)
|
||||
# port can be a string service name such as "http", a numeric
|
||||
# port number or None
|
||||
# port number (int or long), or None
|
||||
socket.getaddrinfo(HOST, "http")
|
||||
socket.getaddrinfo(HOST, 80)
|
||||
socket.getaddrinfo(HOST, 80L)
|
||||
socket.getaddrinfo(HOST, None)
|
||||
# test family and socktype filters
|
||||
infos = socket.getaddrinfo(HOST, None, socket.AF_INET)
|
||||
|
|
|
@ -160,6 +160,8 @@ Core and Builtins
|
|||
Library
|
||||
-------
|
||||
|
||||
- Issue #8853: Allow port to be of type long for socket.getaddrinfo().
|
||||
|
||||
- Issue #16597: In buffered and text IO, call close() on the underlying stream
|
||||
if invoking flush() fails.
|
||||
|
||||
|
|
|
@ -4090,15 +4090,19 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
|
|||
"getaddrinfo() argument 1 must be string or None");
|
||||
return NULL;
|
||||
}
|
||||
if (PyInt_Check(pobj)) {
|
||||
PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj));
|
||||
if (PyInt_Check(pobj) || PyLong_Check(pobj)) {
|
||||
long value = PyLong_AsLong(pobj);
|
||||
if (value == -1 && PyErr_Occurred())
|
||||
return NULL;
|
||||
PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", value);
|
||||
pptr = pbuf;
|
||||
} else if (PyString_Check(pobj)) {
|
||||
pptr = PyString_AsString(pobj);
|
||||
} else if (pobj == Py_None) {
|
||||
pptr = (char *)NULL;
|
||||
} else {
|
||||
PyErr_SetString(socket_error, "Int or String expected");
|
||||
PyErr_SetString(socket_error,
|
||||
"getaddrinfo() argument 2 must be integer or string");
|
||||
goto err;
|
||||
}
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
|
|
Loading…
Reference in New Issue