| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a19f80c commit 98297ee
148 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,8 +56,9 @@ The module defines the following type: | |||
| 56 | 56 | .. function:: array(typecode[, initializer]) | |
| 57 | 57 | ||
| 58 | 58 | Return a new array whose items are restricted by *typecode*, and initialized | |
| 59 | - from the optional *initializer* value, which must be a list, string, or iterable | ||
| 60 | - over elements of the appropriate type. | ||
| 59 | + from the optional *initializer* value, which must be a list, object | ||
| 60 | + supporting the buffer interface, or iterable over elements of the | ||
| 61 | + appropriate type. | ||
| 61 | 62 | ||
| 62 | 63 | If given a list or string, the initializer is passed to the new array's | |
| 63 | 64 | :meth:`fromlist`, :meth:`fromstring`, or :meth:`fromunicode` method (see below) | |
@@ -69,6 +70,10 @@ The module defines the following type: | |||
| 69 | 70 | ||
| 70 | 71 | Obsolete alias for :func:`array`. | |
| 71 | 72 | ||
| 73 | + .. data:: typecodes | ||
| 74 | + | ||
| 75 | + A string with all available type codes. | ||
| 76 | + | ||
| 72 | 77 | Array objects support the ordinary sequence operations of indexing, slicing, | |
| 73 | 78 | concatenation, and multiplication. When using slice assignment, the assigned | |
| 74 | 79 | value must be an array object with the same type code; in all other cases, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -405,7 +405,11 @@ module for more information. | |||
| 405 | 405 | ||
| 406 | 406 | Base class for warnings related to Unicode. | |
| 407 | 407 | ||
| 408 | - The class hierarchy for built-in exceptions is: | ||
| 408 | + .. exception:: BytesWarning | ||
| 409 | + | ||
| 410 | + Base class for warnings related to :class:`bytes` and :class:`buffer`. | ||
| 409 | 411 | ||
| 410 | 412 | ||
| 413 | + The class hierarchy for built-in exceptions is: | ||
| 414 | + | ||
| 411 | 415 | .. literalinclude:: ../../Lib/test/exception_hierarchy.txt | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -118,31 +118,44 @@ available. They are listed here in alphabetical order. | |||
| 118 | 118 | .. index:: pair: Boolean; type | |
| 119 | 119 | ||
| 120 | 120 | ||
| 121 | - .. function:: bytes([arg[, encoding[, errors]]]) | ||
| 121 | + .. function:: buffer([arg[, encoding[, errors]]]) | ||
| 122 | 122 | ||
| 123 | - Return a new array of bytes. The :class:`bytes` type is a mutable sequence | ||
| 123 | + Return a new array of bytes. The :class:`buffer` type is an immutable sequence | ||
| 124 | 124 | of integers in the range 0 <= x < 256. It has most of the usual methods of | |
| 125 | - mutable sequences, described in :ref:`typesseq-mutable`, as well as a few | ||
| 126 | - methods borrowed from strings, described in :ref:`bytes-methods`. | ||
| 125 | + mutable sequences, described in :ref:`typesseq-mutable`, as well as most methods | ||
| 126 | + that the :class:`str` type has, see :ref:`bytes-methods`. | ||
| 127 | 127 | ||
| 128 | 128 | The optional *arg* parameter can be used to initialize the array in a few | |
| 129 | 129 | different ways: | |
| 130 | 130 | ||
| 131 | 131 | * If it is a *string*, you must also give the *encoding* (and optionally, | |
| 132 | - *errors*) parameters; :func:`bytes` then acts like :meth:`str.encode`. | ||
| 132 | + *errors*) parameters; :func:`buffer` then converts the Unicode string to | ||
| 133 | + bytes using :meth:`str.encode`. | ||
| 133 | 134 | ||
| 134 | 135 | * If it is an *integer*, the array will have that size and will be | |
| 135 | 136 | initialized with null bytes. | |
| 136 | 137 | ||
| 137 | 138 | * If it is an object conforming to the *buffer* interface, a read-only buffer | |
| 138 | 139 | of the object will be used to initialize the bytes array. | |
| 139 | 140 | ||
| 140 | - * If it is an *iterable*, it must be an iterable of integers in the range 0 | ||
| 141 | - <= x < 256, which are used as the initial contents of the array. | ||
| 141 | + * If it is an *iterable*, it must be an iterable of integers in the range | ||
| 142 | + ``0 <= x < 256``, which are used as the initial contents of the array. | ||
| 142 | 143 | ||
| 143 | 144 | Without an argument, an array of size 0 is created. | |
| 144 | 145 | ||
| 145 | 146 | ||
| 147 | + .. function:: bytes([arg[, encoding[, errors]]]) | ||
| 148 | + | ||
| 149 | + Return a new "bytes" object, which is an immutable sequence of integers in | ||
| 150 | + the range ``0 <= x < 256``. :class:`bytes` is an immutable version of | ||
| 151 | + :class:`buffer` -- it has the same non-mutating methods and the same indexing | ||
| 152 | + and slicing behavior. | ||
| 153 | + | ||
| 154 | + Accordingly, constructor arguments are interpreted as for :func:`buffer`. | ||
| 155 | + | ||
| 156 | + Bytes objects can also be created with literals, see :ref:`strings`. | ||
| 157 | + | ||
| 158 | + | ||
| 146 | 159 | .. function:: chr(i) | |
| 147 | 160 | ||
| 148 | 161 | Return the string of one character whose Unicode codepoint is the integer | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1313,9 +1313,11 @@ Bytes and Buffer Methods | |||
| 1313 | 1313 | ||
| 1314 | 1314 | Bytes and buffer objects, being "strings of bytes", have all methods found on | |
| 1315 | 1315 | strings, with the exception of :func:`encode`, :func:`format` and | |
| 1316 | - :func:`isidentifier`, which do not make sense with these types. Wherever one of | ||
| 1317 | - these methods needs to interpret the bytes as characters (e.g. the :func:`is...` | ||
| 1318 | - methods), the ASCII character set is assumed. | ||
| 1316 | + :func:`isidentifier`, which do not make sense with these types. For converting | ||
| 1317 | + the objects to strings, they have a :func:`decode` method. | ||
| 1318 | + | ||
| 1319 | + Wherever one of these methods needs to interpret the bytes as characters | ||
| 1320 | + (e.g. the :func:`is...` methods), the ASCII character set is assumed. | ||
| 1319 | 1321 | ||
| 1320 | 1322 | .. note:: | |
| 1321 | 1323 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,6 +80,10 @@ following warnings category classes are currently defined: | |||
| 80 | 80 | | :exc:`UnicodeWarning` | Base category for warnings related to | | |
| 81 | 81 | | | Unicode. | | |
| 82 | 82 | +----------------------------------+-----------------------------------------------+ | |
| 83 | + | :exc:`BytesWarning` | Base category for warnings related to | | ||
| 84 | + | | :class:`bytes` and :class:`buffer`. | | ||
| 85 | + +----------------------------------+-----------------------------------------------+ | ||
| 86 | + | ||
| 83 | 87 | ||
| 84 | 88 | While these are technically built-in exceptions, they are documented here, | |
| 85 | 89 | because conceptually they belong to the warnings mechanism. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -131,11 +131,6 @@ changes to rarely used features.) | |||
| 131 | 131 | that if a file is opened using an incorrect mode or encoding, I/O | |
| 132 | 132 | will likely fail. | |
| 133 | 133 | ||
| 134 | - * Bytes aren't hashable, and don't support certain operations like | ||
| 135 | - ``b.lower()``, ``b.strip()`` or ``b.split()``. | ||
| 136 | - For the latter two, use ``b.strip(b" \t\r\n\f")`` or | ||
| 137 | - ``b.split(b" \t\r\n\f")``. | ||
| 138 | - | ||
| 139 | 134 | * ``map()`` and ``filter()`` return iterators. A quick fix is e.g. | |
| 140 | 135 | ``list(map(...))``, but a better fix is often to use a list | |
| 141 | 136 | comprehension (especially when the original code uses ``lambda``). | |
@@ -158,13 +153,11 @@ Strings and Bytes | |||
| 158 | 153 | * There is only one string type; its name is ``str`` but its behavior | |
| 159 | 154 | and implementation are more like ``unicode`` in 2.x. | |
| 160 | 155 | ||
| 161 | - * PEP 358: There is a new type, ``bytes``, to represent binary data | ||
| 156 | + * PEP 3137: There is a new type, ``bytes``, to represent binary data | ||
| 162 | 157 | (and encoded text, which is treated as binary data until you decide | |
| 163 | 158 | to decode it). The ``str`` and ``bytes`` types cannot be mixed; you | |
| 164 | 159 | must always explicitly convert between them, using the ``.encode()`` | |
| 165 | - (str -> bytes) or ``.decode()`` (bytes -> str) methods. Comparing a | ||
| 166 | - bytes and a str instance for equality raises a TypeError; this | ||
| 167 | - catches common mistakes. | ||
| 160 | + (str -> bytes) or ``.decode()`` (bytes -> str) methods. | ||
| 168 | 161 | ||
| 169 | 162 | * PEP 3112: Bytes literals. E.g. b"abc". | |
| 170 | 163 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -259,7 +259,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ | |||
| 259 | 259 | string representation on success, NULL on failure. This is | |
| 260 | 260 | the equivalent of the Python expression: repr(o). | |
| 261 | 261 | ||
| 262 | - Called by the repr() built-in function and by reverse quotes. | ||
| 262 | + Called by the repr() built-in function. | ||
| 263 | 263 | ||
| 264 | 264 | */ | |
| 265 | 265 | ||
@@ -271,20 +271,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ | |||
| 271 | 271 | string representation on success, NULL on failure. This is | |
| 272 | 272 | the equivalent of the Python expression: str(o).) | |
| 273 | 273 | ||
| 274 | - Called by the str() built-in function and by the print | ||
| 275 | - statement. | ||
| 276 | - | ||
| 277 | - */ | ||
| 278 | - | ||
| 279 | - /* Implemented elsewhere: | ||
| 280 | - | ||
| 281 | - PyObject *PyObject_Unicode(PyObject *o); | ||
| 282 | - | ||
| 283 | - Compute the unicode representation of object, o. Returns the | ||
| 284 | - unicode representation on success, NULL on failure. This is | ||
| 285 | - the equivalent of the Python expression: unistr(o).) | ||
| 286 | - | ||
| 287 | - Called by the unistr() built-in function. | ||
| 274 | + Called by the str() and print() built-in functions. | ||
| 288 | 275 | ||
| 289 | 276 | */ | |
| 290 | 277 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -431,10 +431,8 @@ PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int); | |||
| 431 | 431 | PyAPI_FUNC(void) _Py_BreakPoint(void); | |
| 432 | 432 | PyAPI_FUNC(void) _PyObject_Dump(PyObject *); | |
| 433 | 433 | PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *); | |
| 434 | - PyAPI_FUNC(PyObject *) PyObject_ReprStr8(PyObject *); | ||
| 435 | - PyAPI_FUNC(PyObject *) _PyObject_Str(PyObject *); | ||
| 436 | 434 | PyAPI_FUNC(PyObject *) PyObject_Str(PyObject *); | |
| 437 | - PyAPI_FUNC(PyObject *) PyObject_Unicode(PyObject *); | ||
| 435 | + #define PyObject_Unicode PyObject_Str /* Compatibility */ | ||
| 438 | 436 | PyAPI_FUNC(int) PyObject_Compare(PyObject *, PyObject *); | |
| 439 | 437 | PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int); | |
| 440 | 438 | PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int); | |
@@ -478,7 +476,7 @@ PyAPI_FUNC(long) _Py_HashDouble(double); | |||
| 478 | 476 | PyAPI_FUNC(long) _Py_HashPointer(void*); | |
| 479 | 477 | ||
| 480 | 478 | /* Helper for passing objects to printf and the like */ | |
| 481 | - #define PyObject_REPR(obj) PyString_AS_STRING(PyObject_ReprStr8(obj)) | ||
| 479 | + #define PyObject_REPR(obj) PyUnicode_AsString(PyObject_Repr(obj)) | ||
| 482 | 480 | ||
| 483 | 481 | /* Flag bits for printing: */ | |
| 484 | 482 | #define Py_PRINT_RAW 1 /* No string quotes etc. */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,7 +65,7 @@ extern "C" { | |||
| 65 | 65 | ||
| 66 | 66 | #define RETURN_VALUE 83 | |
| 67 | 67 | #define IMPORT_STAR 84 | |
| 68 | - #define MAKE_BYTES 85 | ||
| 68 | + | ||
| 69 | 69 | #define YIELD_VALUE 86 | |
| 70 | 70 | #define POP_BLOCK 87 | |
| 71 | 71 | #define END_FINALLY 88 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ PyAPI_DATA(int) Py_InteractiveFlag; | |||
| 11 | 11 | PyAPI_DATA(int) Py_InspectFlag; | |
| 12 | 12 | PyAPI_DATA(int) Py_OptimizeFlag; | |
| 13 | 13 | PyAPI_DATA(int) Py_NoSiteFlag; | |
| 14 | + PyAPI_DATA(int) Py_BytesWarningFlag; | ||
| 14 | 15 | PyAPI_DATA(int) Py_UseClassExceptionsFlag; | |
| 15 | 16 | PyAPI_DATA(int) Py_FrozenFlag; | |
| 16 | 17 | PyAPI_DATA(int) Py_TabcheckFlag; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments