On Mar 4, 2011, at 12:54 PM, Massimo Di Pierro wrote: > > All I meant is that > > {{=msg > pass}} > > should become: > > response.write(msg) > pass > > and not > > response.write(msg > pass) > > since there is no ambiguity.
Right. The question the code has to answer, implicitly, is: exactly what is the termination of whatever will be passed to response.write. If the = doesn't appear at the beginning of a code block, the answer is: the next newline, or the end of the code block, whichever comes first. I think that's the right answer. It does mean that: {{=msg abc pass}} will become: response.write (msg abc) pass ...but I think that's OK; it's just a "normal" syntax error. It's really too complicated to try to parse the argument, since you want things like {{="abc def" pass}} to work. I *think* that this will still work: {{="""string on multiple lines """ pass}} ...because the '=' detection comes after the multiline-string escape. > > On Mar 4, 2:25 pm, Jonathan Lundell <jlund...@pobox.com> wrote: >> On Mar 4, 2011, at 12:19 PM, Massimo Di Pierro wrote: >> >> >> >>> I agree that that is what it should do. Please open a ticket about >>> this. >> >> Are you saying (I think) that both cases should terminate on a newline (if >> present)? >> >> >> >> >> >> >> >> >> >>> On Mar 4, 11:20 am, Jonathan Lundell <jlund...@pobox.com> wrote: >>>> On Mar 4, 2011, at 1:52 AM, szimszon wrote: >> >>>>> web2py™ Version 1.92.1 (2011-02-16 15:04:40) >>>>> Python Python 2.5.2: /usr/bin/python >> >>>>> Traceback (most recent call last): >>>>> File "/home/szimszon_nfs/web2py/gluon/restricted.py", line 186, in >>>>> restricted >>>>> ccode = compile2(code,layer) >>>>> File "/home/szimszon_nfs/web2py/gluon/restricted.py", line 173, in >>>>> compile2 >>>>> return compile(code.rstrip().replace('\r\n','\n')+'\n', layer, >>>>> 'exec') >>>>> File "/home/szimszon_nfs/web2py/applications/serveradmin/views/ >>>>> integrity/ftp.html", line 123 >>>>> pass >>>>> ^ >>>>> SyntaxError: invalid syntax >> >>>>> if msg: >>>>> response.write('\n<h2>', escape=False) >>>>> response.write(T("Commands executed")) >>>>> response.write('</h2>\n', escape=False) >>>>> response.write(XML(msg) >>>>> pass >> >>>>> My template was working until now (I don't know exactly from what >>>>> web2py version is it bad). >> >>>>> My template was: >> >>>>> {{if msg:}} >>>>> <h2>{{=T("Commands executed")}}</h2> >>>>> {{ =XML(msg) >>>>> pass >>>>> try: >>>>> dname=request.args[1] >>>>> except: >>>>> dname=0 >>>>> pass >>>>> editname=T('New')}} >> >>>> Thadeus might want to chime in here if I have the details wrong (there >>>> really ought to be a formal reference for template syntax; the tutorial in >>>> the book is nice, but not complete). >> >>>> There's a subtle difference in template parsing when =something appears at >>>> the beginning of an escaped block (where "beginning" ignores white space, >>>> so =XML above is regarded as being at the beginning of the code block). >> >>>> You probably know already that =something is translated to >>>> response.write(something). But the question arises, what exactly is >>>> "something"? That is, where does it end? >> >>>> And when the '=something' is found at the beginning of a code block, >>>> 'something' is defined to be *everything until the end of the code block*. >> >>>> When '=something' is found *embedded* in a code block (not at the >>>> beginning, ignoring white space), then the end of 'something' is either >>>> the next newline or the end of the code block, whichever comes first. >> >>>> So (to shorten up the problem here), you've effectively got this: >> >>>> {{=msg >>>> pass}} >> >>>> ...which becomes: >> >>>> response.write(msg >>>> pass) >> >>>> ...and Python is going to object. >> >>>> On the other hand, if you had written: >> >>>> {{if xyz: >>>> =msg >>>> pass}} >> >>>> The output will be: >> >>>> if xyz: >>>> response.write(msg) >>>> pass >> >>>> ...and everybody's happy. Because =msg wasn't the first thing in the code >>>> block, only msg gets included in the response.write argument. >> >>>> Is there a good reason for =something to be interpreted two different >>>> ways? I'm not sure it's intentional. Thadeus? Massimo? >> >>>>> Now I had to modify: >> >>>>> {{if msg:}} >>>>> <h2>{{=T("Commands executed")}}</h2> >>>>> {{ =XML(msg)}} < ----- >>>>> {{pass <----------- >>>>> try: >>>>> dname=request.args[1] >>>>> except: >>>>> dname=0 >>>>> pass >>>>> editname=T('New')}}