[ZCM] [ZC] 1820/ 5 Accept " saving PageTemplate via FTP, with multiline TALs causes ERROR"

Collector: Zope Bugs, Features, and Patches ... zope-coders-admin at zope.org
Sat Mar 11 10:35:19 EST 2006


Issue #1820 Update (Accept) " saving PageTemplate via FTP, with multiline TALs causes ERROR"
 Status Accepted, Zope/bug medium
To followup, visit:
  http://www.zope.org/Collectors/Zope/1820

==============================================================
= Accept - Entry #5 by mj on Mar 11, 2006 10:35 am

 Status: Rejected => Accepted

 Supporters added: mj

Jumping the gun here; 1474 deals with newline handling in general, not with python expressions in particular. This bug does.

The correct fix would be to extend PageTemplates.PythonExpr.PythonExpr.__init__ to also deal with '\r\n' and '\r' newlines. I'll take this later today or tomorrow.
________________________________________
= Reject - Entry #4 by mj on Mar 11, 2006 10:29 am

 Status: Pending => Rejected

This is a dupe of 1474 (http://www.zope.org/Collectors/Zope/1474); python expressions cannot deal with any line-endings other than simple '\n' newlines.
________________________________________
= Comment - Entry #3 by camil7 on Sep 3, 2005 2:39 pm

 An alternative is to store the page template with
content type of "text/xml" instead of "text/html" because
then the xml parser should take care of then CRLF conversion.
 Seems to work for me; I can upload page templates
with CR/LF linebreaks in python expressions without problem.

This only works if the page template is valid XML, however.

It seems the supplied HTMLParser does not care about CR/LF,
and this is usually handled specially (e.g. in
PageTemplateFile there is explicit code to open the 
corresponding file in text mode if it contains HTML instead of 
XML) but no such measures are taken for FTP or WebDAV
(or just plain file upload via the Upload in the ZMI)

________________________________________
= Comment - Entry #2 by camil7 on Sep 3, 2005 1:22 pm

Most probably this has something to do with the line breaks.
For some reason this seems to work for me when uploading
files with unix style linebreaks (only '\n'), but fails
if uploading windows ('\r\n').

 This issue may be related to issue 1464

 If You want a hotfix and are not afraid to mess with the
Zope source, You should be able to fix this by changing
lib\python\Products\PageTemplates\ZRPythonExpr.py

[...]
    def __init__(self, name, expr, engine):
        self.expr = expr = expr.strip().replace('\n', ' ')
        code, err, warn, use = compile_restricted_eval(expr, str(self))
[...]

 Just use:

        self.expr = expr = expr.strip().replace('\n', ' ').replace('\r',' ')

I guess the "right" place to fix it should be somewhere else,
when reading in the page template via ftp. I will take a look
if i can find it

If it is not caused by the windows line break issue, this
patch will not help, however ....
________________________________________
= Request - Entry #1 by MrRonsen on Jun 24, 2005 7:01 am

saving PageTemplate via FTP, with multiline TALs causes ERROR

take a PageTemplate,
insert a multiline TAL like
(this example you should modify because of the used folders, scripts,
which you dont have):

<tal:block tal:define="dic_link python: {'href' :
container.system_vars.folder_attachment_path_var(item['attachment_file_name']),
                                          'link_text'  : 
container.os.py_get_article_field(contentID=223,field='title_html'),
                                          'css_class'  : 
'left_include_chapter',
                                          'css_inline' : 'x',
                                          'img_inline' : 'x',
                                          'html_mode'  : 'table-tr-td',
                                          'icon'       : 'auto_2',
                                          'modus'      : 1 }">
<tal:block tal:content="structure python:
container.os.py_parse_website_link(dic_link)"></tal:block>
</tal:block>


and save it directly in your ZOPE-Interface,
not via WEBDAV or FTP.

ZOPE will save it, check it, no Errors, ok, fine.
Execute the PageTemplate everything is fine.

next step, connect via FTP to your ZOPE,
look for your PageTemplate with the multiline TAL-expression.
Insert a not important blank sign or line,
and save it via FTP.

If you call, execute the PageTemplate an error occurs!
go into your ZOPE-Interface,
look for your PageTemplate with the multiline TAL-expression,
you will see the Error on red background:

Compilation failed
TAL.TALDefs.TALError: Python expression error:
invalid syntax ('',
                        'img_special' : '',
                        'html'        : '3',
                        'modus'       : 1 )", line 1) in expression 
"python: .......


ahh,
now make nothing, only save this "bad"-PageTemplate.
ZOPE will check it and save it again and the error is past/gone.
If you call, execute the PageTemplate, everthing is fine,
until you save it again per FTP.


At first it seems to be the multiline TAL-expression,
but it is the saving-prozess in ZOPE 2.7.5/2.8.0,
which seems to be different between FTP-Saving and ZOPE-Interface-Saving.
In 2.6.4 this miracle didn´t appeared.

So i need a hint,
better a bugfix, because i want to keep
the multiline TALs, they are much better to read than a long one-line TAL-expression.

(i dont want to make all my multiline TALs form into onelined !)

==============================================================



More information about the Zope-Collector-Monitor mailing list