[Zope] Don't treat .data as a big string.

Kyler B. Laird laird@ecn.purdue.edu
Thu, 21 Jun 2001 13:39:12 -0500


I learned my lesson for today, so I thought I'd
share it.

I am passing around large strings containing
PDF and PS documents.  Sometimes I make a call
like
	document = container.PJdoc(container['proposal'].data)
where the object "proposal" is a PDF file.

I end up writing this data to a temporary file
in my PJ class.  I noticed early on that I
could not simply write the whole string, but I
worked around that by writing it in 1K blocks.

I had my warning.

Today my dumb kludge came back to bite me.  We
found that some of our proposals were rejected
by the PDF parser.  I started looking at the
temporary files and noticed the problem ones
were 98798 bytes in length.  The PDF file sent
was much larger.

After some tests, I determined that asking for
a slice from .data only returns a null string
(zero length) after 98798 bytes.  This meant
that my little 1K write loop was happily going
through the "string" but it was writing 0K
blocks after awhile.

So...I finally fixed the problem.  Instead of
all of the 1K writing junk, I simply cast
whatever is passed to me into a real string.
Then I can write the whole thing without any
problems.

I'm sure this is documented somewhere that I
should have read before, but I'm hoping having
it here too saves someone some grief.

Thank you.

--kyler