[web2py] Re: Error in templating system
I thought that after the = I could only write one string/variable/ function with string output which is wrapped in write... Anything else I could put in non-python block... Never mind. I can live with what you choose as solution :) Just I say it was working before :-o I will stay with web2py anyway :-D On márc. 5, 03:22, Jonathan Lundell jlund...@pobox.com wrote: On Mar 4, 2011, at 6:03 PM, villas wrote: On Mar 4, 10:22 pm, Thadeus Burgess thade...@thadeusb.com wrote: I don't think you should have code included in a {{= block. +1 Explicit is better {{if abc:}} {{=xyz}} {{pass}} Yes, there are extra brackets, but no one's going to have a problem with that. That would continue to work regardless. Right now we have two rules, and it's hard to explain why. {{=abc abc = 123}} ...fails. But {{abc = 123 =abc}} ... is fine. And so is {{abc = 123 =abc abc = 456}} {{pass =abc pass}} is fine. But {{=abc pass}} ...is not. That's a strange set of rules, if you ask me. And confusing, as we've already seen, especially since the error message is not helpful.
[web2py] Re: Error in templating system
There was also a suggestion that the space before the = might have been an issue: {{ =XML(msg)}} Is that space in there on purpose or by accident?
Re: [web2py] Re: Error in templating system
On Mar 5, 2011, at 11:18 AM, pbreit wrote: There was also a suggestion that the space before the = might have been an issue: {{ =XML(msg)}} Is that space in there on purpose or by accident? Leading spaces get stripped (between {{ and =), so that wasn't relevant (in this case).
[web2py] Re: Error in templating system
It was on purbose. On márc. 5, 20:18, pbreit pbreitenb...@gmail.com wrote: There was also a suggestion that the space before the = might have been an issue: {{ =XML(msg)}} Is that space in there on purpose or by accident?
Re: [web2py] Re: Error in templating system
On Mar 5, 2011, at 12:16 PM, szimszon wrote: It was on purbose. If so, it has only a cosmetic effect; the parser strips the spaces. On márc. 5, 20:18, pbreit pbreitenb...@gmail.com wrote: There was also a suggestion that the space before the = might have been an issue: {{ =XML(msg)}} Is that space in there on purpose or by accident?
Re: [web2py] Re: Error in templating system
Ok, when put into this context I agree, it should be fixed. It should all behave the same. -- Thadeus On Fri, Mar 4, 2011 at 8:22 PM, Jonathan Lundell jlund...@pobox.com wrote: s a strange set of rules, if you ask me. And confusing, as we've already seen, especially since the error message is not hel
Re: [web2py] Re: Error in templating system
On Mar 5, 2011, at 4:38 PM, Thadeus Burgess wrote: Ok, when put into this context I agree, it should be fixed. It should all behave the same. I'll create some more unit tests to expose the current behavior and then remove the special case. In the meantime, the workaround is to observe this rule: if a code block begins with '=' (not counting initial whitespace), then the entire code block should be on one line. Example: {{ =this }} {{ =but not this}} One exception: I assume (and will test) that this is OK: {{ =some long string }} ...which doesn't make sense on its own, but might with interpolation. -- Thadeus On Fri, Mar 4, 2011 at 8:22 PM, Jonathan Lundell jlund...@pobox.com wrote: s a strange set of rules, if you ask me. And confusing, as we've already seen, especially since the error message is not hel
[web2py] Re: Error in templating system
Yes I already did it and I mentioned it in the code above but the point is that it was working until I upgraded the framework. The original syntax was good too I mean I can't see what is wrong with it. So it's a backward compatibility issue :( On márc. 4, 10:58, pbreit pbreitenb...@gmail.com wrote: Maybe try closing up the pass with }} and then reopening the rest of the code?
[web2py] Re: Error in templating system
Oh, ok, I see, sorry about that. So it somehow dropped the closing ) after =XML(msg). Could your msg have any special characters in it? I see some UTF-8 related diffs in the code for html.py recently.
[web2py] Re: Error in templating system
Don't know could be but The interpreter which checks the syntax about all the pass-es are in right place give me the syntax error. What I try to say that first I visit the page the msg is None so the if branch isn't executed at all. If I just byte compile the app I have the same syntax error message. And if I close the =XML(msg) with }} and open before pass everything is right. :( On márc. 4, 11:26, pbreit pbreitenb...@gmail.com wrote: Oh, ok, I see, sorry about that. So it somehow dropped the closing ) after =XML(msg). Could your msg have any special characters in it? I see some UTF-8 related diffs in the code for html.py recently.
[web2py] Re: Error in templating system
The code you posted was clearly badly formed. You need to correct it first. The 'pass' function should always look like this: {{pass}} If something only works in a strange, undocumented way, it is likely to be broken in the future. This is nothing to do with backwards compatibility, it is simply working as per the documentation. On Mar 4, 10:42 am, szimszon szims...@gmail.com wrote: Don't know could be but The interpreter which checks the syntax about all the pass-es are in right place give me the syntax error. What I try to say that first I visit the page the msg is None so the if branch isn't executed at all. If I just byte compile the app I have the same syntax error message. And if I close the =XML(msg) with }} and open before pass everything is right. :( On márc. 4, 11:26, pbreit pbreitenb...@gmail.com wrote: Oh, ok, I see, sorry about that. So it somehow dropped the closing ) after =XML(msg). Could your msg have any special characters in it? I see some UTF-8 related diffs in the code for html.py recently.
[web2py] Re: Error in templating system
I agree that that is what it should do. Please open a ticket about this. 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('\nh2', 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')}}
Re: [web2py] Re: Error in templating system
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('\nh2', 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')}}
[web2py] Re: Error in templating system
All I meant is that {{=msg pass}} should become: response.write(msg) pass and not response.write(msg pass) since there is no ambiguity. 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('\nh2', 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')}}
Re: [web2py] Re: Error in templating system
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('\nh2', 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')}}
Re: [web2py] Re: Error in templating system
I don't think you should have code included in a {{= block. {{= should ONLY be used to wrap anything in its code block with a response.write(). Exactly how it does it now. Doing otherwise is simply bad template design. I consider it a bug if it ever worked before. Allowing this syntax encourages template writers to do things in non-standard ways that won't make obvious sense to anybody else attempting to read their templates. (I currently have to maintain and re-write some very ugly web2py code in my day job... the previous guys working severely abused the power of the template system and it has caused us many issues/headaches because of it). tl;dr - it is the desired behaviour, update your app code to standards. lets not complicate web2py further. -- Thadeus On Fri, Mar 4, 2011 at 3:21 PM, Jonathan Lundell jlund...@pobox.com wrote: 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('\nh2', 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:
[web2py] Re: Error in templating system
On Mar 4, 10:22 pm, Thadeus Burgess thade...@thadeusb.com wrote: I don't think you should have code included in a {{= block. +1 Explicit is better {{if abc:}} {{=xyz}} {{pass}} Yes, there are extra brackets, but no one's going to have a problem with that.
Re: [web2py] Re: Error in templating system
On Mar 4, 2011, at 6:03 PM, villas wrote: On Mar 4, 10:22 pm, Thadeus Burgess thade...@thadeusb.com wrote: I don't think you should have code included in a {{= block. +1 Explicit is better {{if abc:}} {{=xyz}} {{pass}} Yes, there are extra brackets, but no one's going to have a problem with that. That would continue to work regardless. Right now we have two rules, and it's hard to explain why. {{=abc abc = 123}} ...fails. But {{abc = 123 =abc}} ... is fine. And so is {{abc = 123 =abc abc = 456}} {{pass =abc pass}} is fine. But {{=abc pass}} ...is not. That's a strange set of rules, if you ask me. And confusing, as we've already seen, especially since the error message is not helpful.