quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gregory (Grisha) Trubetskoy" <gri...@apache.org>
Subject PSP opinion?
Date Sat, 24 May 2003 03:35:06 GMT

[This might take 4 minutes or more to understand]

In my experimenting with the PSP scanner, I tried to improve it by
converting text that spans multiple lines into a Python triple-quote
string. (I haven't yet checked any of this code in, so you'll just have
go by my description below).

To illustrate, *before*:

<html>
Hello World
</html>

Would result in:

req.write("<html>")
req.write("Hello world")
req.write("</html>")

But the *new* way would result in:

req.write("""<html>
Hello world
</html>""")

The unintended consequense of this is that only the first indent after
Python code terminator ("%>") matters, and the question is whether this is
good or bad. At first it seemed good because you need to worry less about
indenting, and there is no need for helpers like curly brackets.

But here is the unintuitive part:

<%
for x in range(3):
	for y in range(3):
%>

		Inside Y loop line 1<br>
	Inside Y loop line 2<br>

The above converts into the following Python:

for x in range(3):
	for y in range(3):

	        req.write("""Inside Y loop line 1<br>
	Inside Y loop line 2<br>
""")

SO, even though line 2 is indented less, it is still going to be inside
the "y" loop.

Here is a "solution" to this:

<%
for x in range(3):
	for y in range(3):
%>

		Inside Y loop line 1<br>
<%%>
	Inside X loop line 1<br>


The "<%%>" above will end the string, so this will result in the following
Python:

for x in range(3):
	for y in range(3):

	        req.write("""Inside Y loop line 1<br>
""")
	req.write("""Inside X loop line 1<br>
""")

I'd appreciate some opinion on whether this way of doing this is
preferred, or should we revert to the old behaviour of writing
individually every line and therefore have every line's indent matter.

My take on it is - the "new" way is definitely going to be faster (i like
that), because it's better to send one huge string than 100 small ones.
The indent gotcha and the "<%%> workaround could just be something people
would have to learn to live with. Or perhaps there could be an even
cleverer way of reducing indent.

Comments?



Mime
View raw message