string containing raw data - PyArg_ParseTuple() bug?

Fredrik Lundh fredrik at pythonware.com
Thu May 6 10:09:33 EDT 1999


Richard Bouska <xbouska at infima.cz> wrote:
> but I got the folowing error:
> 
> lo.write(buf)
> TypeError: write(buffer), with buffer (sized string)
> 
> The proble arises only if the source file are raw data for ASCII texts
> is the script working well.
> 
> The part of the c underlying c code:
>   /* gets arguments */
>         if (!PyArg_ParseTuple (args, "s", &buffer))
>         {
>                 PyErr_SetString(PyExc_TypeError,
>                                 "write(buffer), with buffer (sized
> string).");
>                 return NULL;
>         }
> 
> If I understat it corectly thr problem is in the PyArg_ParseTuple
> function. 

    "programming rule #12: real programmers never make mis-
    takes.  if you stumble upon a strange problem, blame it
    on someone else."

your C code is replacing the error message generated by
PyArg_ParseTuple with a different message.  if you remove
that extra call to SetString, you'll get the original message
instead:

  expected string without null bytes

that is, the C code isn't expecting binary data.  if it were,
it would use "s#" instead.  see the extension handbook for
more details.

</F>





More information about the Python-list mailing list