mishandling of embedded NULs (was: Re: [Csv] trial zip/tar packages of csv module available)
John Machin
sjmachin at lexicon.net
Sat Feb 15 05:31:31 CET 2003
On Fri, 14 Feb 2003 18:54:08 -0600, Skip Montanaro <skip at pobox.com> wrote:
>
> John> Actually it doesn't quite treat a NUL exactly like a newline; it
> John> throws data away without any warning; see below.
>
> This is to be expected I think, considering C strings are being
> manipulated
> at the low level. I just added a check to _csv.c and an extra test. It
> now
> raises csv.Error if the file being read contains NUL bytes. (Should an
> exception be raised on output as well?)
Yes, but conditionally -- IMHO the caller should be able to specify
(strictwriting=True) that an exception should be raised on *any* attempt to
write data that could not be read back "sensibly" using the same dialect
etc. Getting exceptions or a different number of rows or columns when the
data are read back are certainly not "sensible". This general regime would
allow someone who must produce (say) a non-quoted "|"-delimited file format
to verify that there were no "|" in the data. OTOH the caller can specify
strictwriting=False if it's a "you asked for it, you got it" situation.
Cheers,
John
More information about the Csv
mailing list