Compare commits
No commits in common. "f4936ad1c4d0ae1948e428aeddc7d3096252dae4" and "f421bfce80730cb0ff5cbe14727ac30cf0462eed" have entirely different histories.
f4936ad1c4
...
f421bfce80
|
@ -907,9 +907,11 @@ The :mod:`socket` module also offers various network-related services:
|
||||||
where the host byte order is the same as network byte order, this is a no-op;
|
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.
|
otherwise, it performs a 2-byte swap operation.
|
||||||
|
|
||||||
.. versionchanged:: 3.10
|
.. deprecated:: 3.7
|
||||||
Raises :exc:`OverflowError` if *x* does not fit in a 16-bit unsigned
|
In case *x* does not fit in 16-bit unsigned integer, but does fit in a
|
||||||
integer.
|
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.
|
||||||
|
|
||||||
|
|
||||||
.. function:: htonl(x)
|
.. function:: htonl(x)
|
||||||
|
@ -925,9 +927,11 @@ The :mod:`socket` module also offers various network-related services:
|
||||||
where the host byte order is the same as network byte order, this is a no-op;
|
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.
|
otherwise, it performs a 2-byte swap operation.
|
||||||
|
|
||||||
.. versionchanged:: 3.10
|
.. deprecated:: 3.7
|
||||||
Raises :exc:`OverflowError` if *x* does not fit in a 16-bit unsigned
|
In case *x* does not fit in 16-bit unsigned integer, but does fit in a
|
||||||
integer.
|
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.
|
||||||
|
|
||||||
|
|
||||||
.. function:: inet_aton(ip_string)
|
.. function:: inet_aton(ip_string)
|
||||||
|
|
|
@ -537,12 +537,6 @@ Changes in the Python API
|
||||||
silently in Python 3.9.
|
silently in Python 3.9.
|
||||||
(Contributed by Ken Jin in :issue:`42195`.)
|
(Contributed by Ken Jin in :issue:`42195`.)
|
||||||
|
|
||||||
* :meth:`socket.htons` and :meth:`socket.ntohs` now raise :exc:`OverflowError`
|
|
||||||
instead of :exc:`DeprecationWarning` if the given parameter will not fit in
|
|
||||||
a 16-bit unsigned integer.
|
|
||||||
(Contributed by Erlend E. Aasland in :issue:`42393`.)
|
|
||||||
|
|
||||||
|
|
||||||
CPython bytecode changes
|
CPython bytecode changes
|
||||||
========================
|
========================
|
||||||
|
|
||||||
|
|
|
@ -344,7 +344,7 @@ def a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False):
|
||||||
global _a85chars, _a85chars2
|
global _a85chars, _a85chars2
|
||||||
# Delay the initialization of tables to not waste memory
|
# Delay the initialization of tables to not waste memory
|
||||||
# if the function is never called
|
# if the function is never called
|
||||||
if _a85chars2 is None:
|
if _a85chars is None:
|
||||||
_a85chars = [bytes((i,)) for i in range(33, 118)]
|
_a85chars = [bytes((i,)) for i in range(33, 118)]
|
||||||
_a85chars2 = [(a + b) for a in _a85chars for b in _a85chars]
|
_a85chars2 = [(a + b) for a in _a85chars for b in _a85chars]
|
||||||
|
|
||||||
|
@ -452,7 +452,7 @@ def b85encode(b, pad=False):
|
||||||
global _b85chars, _b85chars2
|
global _b85chars, _b85chars2
|
||||||
# Delay the initialization of tables to not waste memory
|
# Delay the initialization of tables to not waste memory
|
||||||
# if the function is never called
|
# if the function is never called
|
||||||
if _b85chars2 is None:
|
if _b85chars is None:
|
||||||
_b85chars = [bytes((i,)) for i in _b85alphabet]
|
_b85chars = [bytes((i,)) for i in _b85alphabet]
|
||||||
_b85chars2 = [(a + b) for a in _b85chars for b in _b85chars]
|
_b85chars2 = [(a + b) for a in _b85chars for b in _b85chars]
|
||||||
return _85encode(b, _b85chars, _b85chars2, pad)
|
return _85encode(b, _b85chars, _b85chars2, pad)
|
||||||
|
|
|
@ -1121,11 +1121,9 @@ class GeneralModuleTests(unittest.TestCase):
|
||||||
s_good_values = [0, 1, 2, 0xffff]
|
s_good_values = [0, 1, 2, 0xffff]
|
||||||
l_good_values = s_good_values + [0xffffffff]
|
l_good_values = s_good_values + [0xffffffff]
|
||||||
l_bad_values = [-1, -2, 1<<32, 1<<1000]
|
l_bad_values = [-1, -2, 1<<32, 1<<1000]
|
||||||
s_bad_values = (
|
s_bad_values = l_bad_values + [_testcapi.INT_MIN - 1,
|
||||||
l_bad_values +
|
_testcapi.INT_MAX + 1]
|
||||||
[_testcapi.INT_MIN-1, _testcapi.INT_MAX+1] +
|
s_deprecated_values = [1<<16, _testcapi.INT_MAX]
|
||||||
[1 << 16, _testcapi.INT_MAX]
|
|
||||||
)
|
|
||||||
for k in s_good_values:
|
for k in s_good_values:
|
||||||
socket.ntohs(k)
|
socket.ntohs(k)
|
||||||
socket.htons(k)
|
socket.htons(k)
|
||||||
|
@ -1138,6 +1136,9 @@ class GeneralModuleTests(unittest.TestCase):
|
||||||
for k in l_bad_values:
|
for k in l_bad_values:
|
||||||
self.assertRaises(OverflowError, socket.ntohl, k)
|
self.assertRaises(OverflowError, socket.ntohl, k)
|
||||||
self.assertRaises(OverflowError, socket.htonl, 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):
|
def testGetServBy(self):
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
|
|
|
@ -1659,7 +1659,6 @@ Quentin Stafford-Fraser
|
||||||
Frank Stajano
|
Frank Stajano
|
||||||
Joel Stanley
|
Joel Stanley
|
||||||
Kyle Stanley
|
Kyle Stanley
|
||||||
Brandon Stansbury
|
|
||||||
Anthony Starks
|
Anthony Starks
|
||||||
David Steele
|
David Steele
|
||||||
Oliver Steele
|
Oliver Steele
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
Fix initialization race condition in :func:`a85encode` and :func:`b85encode`
|
|
||||||
in :mod:`base64`. Patch by Brandon Stansbury.
|
|
|
@ -1,3 +0,0 @@
|
||||||
Raise :exc:`OverflowError` instead of silent truncation in :meth:`socket.ntohs`
|
|
||||||
and :meth:`socket.htons`. Silent truncation was deprecated in Python 3.7.
|
|
||||||
Patch by Erlend E. Aasland
|
|
|
@ -6102,18 +6102,26 @@ socket_ntohs(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (x > 0xffff) {
|
if (x > 0xffff) {
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
if (PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||||
"ntohs: Python int too large to convert to C "
|
"ntohs: Python int too large to convert to C "
|
||||||
"16-bit unsigned integer");
|
"16-bit unsigned integer (The silent truncation "
|
||||||
|
"is deprecated)",
|
||||||
|
1)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return PyLong_FromUnsignedLong(ntohs((unsigned short)x));
|
return PyLong_FromUnsignedLong(ntohs((unsigned short)x));
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(ntohs_doc,
|
PyDoc_STRVAR(ntohs_doc,
|
||||||
"ntohs(integer) -> integer\n\
|
"ntohs(integer) -> integer\n\
|
||||||
\n\
|
\n\
|
||||||
Convert a 16-bit unsigned integer from network to host byte order.");
|
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.");
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -6165,18 +6173,26 @@ socket_htons(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (x > 0xffff) {
|
if (x > 0xffff) {
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
if (PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||||
"htons: Python int too large to convert to C "
|
"htons: Python int too large to convert to C "
|
||||||
"16-bit unsigned integer");
|
"16-bit unsigned integer (The silent truncation "
|
||||||
|
"is deprecated)",
|
||||||
|
1)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return PyLong_FromUnsignedLong(htons((unsigned short)x));
|
return PyLong_FromUnsignedLong(htons((unsigned short)x));
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(htons_doc,
|
PyDoc_STRVAR(htons_doc,
|
||||||
"htons(integer) -> integer\n\
|
"htons(integer) -> integer\n\
|
||||||
\n\
|
\n\
|
||||||
Convert a 16-bit unsigned integer from host to network byte order.");
|
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.");
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
Loading…
Reference in New Issue