[Python-Dev] PEP-393: request for keeping PyUnicode_EncodeDecimal()

Stefan Krah stefan at bytereef.org
Sun Oct 2 13:04:16 CEST 2011


"Martin v. Löwis" <martin at v.loewis.de> wrote:
> > longobject.c still used PyUnicode_EncodeDecimal() until 10 months
> > ago (8304bd765bcf). I missed the PyUnicode_TransformDecimalToASCII()
> > commit, probably because #10557 is still open.
> > 
> > That's why I wouldn't like to implement the function myself at least
> > until the API is settled.
> 
> I don't understand. If you implement it yourself, you don't have to
> worry at all what the API is.

What I'm looking for is a public function that is silently updated if
python-dev decides to accept other numerical input. As I understand
from your comments below, PyUnicode_EncodeDecimal() is frozen, so
that function does indeed not help.

I would consider it reasonable for PyUnicode_TransformDecimalAndSpaceToASCII()
to be documented as:

  "This function might accept different numerical input in the future."


The reason is that some people would like to accept additional input
(see #6632), while others would like to restrict input. If there is
a function that will always track whatever will be decided, extension
authors don't have to worry about being up-to-date.



>    out = malloc(PyUnicode_GET_LENGTH(in)+1);
>    for (i = 0; i < PyUnicode_GET_LENGTH(in); i++) {
>        Py_UCS4 ch = PyUnicode_READ_CHAR(in, i);
>        int d = Py_UNICODE_TODIGIT(ch);
>        if (d != -1) {
>           out[i] == '0'+d;
>           continue;
>        }
>        if (ch < 128)
>           out[i] = ch;
>        else {
>           error();
>           return;
>        }
>    }
>    out[i] = '\0';

Thanks for that. I think alternative leading and trailing whitespace would
need to be handled as well: Decimal("\u180E1.233").


> > Will PyUnicode_TransformDecimalAndSpaceToASCII() be public?
> 
> It's already included in 3.2, so it can't be removed that easily.
> I wish it had been private, though - we have way too many API functions
> dealing with Unicode.

I can find PyUnicode_TransformDecimalToASCII() in 3.2, but not
PyUnicode_TransformDecimalAndSpaceToASCII().



Stefan Krah




More information about the Python-Dev mailing list