[mod_python] zero terminated strings and req.write

Julián Ciccalè jciccale at mac.com
Tue Mar 9 16:47:37 EST 2004


Yes apache.OK equals 0. 

If you are using the Publisher handler, the return value of your function is
writed out on the request.
So you either write your own data to the request and not return any value,
Or return the string to be writed on the request.

Anyway, returning apache.* values is used when you define
your OWN mod_python handler.

- julian

-----Mensaje original-----
De: mod_python-bounces at modpython.org
[mailto:mod_python-bounces at modpython.org] En nombre de Frederick Grim
Enviado el: martes, 09 de marzo de 2004 15:26
Para: mod_python at modpython.org
Asunto: Re: [mod_python] zero terminated strings and req.write

Erik Stephens at <mod_python at 24ksoftware.com> replied:
> On Mon, 8 Mar 2004, Frederick Grim wrote:
> 
> > def gen_xml():
> > 	return """<?xml ... Tons of xhtml stuff here
> >
> > </html>"""
> >
> > def main(req, ERR='0'):
> > 	re.content_type = 'text/xml'
> > 	req.write(gen_xml())
> > 	return apache.OK
> >
> > The problem here is that python puts null bytes at the end of a
> > string and req.write fails with the error that there is a 0 after
> > </html>.
> 
> How does it fail?  Raises an exception?  What is the actual exception
> type and value?  It sounds strange to me cuz I've never had to worry
> about null bytes in strings in my Python travels.

okay I have tracked the problem down.  It seems that return apache.OK
adds a 0 to the output that the browser picks up so somewhere between
function and
browser mod_python leaves the zero at the end of the string.  The problem
manifested itself with a failure when content_type was set to 'text/xml'
since I
guess mod_python shoved the output through a validating parser.

	1. Is this a correct analysis
	2. Is this a bug or my misuse of mod_python
	if is_bug:
		print 'Has this been addressed?'
	else:
		fred_file_bug_report()

	heh :)
		Fred
> 
> 
> > How do I get this failure to not happen.  Even if i set content_type
> > to 'text/html' there appears a little zero at the end of my
> > script. It seems like a bug? maybe.  I am using mod_python 3.1.3
> > apache 2.0.47, and python 2.3
> 
> Dumb questions maybe, but what handler are you using?  If you're using
> the publisher handler, then maybe that zero at the end is what
> apache.OK equals?
> 
> 
> Best regards,
> Erik
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python

-- 
"Windows Longhorn will be like having a little cop right inside your
computer"
	-- Jorge Lopez, MCSE
_______________________________________________
Mod_python mailing list
Mod_python at modpython.org
http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list