This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Add support of bytes objects in PyBytes_FromFormatV()
Type: Stage:
Components: Interpreter Core Versions: Python 3.3
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: vstinner
Priority: normal Keywords: patch

Created on 2011-01-05 02:55 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
pybytes_fromformat_y.patch vstinner, 2011-01-05 03:34
Messages (3)
msg125398 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-01-05 02:55
It would be very practical use have a format, eg. '%y', to accept bytes object in PyBytes_FromFormatV().

Example (extracted from posixmodule.c):

        k = PyBytes_AsString(key2);
        v = PyBytes_AsString(val2);
        len = PyBytes_GET_SIZE(key2) + PyBytes_GET_SIZE(val2) + 2;
        p = PyMem_NEW(char, len);
        if (p == NULL) { PyErr_NoMemory(); ... }
        PyOS_snprintf(p, len, "%s=%s", k, v);

With %y, it can be written:

        p = PyBytes_FromFormat("%y=%y", key2, val2);
        if (p == NULL) { PyErr_NoMemory(); ... }

The '%y' may also accept bytearray and any object with the buffer interface (as the 'y' format of PyArg_Parse*() functions).
msg125401 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-01-05 03:34
Patch implementing this feature. It only supports bytes.
msg136811 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-05-24 23:43
The "%y" format is useless for the posixmodule.c example (it doesn't simplify the code), and I cannot find another usage of this feature. So let's forget it :-)
Date User Action Args
2022-04-11 14:57:10adminsetgithub: 55041
2011-05-24 23:43:47vstinnersetstatus: open -> closed
resolution: not a bug
messages: + msg136811
2011-01-05 03:34:11vstinnersetfiles: + pybytes_fromformat_y.patch

messages: + msg125401
keywords: + patch
2011-01-05 02:55:05vstinnercreate