re.sub problem



I'm trying to make a (tiny) template system (Cheetah and like have far
more than what I need), but I've run into a problem. To simplify
everything, I've decided to make for loops matching the indentation
level of the open and close statements; it appears to work fine, but
apparently it chokes once there are empty lines inside the string being
replaced in.

It's a bit hard to explain, so I'll just show an example:
stm = re.compile('\n(\s+)\{\{for (.+?) in
(.+?)\}\}\n?(.+?)\n\\1\{\{end for\}\}', re.M)
data = re.sub(stm, self.handle_for, data)

I do have a self.handle_for, and I can see that it's not called if I
give it the following string:
[... (not beginning of actual string) ]
{{for baz in bar}}
<p>foo:{baz}</p>
b

{{end for}}

There, nothing is matched; if there wasn't an empty line, it would
match something.

What am I doing wrong?

.



Relevant Pages

  • Re: Exporting excel to text file
    ... filenumber is just a new local variable which is going to hold the system ... >> Thank you so much for your help, the While statement and empty is ... The selection may very large as compared to what is ... >> 'Walk down each row and include it in the string if the cell is not ...
    (microsoft.public.excel.misc)
  • Re: A Logical Model for Lists as Relations
    ... I am aware of the difference between the number zero and an empty list. ... contents of a set - yields a bunch, which also has a comma union ... is a string of length 4. ... Empty strings and empty lists? ...
    (comp.databases.theory)
  • Re: Symbolic benchmark
    ... input string because it looks like people were timing ... just the time to walk the parse tree and simplify it. ... private class Expr { ... public Expr(String nType, Expr nLeft, Expr nRight) { ...
    (comp.lang.java.programmer)
  • Re: Exporting excel to text file
    ... >> Thank you so much for your help, the While statement and empty is ... The selection may very large as compared to what is ... >> Open Filename For Output As #filenumber ... >> 'Walk down each row and include it in the string if the cell is not ...
    (microsoft.public.excel.misc)
  • RE: Update panel with Gridview control
    ... Regarding on your new questions(deal with empty input parameter of the ... separate panel) on the page. ... Format of the initialization string does not conform ... connectionString, Int32 currentPosition, StringBuilder buffer, Boolean ...
    (microsoft.public.dotnet.framework.aspnet)