mirror of https://github.com/python/cpython.git
Merged revisions 81811 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r81811 | victor.stinner | 2010-06-07 23:20:41 +0200 (lun., 07 juin 2010) | 9 lines Issue #8925: fix types of Py_Parse*() and Py_BuildValue() functions * Add links to Python types * Replace "string" by bytes or str * Replace "long" by "int" * Specify the default encoding * Fix reST syntax ("..note ::") * etc. ........
This commit is contained in:
parent
d67cb78f18
commit
4704881235
|
@ -53,13 +53,13 @@ Unless otherwise stated, buffers are not NUL-terminated.
|
||||||
drop int support. It is best to always define :cmacro:`PY_SSIZE_T_CLEAN`.
|
drop int support. It is best to always define :cmacro:`PY_SSIZE_T_CLEAN`.
|
||||||
|
|
||||||
|
|
||||||
``s`` (Unicode object) [const char \*]
|
``s`` (:class:`str`) [const char \*]
|
||||||
Convert a Unicode object to a C pointer to a character string.
|
Convert a Unicode object to a C pointer to a character string.
|
||||||
A pointer to an existing string is stored in the character pointer
|
A pointer to an existing string is stored in the character pointer
|
||||||
variable whose address you pass. The C string is NUL-terminated.
|
variable whose address you pass. The C string is NUL-terminated.
|
||||||
The Python string must not contain embedded NUL bytes; if it does,
|
The Python string must not contain embedded NUL bytes; if it does,
|
||||||
a :exc:`TypeError` exception is raised. Unicode objects are converted
|
a :exc:`TypeError` exception is raised. Unicode objects are converted
|
||||||
to C strings using the default encoding. If this conversion fails, a
|
to C strings using ``'utf-8'`` encoding. If this conversion fails, a
|
||||||
:exc:`UnicodeError` is raised.
|
:exc:`UnicodeError` is raised.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
@ -68,111 +68,112 @@ Unless otherwise stated, buffers are not NUL-terminated.
|
||||||
preferrable to use the ``O&`` format with :cfunc:`PyUnicode_FSConverter`
|
preferrable to use the ``O&`` format with :cfunc:`PyUnicode_FSConverter`
|
||||||
as *converter*.
|
as *converter*.
|
||||||
|
|
||||||
``s*`` (Unicode object or any 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 objects supporting the
|
||||||
buffer protocol (such as :class:`bytes` or :class:`bytearray` objects).
|
buffer protocol.
|
||||||
It fills a :ctype:`Py_buffer` structure provided by the caller.
|
It fills a :ctype:`Py_buffer` structure provided by the caller.
|
||||||
Unicode objects are converted to C strings using the default encoding.
|
|
||||||
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.
|
||||||
|
|
||||||
``s#`` (string, Unicode or any read buffer compatible object) [const char \*, int or :ctype:`Py_ssize_t`]
|
``s#`` (:class:`str`, :class:`bytes` or read-only buffer compatible object) [const char \*, int or :ctype:`Py_ssize_t`]
|
||||||
Like ``s*``, except that it doesn't accept mutable buffer-like objects
|
Like ``s*``, except that it doesn't accept mutable buffer-like objects
|
||||||
such as :class:`bytearray`. The result is stored into two C variables,
|
such as :class:`bytearray`. The result is stored into two C variables,
|
||||||
the first one a pointer to a C string, the second one its length.
|
the first one a pointer to a C string, the second one its length.
|
||||||
The string may contain embedded null bytes.
|
The string may contain embedded null bytes. Unicode objects are converted
|
||||||
|
to C strings using ``'utf-8'`` encoding.
|
||||||
|
|
||||||
``z`` (Unicode object or ``None``) [const char \*]
|
``z`` (:class:`str` or ``None``) [const char \*]
|
||||||
Like ``s``, but the Python object may also be ``None``, in which case the C
|
Like ``s``, but the Python object may also be ``None``, in which case the C
|
||||||
pointer is set to *NULL*.
|
pointer is set to *NULL*.
|
||||||
|
|
||||||
``z*`` (Unicode object or ``None`` or any buffer compatible object) [Py_buffer]
|
``z*`` (:class:`str`, :class:`bytes`, :class:`bytearray`, buffer compatible object or ``None``) [Py_buffer]
|
||||||
Like ``s*``, but the Python object may also be ``None``, in which case the
|
Like ``s*``, but the Python object may also be ``None``, in which case the
|
||||||
``buf`` member of the :ctype:`Py_buffer` structure is set to *NULL*.
|
``buf`` member of the :ctype:`Py_buffer` structure is set to *NULL*.
|
||||||
|
|
||||||
``z#`` (Unicode object or ``None`` or any read buffer compatible object) [const char \*, int]
|
``z#`` (:class:`str`, :class:`bytes`, read-only buffer compatible object or ``None``) [const char \*, int]
|
||||||
Like ``s#``, but the Python object may also be ``None``, in which case the C
|
Like ``s#``, but the Python object may also be ``None``, in which case the C
|
||||||
pointer is set to *NULL*.
|
pointer is set to *NULL*.
|
||||||
|
|
||||||
``y`` (bytes object) [const char \*]
|
``y`` (:class:`bytes`) [const char \*]
|
||||||
This format converts a bytes-like object to a C pointer to a character
|
This format converts a bytes-like object to a C pointer to a character
|
||||||
string; it does not accept Unicode objects. The bytes buffer must not
|
string; it does not accept Unicode objects. The bytes buffer must not
|
||||||
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*`` (any buffer compatible object) [Py_buffer \*]
|
``y*`` (:class:`bytes`, :class:`bytearray` or buffer compatible object) [Py_buffer \*]
|
||||||
This variant on ``s*`` doesn't accept Unicode objects, only objects
|
This variant on ``s*`` doesn't accept Unicode objects, only objects
|
||||||
supporting the buffer protocol. **This is the recommended way to accept
|
supporting the buffer protocol. **This is the recommended way to accept
|
||||||
binary data.**
|
binary data.**
|
||||||
|
|
||||||
``y#`` (bytes object) [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 bytes-like
|
||||||
objects.
|
objects.
|
||||||
|
|
||||||
``S`` (bytes object) [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
|
||||||
attempting any conversion. Raises :exc:`TypeError` if the object is not
|
attempting any conversion. Raises :exc:`TypeError` if the object is not
|
||||||
a bytes object. The C variable may also be declared as :ctype:`PyObject\*`.
|
a bytes object. The C variable may also be declared as :ctype:`PyObject\*`.
|
||||||
|
|
||||||
``Y`` (bytearray object) [PyByteArrayObject \*]
|
``Y`` (:class:`bytearray`) [PyByteArrayObject \*]
|
||||||
Requires that the Python object is a :class:`bytearray` object, without
|
Requires that the Python object is a :class:`bytearray` object, without
|
||||||
attempting any conversion. Raises :exc:`TypeError` if the object is not
|
attempting any conversion. Raises :exc:`TypeError` if the object is not
|
||||||
a bytearray object. The C variable may also be declared as :ctype:`PyObject\*`.
|
a :class:`bytearray` object. The C variable may also be declared as :ctype:`PyObject\*`.
|
||||||
|
|
||||||
``u`` (Unicode object) [Py_UNICODE \*]
|
``u`` (:class:`str`) [Py_UNICODE \*]
|
||||||
Convert a Python Unicode object to a C pointer to a NUL-terminated buffer of
|
Convert a Python Unicode object to a C pointer to a NUL-terminated buffer of
|
||||||
Unicode characters. You must pass the address of a :ctype:`Py_UNICODE`
|
Unicode characters. You must pass the address of a :ctype:`Py_UNICODE`
|
||||||
pointer variable, which will be filled with the pointer to an existing
|
pointer variable, which will be filled with the pointer to an existing
|
||||||
Unicode buffer. Please note that the width of a :ctype:`Py_UNICODE`
|
Unicode buffer. Please note that the width of a :ctype:`Py_UNICODE`
|
||||||
character depends on compilation options (it is either 16 or 32 bits).
|
character depends on compilation options (it is either 16 or 32 bits).
|
||||||
|
|
||||||
..note ::
|
.. note::
|
||||||
Since ``u`` doesn't give you back the length of the string, and it
|
Since ``u`` doesn't give you back the length of the string, and it
|
||||||
may contain embedded NUL characters, it is recommended to use ``u#``
|
may contain embedded NUL characters, it is recommended to use ``u#``
|
||||||
or ``U`` instead.
|
or ``U`` instead.
|
||||||
|
|
||||||
``u#`` (Unicode object) [Py_UNICODE \*, int]
|
``u#`` (:class:`str`) [Py_UNICODE \*, int]
|
||||||
This variant on ``u`` stores into two C variables, the first one a pointer to a
|
This variant on ``u`` stores into two C variables, the first one a pointer to a
|
||||||
Unicode data buffer, the second one its length. Non-Unicode objects are handled
|
Unicode data buffer, the second one its length. Non-Unicode objects are handled
|
||||||
by interpreting their read-buffer pointer as pointer to a :ctype:`Py_UNICODE`
|
by interpreting their read-buffer pointer as pointer to a :ctype:`Py_UNICODE`
|
||||||
array.
|
array.
|
||||||
|
|
||||||
``Z`` (Unicode or ``None``) [Py_UNICODE \*]
|
``Z`` (:class:`str` or ``None``) [Py_UNICODE \*]
|
||||||
Like ``u``, but the Python object may also be ``None``, in which case the
|
Like ``u``, but the Python object may also be ``None``, in which case the
|
||||||
:ctype:`Py_UNICODE` pointer is set to *NULL*.
|
:ctype:`Py_UNICODE` pointer is set to *NULL*.
|
||||||
|
|
||||||
``Z#`` (Unicode or ``None``) [Py_UNICODE \*, int]
|
``Z#`` (:class:`str` or ``None``) [Py_UNICODE \*, int]
|
||||||
Like ``u#``, but the Python object may also be ``None``, in which case the
|
Like ``u#``, but the Python object may also be ``None``, in which case the
|
||||||
:ctype:`Py_UNICODE` pointer is set to *NULL*.
|
:ctype:`Py_UNICODE` pointer is set to *NULL*.
|
||||||
|
|
||||||
``U`` (Unicode object) [PyUnicodeObject \*]
|
``U`` (:class:`str`) [PyUnicodeObject \*]
|
||||||
Requires that the Python object is a Unicode object, without attempting
|
Requires that the Python object is a Unicode object, without attempting
|
||||||
any conversion. Raises :exc:`TypeError` if the object is not a Unicode
|
any conversion. Raises :exc:`TypeError` if the object is not a Unicode
|
||||||
object. The C variable may also be declared as :ctype:`PyObject\*`.
|
object. The C variable may also be declared as :ctype:`PyObject\*`.
|
||||||
|
|
||||||
``t#`` (read-only character buffer) [char \*, int]
|
``t#`` (:class:`bytes`, :class:`bytearray` or read-only character buffer) [char \*, int]
|
||||||
Like ``s#``, but accepts any object which implements the read-only buffer
|
Like ``s#``, but accepts any object which implements the read-only buffer
|
||||||
interface. The :ctype:`char\*` variable is set to point to the first byte of
|
interface. The :ctype:`char\*` variable is set to point to the first byte of
|
||||||
the buffer, and the :ctype:`int` is set to the length of the buffer. Only
|
the buffer, and the :ctype:`int` is set to the length of the buffer. Only
|
||||||
single-segment buffer objects are accepted; :exc:`TypeError` is raised for all
|
single-segment buffer objects are accepted; :exc:`TypeError` is raised for all
|
||||||
others.
|
others.
|
||||||
|
|
||||||
``w`` (read-write character buffer) [char \*]
|
``w`` (:class:`bytearray` or read-write character buffer) [char \*]
|
||||||
Similar to ``s``, but accepts any object which implements the read-write buffer
|
Similar to ``s``, but accepts any object which implements the read-write buffer
|
||||||
interface. The caller must determine the length of the buffer by other means,
|
interface. The caller must determine the length of the buffer by other means,
|
||||||
or use ``w#`` instead. Only single-segment buffer objects are accepted;
|
or use ``w#`` instead. Only single-segment buffer objects are accepted;
|
||||||
:exc:`TypeError` is raised for all others.
|
:exc:`TypeError` is raised for all others.
|
||||||
|
|
||||||
``w*`` (read-write byte-oriented buffer) [Py_buffer]
|
``w*`` (:class:`bytearray` or read-write byte-oriented buffer) [Py_buffer]
|
||||||
This is to ``w`` what ``s*`` is to ``s``.
|
This is to ``w`` what ``s*`` is to ``s``.
|
||||||
|
|
||||||
``w#`` (read-write character buffer) [char \*, int]
|
``w#`` (:class:`bytearray` or read-write character buffer) [char \*, int]
|
||||||
Like ``s#``, but accepts any object which implements the read-write buffer
|
Like ``s#``, but accepts any object which implements the read-write buffer
|
||||||
interface. The :ctype:`char \*` variable is set to point to the first byte
|
interface. The :ctype:`char \*` variable is set to point to the first byte
|
||||||
of the buffer, and the :ctype:`int` is set to the length of the buffer.
|
of the buffer, and the :ctype:`int` is set to the length of the buffer.
|
||||||
Only single-segment buffer objects are accepted; :exc:`TypeError` is raised
|
Only single-segment buffer objects are accepted; :exc:`TypeError` is raised
|
||||||
for all others.
|
for all others.
|
||||||
|
|
||||||
``es`` (string, Unicode object or character buffer compatible object) [const char \*encoding, char \*\*buffer]
|
``es`` (:class:`str`) [const char \*encoding, char \*\*buffer]
|
||||||
This variant on ``s`` is used for encoding Unicode and objects convertible to
|
This variant on ``s`` is used for encoding Unicode and objects convertible to
|
||||||
Unicode into a character buffer. It only works for encoded data without embedded
|
Unicode into a character buffer. It only works for encoded data without embedded
|
||||||
NUL bytes.
|
NUL bytes.
|
||||||
|
@ -190,12 +191,12 @@ Unless otherwise stated, buffers are not NUL-terminated.
|
||||||
allocated storage. The caller is responsible for calling :cfunc:`PyMem_Free` to
|
allocated storage. The caller is responsible for calling :cfunc:`PyMem_Free` to
|
||||||
free the allocated buffer after use.
|
free the allocated buffer after use.
|
||||||
|
|
||||||
``et`` (string, Unicode object or character buffer compatible object) [const char \*encoding, char \*\*buffer]
|
``et`` (:class:`str`, :class:`bytes` or :class:`bytearray`) [const char \*encoding, char \*\*buffer]
|
||||||
Same as ``es`` except that 8-bit string objects are passed through without
|
Same as ``es`` except that byte string objects are passed through without
|
||||||
recoding them. Instead, the implementation assumes that the string object uses
|
recoding them. Instead, the implementation assumes that the byte string object uses
|
||||||
the encoding passed in as parameter.
|
the encoding passed in as parameter.
|
||||||
|
|
||||||
``es#`` (string, Unicode object or character buffer compatible object) [const char \*encoding, char \*\*buffer, int \*buffer_length]
|
``es#`` (:class:`str`) [const char \*encoding, char \*\*buffer, int \*buffer_length]
|
||||||
This variant on ``s#`` is used for encoding Unicode and objects convertible to
|
This variant on ``s#`` is used for encoding Unicode and objects convertible to
|
||||||
Unicode into a character buffer. Unlike the ``es`` format, this variant allows
|
Unicode into a character buffer. Unlike the ``es`` format, this variant allows
|
||||||
input data which contains NUL characters.
|
input data which contains NUL characters.
|
||||||
|
@ -226,71 +227,71 @@ Unless otherwise stated, buffers are not NUL-terminated.
|
||||||
In both cases, *\*buffer_length* is set to the length of the encoded data
|
In both cases, *\*buffer_length* is set to the length of the encoded data
|
||||||
without the trailing NUL byte.
|
without the trailing NUL byte.
|
||||||
|
|
||||||
``et#`` (string, Unicode object or character buffer compatible object) [const char \*encoding, char \*\*buffer, int \*buffer_length]
|
``et#`` (:class:`str`, :class:`bytes` or :class:`bytearray`) [const char \*encoding, char \*\*buffer, int \*buffer_length]
|
||||||
Same as ``es#`` except that string objects are passed through without recoding
|
Same as ``es#`` except that byte string objects are passed through without recoding
|
||||||
them. Instead, the implementation assumes that the string object uses the
|
them. Instead, the implementation assumes that the byte string object uses the
|
||||||
encoding passed in as parameter.
|
encoding passed in as parameter.
|
||||||
|
|
||||||
Numbers
|
Numbers
|
||||||
-------
|
-------
|
||||||
|
|
||||||
``b`` (integer) [unsigned char]
|
``b`` (:class:`int`) [unsigned char]
|
||||||
Convert a nonnegative Python integer to an unsigned tiny int, stored in a C
|
Convert a nonnegative Python integer to an unsigned tiny int, stored in a C
|
||||||
:ctype:`unsigned char`.
|
:ctype:`unsigned char`.
|
||||||
|
|
||||||
``B`` (integer) [unsigned char]
|
``B`` (:class:`int`) [unsigned char]
|
||||||
Convert a Python integer to a tiny int without overflow checking, stored in a C
|
Convert a Python integer to a tiny int without overflow checking, stored in a C
|
||||||
:ctype:`unsigned char`.
|
:ctype:`unsigned char`.
|
||||||
|
|
||||||
``h`` (integer) [short int]
|
``h`` (:class:`int`) [short int]
|
||||||
Convert a Python integer to a C :ctype:`short int`.
|
Convert a Python integer to a C :ctype:`short int`.
|
||||||
|
|
||||||
``H`` (integer) [unsigned short int]
|
``H`` (:class:`int`) [unsigned short int]
|
||||||
Convert a Python integer to a C :ctype:`unsigned short int`, without overflow
|
Convert a Python integer to a C :ctype:`unsigned short int`, without overflow
|
||||||
checking.
|
checking.
|
||||||
|
|
||||||
``i`` (integer) [int]
|
``i`` (:class:`int`) [int]
|
||||||
Convert a Python integer to a plain C :ctype:`int`.
|
Convert a Python integer to a plain C :ctype:`int`.
|
||||||
|
|
||||||
``I`` (integer) [unsigned int]
|
``I`` (:class:`int`) [unsigned int]
|
||||||
Convert a Python integer to a C :ctype:`unsigned int`, without overflow
|
Convert a Python integer to a C :ctype:`unsigned int`, without overflow
|
||||||
checking.
|
checking.
|
||||||
|
|
||||||
``l`` (integer) [long int]
|
``l`` (:class:`int`) [long int]
|
||||||
Convert a Python integer to a C :ctype:`long int`.
|
Convert a Python integer to a C :ctype:`long int`.
|
||||||
|
|
||||||
``k`` (integer) [unsigned long]
|
``k`` (:class:`int`) [unsigned long]
|
||||||
Convert a Python integer to a C :ctype:`unsigned long` without
|
Convert a Python integer to a C :ctype:`unsigned long` without
|
||||||
overflow checking.
|
overflow checking.
|
||||||
|
|
||||||
``L`` (integer) [PY_LONG_LONG]
|
``L`` (:class:`int`) [PY_LONG_LONG]
|
||||||
Convert a Python integer to a C :ctype:`long long`. This format is only
|
Convert a Python integer to a C :ctype:`long long`. This format is only
|
||||||
available on platforms that support :ctype:`long long` (or :ctype:`_int64` on
|
available on platforms that support :ctype:`long long` (or :ctype:`_int64` on
|
||||||
Windows).
|
Windows).
|
||||||
|
|
||||||
``K`` (integer) [unsigned PY_LONG_LONG]
|
``K`` (:class:`int`) [unsigned PY_LONG_LONG]
|
||||||
Convert a Python integer to a C :ctype:`unsigned long long`
|
Convert a Python integer to a C :ctype:`unsigned long long`
|
||||||
without overflow checking. This format is only available on platforms that
|
without overflow checking. This format is only available on platforms that
|
||||||
support :ctype:`unsigned long long` (or :ctype:`unsigned _int64` on Windows).
|
support :ctype:`unsigned long long` (or :ctype:`unsigned _int64` on Windows).
|
||||||
|
|
||||||
``n`` (integer) [Py_ssize_t]
|
``n`` (:class:`int`) [Py_ssize_t]
|
||||||
Convert a Python integer to a C :ctype:`Py_ssize_t`.
|
Convert a Python integer to a C :ctype:`Py_ssize_t`.
|
||||||
|
|
||||||
``c`` (bytes object of length 1) [char]
|
``c`` (:class:`bytes` of length 1) [char]
|
||||||
Convert a Python byte, represented as a :class:`bytes` object of length 1,
|
Convert a Python byte, represented as a :class:`bytes` object of length 1,
|
||||||
to a C :ctype:`char`.
|
to a C :ctype:`char`.
|
||||||
|
|
||||||
``C`` (Unicode object of length 1) [int]
|
``C`` (:class:`str` of length 1) [int]
|
||||||
Convert a Python character, represented as a :class:`str`: object of
|
Convert a Python character, represented as a :class:`str` object of
|
||||||
length 1, to a C :ctype:`int`.
|
length 1, to a C :ctype:`int`.
|
||||||
|
|
||||||
``f`` (float) [float]
|
``f`` (:class:`float`) [float]
|
||||||
Convert a Python floating point number to a C :ctype:`float`.
|
Convert a Python floating point number to a C :ctype:`float`.
|
||||||
|
|
||||||
``d`` (float) [double]
|
``d`` (:class:`float`) [double]
|
||||||
Convert a Python floating point number to a C :ctype:`double`.
|
Convert a Python floating point number to a C :ctype:`double`.
|
||||||
|
|
||||||
``D`` (complex) [Py_complex]
|
``D`` (:class:`complex`) [Py_complex]
|
||||||
Convert a Python complex number to a C :ctype:`Py_complex` structure.
|
Convert a Python complex number to a C :ctype:`Py_complex` structure.
|
||||||
|
|
||||||
Other objects
|
Other objects
|
||||||
|
@ -330,7 +331,7 @@ Other objects
|
||||||
.. versionchanged:: 3.1
|
.. versionchanged:: 3.1
|
||||||
Py_CLEANUP_SUPPORTED was added.
|
Py_CLEANUP_SUPPORTED was added.
|
||||||
|
|
||||||
``(items)`` (tuple) [*matching-items*]
|
``(items)`` (:class:`tuple`) [*matching-items*]
|
||||||
The object must be a Python sequence whose length is the number of format units
|
The object must be a Python sequence whose length is the number of format units
|
||||||
in *items*. The C arguments must correspond to the individual format units in
|
in *items*. The C arguments must correspond to the individual format units in
|
||||||
*items*. Format units for sequences may be nested.
|
*items*. Format units for sequences may be nested.
|
||||||
|
@ -489,95 +490,96 @@ Building values
|
||||||
not within format units such as ``s#``). This can be used to make long format
|
not within format units such as ``s#``). This can be used to make long format
|
||||||
strings a tad more readable.
|
strings a tad more readable.
|
||||||
|
|
||||||
``s`` (string) [char \*]
|
``s`` (:class:`str` or ``None``) [char \*]
|
||||||
Convert a null-terminated C string to a Python object. If the C string pointer
|
Convert a null-terminated C string to a Python object using ``'utf-8'``
|
||||||
is *NULL*, ``None`` is used.
|
encoding. If the C string pointer is *NULL*, ``None`` is used.
|
||||||
|
|
||||||
``s#`` (string) [char \*, int]
|
``s#`` (:class:`str` or ``None``) [char \*, int]
|
||||||
Convert a C string and its length to a Python object. If the C string pointer
|
Convert a C string and its length to a Python object using ``'utf-8'``
|
||||||
is *NULL*, the length is ignored and ``None`` is returned.
|
encoding. If the C string pointer is *NULL*, the length is ignored and
|
||||||
|
``None`` is returned.
|
||||||
|
|
||||||
``y`` (bytes) [char \*]
|
``y`` (:class:`bytes`) [char \*]
|
||||||
This converts a C string to a Python :func:`bytes` object. If the C
|
This converts a C string to a Python :func:`bytes` object. If the C
|
||||||
string pointer is *NULL*, ``None`` is returned.
|
string pointer is *NULL*, ``None`` is returned.
|
||||||
|
|
||||||
``y#`` (bytes) [char \*, int]
|
``y#`` (:class:`bytes`) [char \*, int]
|
||||||
This converts a C string and its lengths to a Python object. If the C
|
This converts a C string and its lengths to a Python object. If the C
|
||||||
string pointer is *NULL*, ``None`` is returned.
|
string pointer is *NULL*, ``None`` is returned.
|
||||||
|
|
||||||
``z`` (string or ``None``) [char \*]
|
``z`` (:class:`str` or ``None``) [char \*]
|
||||||
Same as ``s``.
|
Same as ``s``.
|
||||||
|
|
||||||
``z#`` (string or ``None``) [char \*, int]
|
``z#`` (:class:`str` or ``None``) [char \*, int]
|
||||||
Same as ``s#``.
|
Same as ``s#``.
|
||||||
|
|
||||||
``u`` (Unicode string) [Py_UNICODE \*]
|
``u`` (:class:`str`) [Py_UNICODE \*]
|
||||||
Convert a null-terminated buffer of Unicode (UCS-2 or UCS-4) data to a Python
|
Convert a null-terminated buffer of Unicode (UCS-2 or UCS-4) data to a Python
|
||||||
Unicode object. If the Unicode buffer pointer is *NULL*, ``None`` is returned.
|
Unicode object. If the Unicode buffer pointer is *NULL*, ``None`` is returned.
|
||||||
|
|
||||||
``u#`` (Unicode string) [Py_UNICODE \*, int]
|
``u#`` (:class:`str`) [Py_UNICODE \*, int]
|
||||||
Convert a Unicode (UCS-2 or UCS-4) data buffer and its length to a Python
|
Convert a Unicode (UCS-2 or UCS-4) data buffer and its length to a Python
|
||||||
Unicode object. If the Unicode buffer pointer is *NULL*, the length is ignored
|
Unicode object. If the Unicode buffer pointer is *NULL*, the length is ignored
|
||||||
and ``None`` is returned.
|
and ``None`` is returned.
|
||||||
|
|
||||||
``U`` (string) [char \*]
|
``U`` (:class:`str` or ``None``) [char \*]
|
||||||
Convert a null-terminated C string to a Python unicode object. If the C string
|
Convert a null-terminated C string to a Python unicode object. If the C string
|
||||||
pointer is *NULL*, ``None`` is used.
|
pointer is *NULL*, ``None`` is used.
|
||||||
|
|
||||||
``U#`` (string) [char \*, int]
|
``U#`` (:class:`str` or ``None``) [char \*, int]
|
||||||
Convert a C string and its length to a Python unicode object. If the C string
|
Convert a C string and its length to a Python unicode object. If the C string
|
||||||
pointer is *NULL*, the length is ignored and ``None`` is returned.
|
pointer is *NULL*, the length is ignored and ``None`` is returned.
|
||||||
|
|
||||||
``i`` (integer) [int]
|
``i`` (:class:`int`) [int]
|
||||||
Convert a plain C :ctype:`int` to a Python integer object.
|
Convert a plain C :ctype:`int` to a Python integer object.
|
||||||
|
|
||||||
``b`` (integer) [char]
|
``b`` (:class:`int`) [char]
|
||||||
Convert a plain C :ctype:`char` to a Python integer object.
|
Convert a plain C :ctype:`char` to a Python integer object.
|
||||||
|
|
||||||
``h`` (integer) [short int]
|
``h`` (:class:`int`) [short int]
|
||||||
Convert a plain C :ctype:`short int` to a Python integer object.
|
Convert a plain C :ctype:`short int` to a Python integer object.
|
||||||
|
|
||||||
``l`` (integer) [long int]
|
``l`` (:class:`int`) [long int]
|
||||||
Convert a C :ctype:`long int` to a Python integer object.
|
Convert a C :ctype:`long int` to a Python integer object.
|
||||||
|
|
||||||
``B`` (integer) [unsigned char]
|
``B`` (:class:`int`) [unsigned char]
|
||||||
Convert a C :ctype:`unsigned char` to a Python integer object.
|
Convert a C :ctype:`unsigned char` to a Python integer object.
|
||||||
|
|
||||||
``H`` (integer) [unsigned short int]
|
``H`` (:class:`int`) [unsigned short int]
|
||||||
Convert a C :ctype:`unsigned short int` to a Python integer object.
|
Convert a C :ctype:`unsigned short int` to a Python integer object.
|
||||||
|
|
||||||
``I`` (integer) [unsigned int]
|
``I`` (:class:`int`) [unsigned int]
|
||||||
Convert a C :ctype:`unsigned int` to a Python integer object.
|
Convert a C :ctype:`unsigned int` to a Python integer object.
|
||||||
|
|
||||||
``k`` (integer) [unsigned long]
|
``k`` (:class:`int`) [unsigned long]
|
||||||
Convert a C :ctype:`unsigned long` to a Python integer object.
|
Convert a C :ctype:`unsigned long` to a Python integer object.
|
||||||
|
|
||||||
``L`` (long) [PY_LONG_LONG]
|
``L`` (:class:`int`) [PY_LONG_LONG]
|
||||||
Convert a C :ctype:`long long` to a Python integer object. Only available
|
Convert a C :ctype:`long long` to a Python integer object. Only available
|
||||||
on platforms that support :ctype:`long long`.
|
on platforms that support :ctype:`long long`.
|
||||||
|
|
||||||
``K`` (long) [unsigned PY_LONG_LONG]
|
``K`` (:class:`int`) [unsigned PY_LONG_LONG]
|
||||||
Convert a C :ctype:`unsigned long long` to a Python integer object. Only
|
Convert a C :ctype:`unsigned long long` to a Python integer object. Only
|
||||||
available on platforms that support :ctype:`unsigned long long`.
|
available on platforms that support :ctype:`unsigned long long`.
|
||||||
|
|
||||||
``n`` (int) [Py_ssize_t]
|
``n`` (:class:`int`) [Py_ssize_t]
|
||||||
Convert a C :ctype:`Py_ssize_t` to a Python integer.
|
Convert a C :ctype:`Py_ssize_t` to a Python integer.
|
||||||
|
|
||||||
``c`` (string of length 1) [char]
|
``c`` (:class:`bytes` of length 1) [char]
|
||||||
Convert a C :ctype:`int` representing a byte to a Python byte string of
|
Convert a C :ctype:`int` representing a byte to a Python :class:`bytes` object of
|
||||||
length 1.
|
length 1.
|
||||||
|
|
||||||
``C`` (string of length 1) [int]
|
``C`` (:class:`str` of length 1) [int]
|
||||||
Convert a C :ctype:`int` representing a character to Python unicode
|
Convert a C :ctype:`int` representing a character to Python :class:`str`
|
||||||
string of length 1.
|
object of length 1.
|
||||||
|
|
||||||
``d`` (float) [double]
|
``d`` (:class:`float`) [double]
|
||||||
Convert a C :ctype:`double` to a Python floating point number.
|
Convert a C :ctype:`double` to a Python floating point number.
|
||||||
|
|
||||||
``f`` (float) [float]
|
``f`` (:class:`float`) [float]
|
||||||
Same as ``d``.
|
Convert a C :ctype:`float` to a Python floating point number.
|
||||||
|
|
||||||
``D`` (complex) [Py_complex \*]
|
``D`` (:class:`complex`) [Py_complex \*]
|
||||||
Convert a C :ctype:`Py_complex` structure to a Python complex number.
|
Convert a C :ctype:`Py_complex` structure to a Python complex number.
|
||||||
|
|
||||||
``O`` (object) [PyObject \*]
|
``O`` (object) [PyObject \*]
|
||||||
|
@ -602,13 +604,13 @@ Building values
|
||||||
\*`) as its argument and should return a "new" Python object, or *NULL* if an
|
\*`) as its argument and should return a "new" Python object, or *NULL* if an
|
||||||
error occurred.
|
error occurred.
|
||||||
|
|
||||||
``(items)`` (tuple) [*matching-items*]
|
``(items)`` (:class:`tuple`) [*matching-items*]
|
||||||
Convert a sequence of C values to a Python tuple with the same number of items.
|
Convert a sequence of C values to a Python tuple with the same number of items.
|
||||||
|
|
||||||
``[items]`` (list) [*matching-items*]
|
``[items]`` (:class:`list`) [*matching-items*]
|
||||||
Convert a sequence of C values to a Python list with the same number of items.
|
Convert a sequence of C values to a Python list with the same number of items.
|
||||||
|
|
||||||
``{items}`` (dictionary) [*matching-items*]
|
``{items}`` (:class:`dict`) [*matching-items*]
|
||||||
Convert a sequence of C values to a Python dictionary. Each pair of consecutive
|
Convert a sequence of C values to a Python dictionary. Each pair of consecutive
|
||||||
C values adds one item to the dictionary, serving as key and value,
|
C values adds one item to the dictionary, serving as key and value,
|
||||||
respectively.
|
respectively.
|
||||||
|
|
Loading…
Reference in New Issue