[Tutor] ASP processing
Nicholas Wieland
nicholas_wieland@yahoo.it
Tue Feb 18 20:54:02 2003
Hello everyone,
I'm trying to parse ASP embedded in HTML files in Python, for a
little translator I'm going to use to speed the translation of a web
site.
My problem with ASP is that I must parse the text between <% and %>, so
at the moment I can't understand how to use htmllib and derivates,
because they handle start and end tags, not the multiline text *inside*
a tag.
Here is the code. It's quite unreadable and doesn't process the text
correctly...
while(1):
line = source.readline()
if(string.find(line, "\<%")):
while(1):
asp = source.readline()
start = string.find(asp, "\"")
end = string.rfind(asp, "\"")
quote = asp[start+1 : end]
if (len(quote) > 1):
dest.write(asp[:start+1])
self.TxtSource.WriteText(quote)
t_dlg = wxTextEntryDialog(self, 'Question', 'Caption',
'')
try:
if t_dlg.ShowModal() == wxID_OK:
answer = t_dlg.GetValue()
dest.write(answer)
finally:
t_dlg.Destroy()
self.TxtSource.Clear()
dest.write(asp[end:])
else:
dest.write(asp)
if(string.rfind(asp, "\%>")):
break
if (line == ""):
break
As you can see it's far away from being perfect, so I need suggestion.
I'd like to use a module instead of writing all the parser... do I have
to use something like sgmllib ?
TIA,
Nicholas