| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0eac130 commit 8490f5a
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -174,6 +174,9 @@ To map anonymous memory, -1 should be passed as the fileno along with the length | |||
| 174 | 174 | Optional arguments *start* and *end* are interpreted as in slice notation. | |
| 175 | 175 | Returns ``-1`` on failure. | |
| 176 | 176 | ||
| 177 | + .. versionchanged: 3.5 | ||
| 178 | + Writable :term:`bytes-like object` is now accepted. | ||
| 179 | + | ||
| 177 | 180 | ||
| 178 | 181 | .. method:: flush([offset[, size]]) | |
| 179 | 182 | ||
@@ -234,6 +237,9 @@ To map anonymous memory, -1 should be passed as the fileno along with the length | |||
| 234 | 237 | Optional arguments *start* and *end* are interpreted as in slice notation. | |
| 235 | 238 | Returns ``-1`` on failure. | |
| 236 | 239 | ||
| 240 | + .. versionchanged: 3.5 | ||
| 241 | + Writable :term:`bytes-like object` is now accepted. | ||
| 242 | + | ||
| 237 | 243 | ||
| 238 | 244 | .. method:: seek(pos[, whence]) | |
| 239 | 245 | ||
@@ -261,6 +267,9 @@ To map anonymous memory, -1 should be passed as the fileno along with the length | |||
| 261 | 267 | were written. If the mmap was created with :const:`ACCESS_READ`, then | |
| 262 | 268 | writing to it will raise a :exc:`TypeError` exception. | |
| 263 | 269 | ||
| 270 | + .. versionchanged: 3.5 | ||
| 271 | + Writable :term:`bytes-like object` is now accepted. | ||
| 272 | + | ||
| 264 | 273 | ||
| 265 | 274 | .. method:: write_byte(byte) | |
| 266 | 275 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,21 +148,30 @@ and (read-only) attributes: | |||
| 148 | 148 | ||
| 149 | 149 | .. method:: oss_audio_device.write(data) | |
| 150 | 150 | ||
| 151 | - Write the Python string *data* to the audio device and return the number of | ||
| 152 | - bytes written. If the audio device is in blocking mode (the default), the | ||
| 153 | - entire string is always written (again, this is different from usual Unix device | ||
| 154 | - semantics). If the device is in non-blocking mode, some data may not be written | ||
| 151 | + Write a :term:`bytes-like object` *data* to the audio device and return the | ||
| 152 | + number of bytes written. If the audio device is in blocking mode (the | ||
| 153 | + default), the entire data is always written (again, this is different from | ||
| 154 | + usual Unix device semantics). If the device is in non-blocking mode, some | ||
| 155 | + data may not be written | ||
| 155 | 156 | ---see :meth:`writeall`. | |
| 156 | 157 | ||
| 158 | + .. versionchanged: 3.5 | ||
| 159 | + Writable :term:`bytes-like object` is now accepted. | ||
| 160 | + | ||
| 157 | 161 | ||
| 158 | 162 | .. method:: oss_audio_device.writeall(data) | |
| 159 | 163 | ||
| 160 | - Write the entire Python string *data* to the audio device: waits until the audio | ||
| 161 | - device is able to accept data, writes as much data as it will accept, and | ||
| 162 | - repeats until *data* has been completely written. If the device is in blocking | ||
| 163 | - mode (the default), this has the same effect as :meth:`write`; :meth:`writeall` | ||
| 164 | - is only useful in non-blocking mode. Has no return value, since the amount of | ||
| 165 | - data written is always equal to the amount of data supplied. | ||
| 164 | + Write a :term:`bytes-like object` *data* to the audio device: waits until | ||
| 165 | + the audio device is able to accept data, writes as much data as it will | ||
| 166 | + accept, and repeats until *data* has been completely written. If the device | ||
| 167 | + is in blocking mode (the default), this has the same effect as | ||
| 168 | + :meth:`write`; :meth:`writeall` is only useful in non-blocking mode. Has | ||
| 169 | + no return value, since the amount of data written is always equal to the | ||
| 170 | + amount of data supplied. | ||
| 171 | + | ||
| 172 | + .. versionchanged: 3.5 | ||
| 173 | + Writable :term:`bytes-like object` is now accepted. | ||
| 174 | + | ||
| 166 | 175 | ||
| 167 | 176 | .. versionchanged:: 3.2 | |
| 168 | 177 | Audio device objects also support the context management protocol, i.e. they can | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,17 +46,20 @@ created. Socket addresses are represented as follows: | |||
| 46 | 46 | - The address of an :const:`AF_UNIX` socket bound to a file system node | |
| 47 | 47 | is represented as a string, using the file system encoding and the | |
| 48 | 48 | ``'surrogateescape'`` error handler (see :pep:`383`). An address in | |
| 49 | - Linux's abstract namespace is returned as a :class:`bytes` object with | ||
| 49 | + Linux's abstract namespace is returned as a :term:`bytes-like object` with | ||
| 50 | 50 | an initial null byte; note that sockets in this namespace can | |
| 51 | 51 | communicate with normal file system sockets, so programs intended to | |
| 52 | 52 | run on Linux may need to deal with both types of address. A string or | |
| 53 | - :class:`bytes` object can be used for either type of address when | ||
| 53 | + bytes-like object can be used for either type of address when | ||
| 54 | 54 | passing it as an argument. | |
| 55 | 55 | ||
| 56 | 56 | .. versionchanged:: 3.3 | |
| 57 | 57 | Previously, :const:`AF_UNIX` socket paths were assumed to use UTF-8 | |
| 58 | 58 | encoding. | |
| 59 | 59 | ||
| 60 | + .. versionchanged: 3.5 | ||
| 61 | + Writable :term:`bytes-like object` is now accepted. | ||
| 62 | + | ||
| 60 | 63 | - A pair ``(host, port)`` is used for the :const:`AF_INET` address family, | |
| 61 | 64 | where *host* is a string representing either a hostname in Internet domain | |
| 62 | 65 | notation like ``'daring.cwi.nl'`` or an IPv4 address like ``'100.50.200.5'``, | |
@@ -609,8 +612,8 @@ The :mod:`socket` module also offers various network-related services: | |||
| 609 | 612 | ||
| 610 | 613 | .. function:: inet_ntoa(packed_ip) | |
| 611 | 614 | ||
| 612 | - Convert a 32-bit packed IPv4 address (a bytes object four characters in | ||
| 613 | - length) to its standard dotted-quad string representation (for example, | ||
| 615 | + Convert a 32-bit packed IPv4 address (a :term:`bytes-like object` four | ||
| 616 | + bytes in length) to its standard dotted-quad string representation (for example, | ||
| 614 | 617 | '123.45.67.89'). This is useful when conversing with a program that uses the | |
| 615 | 618 | standard C library and needs objects of type :c:type:`struct in_addr`, which | |
| 616 | 619 | is the C type for the 32-bit packed binary data this function takes as an | |
@@ -621,6 +624,9 @@ The :mod:`socket` module also offers various network-related services: | |||
| 621 | 624 | support IPv6, and :func:`inet_ntop` should be used instead for IPv4/v6 dual | |
| 622 | 625 | stack support. | |
| 623 | 626 | ||
| 627 | + .. versionchanged: 3.5 | ||
| 628 | + Writable :term:`bytes-like object` is now accepted. | ||
| 629 | + | ||
| 624 | 630 | ||
| 625 | 631 | .. function:: inet_pton(address_family, ip_string) | |
| 626 | 632 | ||
@@ -643,22 +649,26 @@ The :mod:`socket` module also offers various network-related services: | |||
| 643 | 649 | ||
| 644 | 650 | .. function:: inet_ntop(address_family, packed_ip) | |
| 645 | 651 | ||
| 646 | - Convert a packed IP address (a bytes object of some number of characters) to its | ||
| 647 | - standard, family-specific string representation (for example, ``'7.10.0.5'`` or | ||
| 648 | - ``'5aef:2b::8'``). :func:`inet_ntop` is useful when a library or network protocol | ||
| 649 | - returns an object of type :c:type:`struct in_addr` (similar to :func:`inet_ntoa`) | ||
| 650 | - or :c:type:`struct in6_addr`. | ||
| 652 | + Convert a packed IP address (a :term:`bytes-like object` of some number of | ||
| 653 | + bytes) to its standard, family-specific string representation (for | ||
| 654 | + example, ``'7.10.0.5'`` or ``'5aef:2b::8'``). | ||
| 655 | + :func:`inet_ntop` is useful when a library or network protocol returns an | ||
| 656 | + object of type :c:type:`struct in_addr` (similar to :func:`inet_ntoa`) or | ||
| 657 | + :c:type:`struct in6_addr`. | ||
| 651 | 658 | ||
| 652 | 659 | Supported values for *address_family* are currently :const:`AF_INET` and | |
| 653 | - :const:`AF_INET6`. If the string *packed_ip* is not the correct length for the | ||
| 654 | - specified address family, :exc:`ValueError` will be raised. A | ||
| 655 | - :exc:`OSError` is raised for errors from the call to :func:`inet_ntop`. | ||
| 660 | + :const:`AF_INET6`. If the bytes object *packed_ip* is not the correct | ||
| 661 | + length for the specified address family, :exc:`ValueError` will be raised. | ||
| 662 | + A :exc:`OSError` is raised for errors from the call to :func:`inet_ntop`. | ||
| 656 | 663 | ||
| 657 | 664 | Availability: Unix (maybe not all platforms), Windows. | |
| 658 | 665 | ||
| 659 | 666 | .. versionchanged:: 3.4 | |
| 660 | 667 | Windows support added | |
| 661 | 668 | ||
| 669 | + .. versionchanged: 3.5 | ||
| 670 | + Writable :term:`bytes-like object` is now accepted. | ||
| 671 | + | ||
| 662 | 672 | ||
| 663 | 673 | .. | |
| 664 | 674 | XXX: Are sendmsg(), recvmsg() and CMSG_*() available on any | |
@@ -1207,11 +1217,15 @@ to sockets. | |||
| 1207 | 1217 | ||
| 1208 | 1218 | Set the value of the given socket option (see the Unix manual page | |
| 1209 | 1219 | :manpage:`setsockopt(2)`). The needed symbolic constants are defined in the | |
| 1210 | - :mod:`socket` module (:const:`SO_\*` etc.). The value can be an integer or a | ||
| 1211 | - bytes object representing a buffer. In the latter case it is up to the caller to | ||
| 1220 | + :mod:`socket` module (:const:`SO_\*` etc.). The value can be an integer or | ||
| 1221 | + a :term:`bytes-like object` representing a buffer. In the latter case it is | ||
| 1222 | + up to the caller to | ||
| 1212 | 1223 | ensure that the bytestring contains the proper bits (see the optional built-in | |
| 1213 | 1224 | module :mod:`struct` for a way to encode C structures as bytestrings). | |
| 1214 | 1225 | ||
| 1226 | + .. versionchanged: 3.5 | ||
| 1227 | + Writable :term:`bytes-like object` is now accepted. | ||
| 1228 | + | ||
| 1215 | 1229 | ||
| 1216 | 1230 | .. method:: socket.shutdown(how) | |
| 1217 | 1231 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -340,6 +340,9 @@ Random generation | |||
| 340 | 340 | string (so you can always use :const:`0.0`). See :rfc:`1750` for more | |
| 341 | 341 | information on sources of entropy. | |
| 342 | 342 | ||
| 343 | + .. versionchanged: 3.5 | ||
| 344 | + Writable :term:`bytes-like object` is now accepted. | ||
| 345 | + | ||
| 343 | 346 | Certificate handling | |
| 344 | 347 | ^^^^^^^^^^^^^^^^^^^^ | |
| 345 | 348 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1086,6 +1086,7 @@ def test_stream_bare(self): | |||
| 1086 | 1086 | class EscapeDecodeTest(unittest.TestCase): | |
| 1087 | 1087 | def test_empty(self): | |
| 1088 | 1088 | self.assertEqual(codecs.escape_decode(b""), (b"", 0)) | |
| 1089 | + self.assertEqual(codecs.escape_decode(bytearray()), (b"", 0)) | ||
| 1089 | 1090 | ||
| 1090 | 1091 | def test_raw(self): | |
| 1091 | 1092 | decode = codecs.escape_decode | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -282,6 +282,7 @@ def test_find_end(self): | |||
| 282 | 282 | self.assertEqual(m.find(b'one', 1), 8) | |
| 283 | 283 | self.assertEqual(m.find(b'one', 1, -1), 8) | |
| 284 | 284 | self.assertEqual(m.find(b'one', 1, -2), -1) | |
| 285 | + self.assertEqual(m.find(bytearray(b'one')), 0) | ||
| 285 | 286 | ||
| 286 | 287 | ||
| 287 | 288 | def test_rfind(self): | |
@@ -300,6 +301,7 @@ def test_rfind(self): | |||
| 300 | 301 | self.assertEqual(m.rfind(b'one', 0, -2), 0) | |
| 301 | 302 | self.assertEqual(m.rfind(b'one', 1, -1), 8) | |
| 302 | 303 | self.assertEqual(m.rfind(b'one', 1, -2), -1) | |
| 304 | + self.assertEqual(m.rfind(bytearray(b'one')), 8) | ||
| 303 | 305 | ||
| 304 | 306 | ||
| 305 | 307 | def test_double_close(self): | |
@@ -601,8 +603,10 @@ def test_io_methods(self): | |||
| 601 | 603 | m.write(b"bar") | |
| 602 | 604 | self.assertEqual(m.tell(), 6) | |
| 603 | 605 | self.assertEqual(m[:], b"012bar6789") | |
| 604 | - m.seek(8) | ||
| 605 | - self.assertRaises(ValueError, m.write, b"bar") | ||
| 606 | + m.write(bytearray(b"baz")) | ||
| 607 | + self.assertEqual(m.tell(), 9) | ||
| 608 | + self.assertEqual(m[:], b"012barbaz9") | ||
| 609 | + self.assertRaises(ValueError, m.write, b"ba") | ||
| 606 | 610 | ||
| 607 | 611 | def test_non_ascii_byte(self): | |
| 608 | 612 | for b in (129, 200, 255): # > 128 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1074,13 +1074,15 @@ def testStringToIPv4(self): | |||
| 1074 | 1074 | assertInvalid(f, b'\x00' * 3) | |
| 1075 | 1075 | assertInvalid(f, b'\x00' * 5) | |
| 1076 | 1076 | assertInvalid(f, b'\x00' * 16) | |
| 1077 | + self.assertEqual('170.85.170.85', f(bytearray(b'\xaa\x55\xaa\x55'))) | ||
| 1077 | 1078 | ||
| 1078 | 1079 | self.assertEqual('1.0.1.0', g(b'\x01\x00\x01\x00')) | |
| 1079 | 1080 | self.assertEqual('170.85.170.85', g(b'\xaa\x55\xaa\x55')) | |
| 1080 | 1081 | self.assertEqual('255.255.255.255', g(b'\xff\xff\xff\xff')) | |
| 1081 | 1082 | assertInvalid(g, b'\x00' * 3) | |
| 1082 | 1083 | assertInvalid(g, b'\x00' * 5) | |
| 1083 | 1084 | assertInvalid(g, b'\x00' * 16) | |
| 1085 | + self.assertEqual('170.85.170.85', g(bytearray(b'\xaa\x55\xaa\x55'))) | ||
| 1084 | 1086 | ||
| 1085 | 1087 | @unittest.skipUnless(hasattr(socket, 'inet_ntop'), | |
| 1086 | 1088 | 'test needs socket.inet_ntop()') | |
@@ -1110,6 +1112,7 @@ def testStringToIPv6(self): | |||
| 1110 | 1112 | 'aef:b01:506:1001:ffff:9997:55:170', | |
| 1111 | 1113 | f(b'\x0a\xef\x0b\x01\x05\x06\x10\x01\xff\xff\x99\x97\x00\x55\x01\x70') | |
| 1112 | 1114 | ) | |
| 1115 | + self.assertEqual('::1', f(bytearray(b'\x00' * 15 + b'\x01'))) | ||
| 1113 | 1116 | ||
| 1114 | 1117 | assertInvalid(b'\x12' * 15) | |
| 1115 | 1118 | assertInvalid(b'\x12' * 17) | |
@@ -1497,6 +1500,7 @@ def testFilter(self): | |||
| 1497 | 1500 | s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, can_filter) | |
| 1498 | 1501 | self.assertEqual(can_filter, | |
| 1499 | 1502 | s.getsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, 8)) | |
| 1503 | + s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, bytearray(can_filter)) | ||
| 1500 | 1504 | ||
| 1501 | 1505 | ||
| 1502 | 1506 | @unittest.skipUnless(HAVE_SOCKET_CAN, 'SocketCan required for this test.') | |
@@ -4508,6 +4512,12 @@ def testStrName(self): | |||
| 4508 | 4512 | finally: | |
| 4509 | 4513 | s.close() | |
| 4510 | 4514 | ||
| 4515 | + def testBytearrayName(self): | ||
| 4516 | + # Check that an abstract name can be passed as a bytearray. | ||
| 4517 | + with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s: | ||
| 4518 | + s.bind(bytearray(b"\x00python\x00test\x00")) | ||
| 4519 | + self.assertEqual(s.getsockname(), b"\x00python\x00test\x00") | ||
| 4520 | + | ||
| 4511 | 4521 | @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'test needs socket.AF_UNIX') | |
| 4512 | 4522 | class TestUnixDomain(unittest.TestCase): | |
| 4513 | 4523 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -171,6 +171,8 @@ def test_random(self): | |||
| 171 | 171 | self.assertRaises(TypeError, ssl.RAND_egd, 1) | |
| 172 | 172 | self.assertRaises(TypeError, ssl.RAND_egd, 'foo', 1) | |
| 173 | 173 | ssl.RAND_add("this is a random string", 75.0) | |
| 174 | + ssl.RAND_add(b"this is a random bytes object", 75.0) | ||
| 175 | + ssl.RAND_add(bytearray(b"this is a random bytearray object"), 75.0) | ||
| 174 | 176 | ||
| 175 | 177 | @unittest.skipUnless(os.name == 'posix', 'requires posix') | |
| 176 | 178 | def test_random_fork(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,10 @@ Core and Builtins | |||
| 21 | 21 | Library | |
| 22 | 22 | ------- | |
| 23 | 23 | ||
| 24 | + - Issue #23001: Few functions in modules mmap, ossaudiodev, socket, ssl, and | ||
| 25 | + codecs, that accepted only read-only bytes-like object now accept writable | ||
| 26 | + bytes-like object too. | ||
| 27 | + | ||
| 24 | 28 | - Issue #23646: If time.sleep() is interrupted by a signal, the sleep is now | |
| 25 | 29 | retried with the recomputed delay, except if the signal handler raises an | |
| 26 | 30 | exception (PEP 475). | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -208,15 +208,18 @@ static PyObject * | |||
| 208 | 208 | escape_decode(PyObject *self, | |
| 209 | 209 | PyObject *args) | |
| 210 | 210 | { | |
| 211 | + Py_buffer pbuf; | ||
| 211 | 212 | const char *errors = NULL; | |
| 212 | - const char *data; | ||
| 213 | - Py_ssize_t size; | ||
| 213 | + PyObject *result; | ||
| 214 | 214 | ||
| 215 | - if (!PyArg_ParseTuple(args, "s#|z:escape_decode", | ||
| 216 | - &data, &size, &errors)) | ||
| 215 | + if (!PyArg_ParseTuple(args, "s*|z:escape_decode", | ||
| 216 | + &pbuf, &errors)) | ||
| 217 | 217 | return NULL; | |
| 218 | - return codec_tuple(PyBytes_DecodeEscape(data, size, errors, 0, NULL), | ||
| 219 | - size); | ||
| 218 | + result = codec_tuple( | ||
| 219 | + PyBytes_DecodeEscape(pbuf.buf, pbuf.len, errors, 0, NULL), | ||
| 220 | + pbuf.len); | ||
| 221 | + PyBuffer_Release(&pbuf); | ||
| 222 | + return result; | ||
| 220 | 223 | } | |
| 221 | 224 | ||
| 222 | 225 | static PyObject * | |
| Back | FazBrowse Home | New Git URL |
0 commit comments