Kaydet (Commit) c228e967 authored tarafından Ezio Melotti's avatar Ezio Melotti

#16518: use "bytes-like object" throughout the docs.

üst 28faf03d
...@@ -70,8 +70,7 @@ Unless otherwise stated, buffers are not NUL-terminated. ...@@ -70,8 +70,7 @@ Unless otherwise stated, buffers are not NUL-terminated.
as *converter*. as *converter*.
``s*`` (:class:`str`, :class:`bytes`, :class:`bytearray` or buffer compatible object) [Py_buffer] ``s*`` (:class:`str`, :class:`bytes`, :class:`bytearray` or buffer compatible object) [Py_buffer]
This format accepts Unicode objects as well as objects supporting the This format accepts Unicode objects as well as :term:`bytes-like object`\ s.
buffer protocol.
It fills a :c:type:`Py_buffer` structure provided by the caller. It fills a :c:type:`Py_buffer` structure provided by the caller.
In this case the resulting C string may contain embedded NUL bytes. In this case the resulting C string may contain embedded NUL bytes.
Unicode objects are converted to C strings using ``'utf-8'`` encoding. Unicode objects are converted to C strings using ``'utf-8'`` encoding.
...@@ -101,14 +100,14 @@ Unless otherwise stated, buffers are not NUL-terminated. ...@@ -101,14 +100,14 @@ Unless otherwise stated, buffers are not NUL-terminated.
contain embedded NUL bytes; if it does, a :exc:`TypeError` contain embedded NUL bytes; if it does, a :exc:`TypeError`
exception is raised. exception is raised.
``y*`` (:class:`bytes`, :class:`bytearray` or buffer compatible object) [Py_buffer] ``y*`` (:class:`bytes`, :class:`bytearray` or :term:`bytes-like object`) [Py_buffer]
This variant on ``s*`` doesn't accept Unicode objects, only objects This variant on ``s*`` doesn't accept Unicode objects, only
supporting the buffer protocol. **This is the recommended way to accept :term:`bytes-like object`\ s. **This is the recommended way to accept
binary data.** binary data.**
``y#`` (:class:`bytes`) [const char \*, int] ``y#`` (:class:`bytes`) [const char \*, int]
This variant on ``s#`` doesn't accept Unicode objects, only bytes-like This variant on ``s#`` doesn't accept Unicode objects, only :term:`bytes-like
objects. object`\ s.
``S`` (:class:`bytes`) [PyBytesObject \*] ``S`` (:class:`bytes`) [PyBytesObject \*]
Requires that the Python object is a :class:`bytes` object, without Requires that the Python object is a :class:`bytes` object, without
......
...@@ -40,7 +40,7 @@ Direct API functions ...@@ -40,7 +40,7 @@ Direct API functions
.. c:function:: PyObject* PyByteArray_FromObject(PyObject *o) .. c:function:: PyObject* PyByteArray_FromObject(PyObject *o)
Return a new bytearray object from any object, *o*, that implements the Return a new bytearray object from any object, *o*, that implements the
buffer protocol. :ref:`buffer protocol <bufferobjects>`.
.. XXX expand about the buffer protocol, at least somewhere .. XXX expand about the buffer protocol, at least somewhere
......
...@@ -73,8 +73,8 @@ The module defines the following type: ...@@ -73,8 +73,8 @@ The module defines the following type:
.. class:: array(typecode[, initializer]) .. class:: array(typecode[, initializer])
A new array whose items are restricted by *typecode*, and initialized A new array whose items are restricted by *typecode*, and initialized
from the optional *initializer* value, which must be a list, object from the optional *initializer* value, which must be a list, a
supporting the buffer interface, or iterable over elements of the :term:`bytes-like object`, or iterable over elements of the
appropriate type. appropriate type.
If given a list or string, the initializer is passed to the new array's If given a list or string, the initializer is passed to the new array's
...@@ -91,7 +91,7 @@ Array objects support the ordinary sequence operations of indexing, slicing, ...@@ -91,7 +91,7 @@ Array objects support the ordinary sequence operations of indexing, slicing,
concatenation, and multiplication. When using slice assignment, the assigned concatenation, and multiplication. When using slice assignment, the assigned
value must be an array object with the same type code; in all other cases, value must be an array object with the same type code; in all other cases,
:exc:`TypeError` is raised. Array objects also implement the buffer interface, :exc:`TypeError` is raised. Array objects also implement the buffer interface,
and may be used wherever buffer objects are supported. and may be used wherever :term:`bytes-like object`\ s are supported.
The following data items and methods are also supported: The following data items and methods are also supported:
......
...@@ -21,8 +21,9 @@ higher-level modules. ...@@ -21,8 +21,9 @@ higher-level modules.
.. note:: .. note::
``a2b_*`` functions accept Unicode strings containing only ASCII characters. ``a2b_*`` functions accept Unicode strings containing only ASCII characters.
Other functions only accept bytes and bytes-compatible objects (such as Other functions only accept :term:`bytes-like object`\ s (such as
bytearray objects and other objects implementing the buffer API). :class:`bytes`, :class:`bytearray` and other objects that support the buffer
protocol).
.. versionchanged:: 3.3 .. versionchanged:: 3.3
ASCII-only unicode strings are now accepted by the ``a2b_*`` functions. ASCII-only unicode strings are now accepted by the ``a2b_*`` functions.
......
...@@ -32,9 +32,9 @@ digests. The modern term is secure hash. ...@@ -32,9 +32,9 @@ digests. The modern term is secure hash.
There is one constructor method named for each type of :dfn:`hash`. All return There is one constructor method named for each type of :dfn:`hash`. All return
a hash object with the same simple interface. For example: use :func:`sha1` to a hash object with the same simple interface. For example: use :func:`sha1` to
create a SHA1 hash object. You can now feed this object with objects conforming create a SHA1 hash object. You can now feed this object with :term:`bytes-like
to the buffer interface (normally :class:`bytes` objects) using the object`\ s (normally :class:`bytes`) using the :meth:`update` method.
:meth:`update` method. At any point you can ask it for the :dfn:`digest` of the At any point you can ask it for the :dfn:`digest` of the
concatenation of the data fed to it so far using the :meth:`digest` or concatenation of the data fed to it so far using the :meth:`digest` or
:meth:`hexdigest` methods. :meth:`hexdigest` methods.
......
...@@ -74,8 +74,7 @@ This module also provides the following helper function: ...@@ -74,8 +74,7 @@ This module also provides the following helper function:
timing analysis by avoiding content-based short circuiting behaviour, timing analysis by avoiding content-based short circuiting behaviour,
making it appropriate for cryptography. *a* and *b* must both be of the making it appropriate for cryptography. *a* and *b* must both be of the
same type: either :class:`str` (ASCII only, as e.g. returned by same type: either :class:`str` (ASCII only, as e.g. returned by
:meth:`HMAC.hexdigest`), or any type that supports the buffer protocol :meth:`HMAC.hexdigest`), or a :term:`bytes-like object`.
(e.g. :class:`bytes`).
.. note:: .. note::
......
...@@ -800,8 +800,7 @@ Connection objects are usually created using :func:`Pipe` -- see also ...@@ -800,8 +800,7 @@ Connection objects are usually created using :func:`Pipe` -- see also
.. method:: send_bytes(buffer[, offset[, size]]) .. method:: send_bytes(buffer[, offset[, size]])
Send byte data from an object supporting the buffer interface as a Send byte data from a :term:`bytes-like object` as a complete message.
complete message.
If *offset* is given then data is read from that position in *buffer*. If If *offset* is given then data is read from that position in *buffer*. If
*size* is given then that many bytes will be read from buffer. Very large *size* is given then that many bytes will be read from buffer. Very large
...@@ -832,7 +831,7 @@ Connection objects are usually created using :func:`Pipe` -- see also ...@@ -832,7 +831,7 @@ Connection objects are usually created using :func:`Pipe` -- see also
:exc:`EOFError` if there is nothing left to receive and the other end was :exc:`EOFError` if there is nothing left to receive and the other end was
closed. closed.
*buffer* must be an object satisfying the writable buffer interface. If *buffer* must be a writable :term:`bytes-like object`. If
*offset* is given then the message will be written into the buffer from *offset* is given then the message will be written into the buffer from
that position. Offset must be a non-negative integer less than the that position. Offset must be a non-negative integer less than the
length of *buffer* (in bytes). length of *buffer* (in bytes).
......
...@@ -519,9 +519,8 @@ class`. In addition, it provides one more method: ...@@ -519,9 +519,8 @@ class`. In addition, it provides one more method:
>>> int.from_bytes([255, 0, 0], byteorder='big') >>> int.from_bytes([255, 0, 0], byteorder='big')
16711680 16711680
The argument *bytes* must either support the buffer protocol or be an The argument *bytes* must either be a :term:`bytes-like object` or an
iterable producing bytes. :class:`bytes` and :class:`bytearray` are iterable producing bytes.
examples of built-in objects that support the buffer protocol.
The *byteorder* argument determines the byte order used to represent the The *byteorder* argument determines the byte order used to represent the
integer. If *byteorder* is ``"big"``, the most significant byte is at the integer. If *byteorder* is ``"big"``, the most significant byte is at the
...@@ -1417,10 +1416,9 @@ multiple fragments. ...@@ -1417,10 +1416,9 @@ multiple fragments.
single: bytes; str (built-in class) single: bytes; str (built-in class)
If at least one of *encoding* or *errors* is given, *object* should be a If at least one of *encoding* or *errors* is given, *object* should be a
:class:`bytes` or :class:`bytearray` object, or more generally any object :term:`bytes-like object` (e.g. :class:`bytes` or :class:`bytearray`). In
that supports the :ref:`buffer protocol <bufferobjects>`. In this case, if this case, if *object* is a :class:`bytes` (or :class:`bytearray`) object,
*object* is a :class:`bytes` (or :class:`bytearray`) object, then then ``str(bytes, encoding, errors)`` is equivalent to
``str(bytes, encoding, errors)`` is equivalent to
:meth:`bytes.decode(encoding, errors) <bytes.decode>`. Otherwise, the bytes :meth:`bytes.decode(encoding, errors) <bytes.decode>`. Otherwise, the bytes
object underlying the buffer object is obtained before calling object underlying the buffer object is obtained before calling
:meth:`bytes.decode`. See :ref:`binaryseq` and :meth:`bytes.decode`. See :ref:`binaryseq` and
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment