A bug in pindent.py?
Magnus Lie Hetland
mlh at idi.ntnu.no
Sat Oct 6 11:52:35 EDT 2001
I've been taking a look at changing xml files into
Python programs with xslt (for applications like
psp etc.) What I do, is change something like
<foo>
bar
<script language="python">
print "2*2 is", 2*2
</script>
</foo>
into something like:
print '''<foo>
bar
'''
print "2*2 is", 2*2
print '''
</foo>'''
Obviously, the indentation isn't correct here. My hope
was that I could use pindent.py (from the standard
Tools/scripts directory) to fix this, using # end foo
tags where necessary. However, it seems that pindent
also destroys triple-quoted strings, so the result is:
print '''<foo>
bar
'''
print "2*2 is, 2*2
print '''
</foo>'''
Admittedly, this works, and the xml is still well-formed,
but I'm sure there are cases (like in xhtml <pre> tags
containing Python examples) where this would foul up the
result beyond the pure aesthetics of xml indentation.
I just wanted to hear if anybody knows of an alternative
solution, or if anybody was willing to fix this. Otherwise
I might try to write a patch myself, or, failing that,
write a separate tool... (This may, of course, be solvable
completely in xslt, though I'm not sure how.)
--
Magnus Lie Hetland http://www.hetland.org
"Reality is that which, when you stop believing in
it, doesn't go away." -- Philip K. Dick
More information about the Python-list
mailing list