diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst index faf8a76251..123c8e4e8e 100755 --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -900,13 +900,8 @@ The :mod:`socket` module also offers various network-related services: Convert 16-bit positive integers from network to host byte order. On machines where the host byte order is the same as network byte order, this is a no-op; - otherwise, it performs a 2-byte swap operation. - - .. deprecated:: 3.7 - In case *x* does not fit in 16-bit unsigned integer, but does fit in a - positive C int, it is silently truncated to 16-bit unsigned integer. - This silent truncation feature is deprecated, and will raise an - exception in future versions of Python. + otherwise, it performs a 2-byte swap operation. :exc:`OverflowError` is raised + if *x* does not fit in a 16-bit unsigned integer. .. function:: htonl(x) @@ -920,13 +915,8 @@ The :mod:`socket` module also offers various network-related services: Convert 16-bit positive integers from host to network byte order. On machines where the host byte order is the same as network byte order, this is a no-op; - otherwise, it performs a 2-byte swap operation. - - .. deprecated:: 3.7 - In case *x* does not fit in 16-bit unsigned integer, but does fit in a - positive C int, it is silently truncated to 16-bit unsigned integer. - This silent truncation feature is deprecated, and will raise an - exception in future versions of Python. + otherwise, it performs a 2-byte swap operation. :exc:`OverflowError` is raised + if *x* does not fit in a 16-bit unsigned integer. .. function:: inet_aton(ip_string) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 80638325ba..356f661966 100755 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1121,9 +1121,11 @@ def testNtoHErrors(self): s_good_values = [0, 1, 2, 0xffff] l_good_values = s_good_values + [0xffffffff] l_bad_values = [-1, -2, 1<<32, 1<<1000] - s_bad_values = l_bad_values + [_testcapi.INT_MIN - 1, - _testcapi.INT_MAX + 1] - s_deprecated_values = [1<<16, _testcapi.INT_MAX] + s_bad_values = ( + l_bad_values + + [_testcapi.INT_MIN-1, _testcapi.INT_MAX+1] + + [1 << 16, _testcapi.INT_MAX] + ) for k in s_good_values: socket.ntohs(k) socket.htons(k) @@ -1136,9 +1138,6 @@ def testNtoHErrors(self): for k in l_bad_values: self.assertRaises(OverflowError, socket.ntohl, k) self.assertRaises(OverflowError, socket.htonl, k) - for k in s_deprecated_values: - self.assertWarns(DeprecationWarning, socket.ntohs, k) - self.assertWarns(DeprecationWarning, socket.htons, k) def testGetServBy(self): eq = self.assertEqual diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index d773836702..b414843c5d 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -6102,13 +6102,10 @@ socket_ntohs(PyObject *self, PyObject *args) return NULL; } if (x > 0xffff) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "ntohs: Python int too large to convert to C " - "16-bit unsigned integer (The silent truncation " - "is deprecated)", - 1)) { - return NULL; - } + PyErr_SetString(PyExc_OverflowError, + "ntohs: Python int too large to convert to C " + "16-bit unsigned integer"); + return NULL; } return PyLong_FromUnsignedLong(ntohs((unsigned short)x)); } @@ -6117,11 +6114,8 @@ PyDoc_STRVAR(ntohs_doc, "ntohs(integer) -> integer\n\ \n\ Convert a 16-bit unsigned integer from network to host byte order.\n\ -Note that in case the received integer does not fit in 16-bit unsigned\n\ -integer, but does fit in a positive C int, it is silently truncated to\n\ -16-bit unsigned integer.\n\ -However, this silent truncation feature is deprecated, and will raise an\n\ -exception in future versions of Python."); +An OverflowError is raised if the received integer does not fit in\n\ +a 16-bit unsigned integer, but does fit in a positive C int."); static PyObject * @@ -6173,13 +6167,10 @@ socket_htons(PyObject *self, PyObject *args) return NULL; } if (x > 0xffff) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "htons: Python int too large to convert to C " - "16-bit unsigned integer (The silent truncation " - "is deprecated)", - 1)) { - return NULL; - } + PyErr_SetString(PyExc_OverflowError, + "htons: Python int too large to convert to C " + "16-bit unsigned integer"); + return NULL; } return PyLong_FromUnsignedLong(htons((unsigned short)x)); } @@ -6188,11 +6179,8 @@ PyDoc_STRVAR(htons_doc, "htons(integer) -> integer\n\ \n\ Convert a 16-bit unsigned integer from host to network byte order.\n\ -Note that in case the received integer does not fit in 16-bit unsigned\n\ -integer, but does fit in a positive C int, it is silently truncated to\n\ -16-bit unsigned integer.\n\ -However, this silent truncation feature is deprecated, and will raise an\n\ -exception in future versions of Python."); +An OverflowError is raised if the received integer does not fit in\n\ +a 16-bit unsigned integer, but does fit in a positive C int."); static PyObject *