[Zope] global name 'context' not defined in TrustedFSPageTemplate
Jürgen Herrmann
Juergen.Herrmann at XLhost.de
Fri Jun 2 07:10:59 EDT 2006
On Thu, June 1, 2006 18:13, Jürgen Herrmann wrote:
>
> On Thu, June 1, 2006 18:08, Jonathan wrote:
>>
>> ----- Original Message -----
>> From: "Jürgen Herrmann" <Juergen.Herrmann at XLhost.de>
>> To: <zope at zope.org>
>> Sent: Thursday, June 01, 2006 11:51 AM
>> Subject: [Zope] global name 'context' not defined in TrustedFSPageTemplate
>>
>>
>>> hi!
>>>
>>> i get the following error in one of my trusted page template files:
>>>
>>> Traceback (innermost last):
>>> * Module ZPublisher.Publish, line 113, in publish
>>> * Module ZPublisher.mapply, line 88, in mapply
>>> * Module ZPublisher.Publish, line 40, in call_object
>>> * Module Shared.DC.Scripts.Bindings, line 311, in __call__
>>> * Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
>>> * Module Products.CMFCore.FSPageTemplate, line 195, in _exec
>>> * Module Products.TrustedExecutables.TrustedFSPageTemplate, line 31, in
>>> pt_render
>>> * Module Products.PageTemplates.PageTemplate, line 104, in pt_render
>>> <TrustedFSPageTemplate at /bliss/BlissCalendar/show_content_week>
>>> * Module TAL.TALInterpreter, line 238, in __call__
>>> * Module TAL.TALInterpreter, line 281, in interpret
>>> * Module TAL.TALInterpreter, line 507, in do_setLocal_tal
>>> * Module Products.PageTemplates.TALES, line 221, in evaluate
>>> URL:
>>> file:/home/bliss/zope/Products/BlissCalendar/www/BlissCalendar/show_content_week.xpt
>>> Line 3, Column 0
>>> Expression: <PythonExpr dates.sort(lambda a,b:
>>> cmp(context.utils.text2date(a),
>>> context.utils.text2date(b)))>
>>> Names:
>>>
>>> {'container': <BlissCalendar at /bliss/BlissCalendar>,
>>> 'context': <BlissCalendar at /bliss/BlissCalendar>,
>>> 'default': <Products.PageTemplates.TALES.Default instance at
>>> 0xb703850c>,
>>> 'here': <BlissCalendar at /bliss/BlissCalendar>,
>>> 'loop': <Products.PageTemplates.TALES.SafeMapping object at
>>> 0xb5d9426c>,
>>> 'modules':
>>> <Products.TrustedExecutables.TrustedExpression._ModuleImporter instance at
>>> 0xb6fa1b8c>,
>>> 'nothing': None,
>>> 'options': {'args': ()},
>>> 'repeat': <Products.PageTemplates.TALES.SafeMapping object at
>>> 0xb5d9426c>,
>>> 'request': <HTTPRequest,
>>> URL=https://bliss.local/BlissCalendar/show_content_week>,
>>> 'root': <Application at >,
>>> 'template': <TrustedFSPageTemplate at
>>> /bliss/BlissCalendar/show_content_week>,
>>> 'traverse_subpath': [],
>>> 'user': <User at /bliss/data/Users/instances/juherm00 used for
>>> /bliss/acl_users>}
>>>
>>> * Module Products.PageTemplates.PythonExpr, line 70, in __call__
>>> __traceback_info__: dates.sort(lambda a,b:
>>> cmp(context.utils.text2date(a),
>>> context.utils.text2date(b)))
>>> * Module <string>, line 2, in f
>>> * Module <string>, line 2, in <lambda>
>>>
>>> NameError: global name 'context' is not defined
>>
>> Just a guess (the python gurus could answer this for sure), but lambda
>> functions have access to variables in the containing scope, which in your
>> case is the date.sort function. Does date.sort provide access to 'context'?
>>
>> A quick test would be to get rid of the lambda function and create a named
>> function and see if that works.
>>
> i have to add that this was a "normal" page template file before, just
> converted i to a trusted one. in the "normal" page template file this
> expression just worked.
>
> i'll dig a bit deeper tomorrow if nothing comes up here.
> going home now, my brain refuses to think any longer.
>
> regards, juergen
i tried what Jonathan suggested and replaced the lambda by a named
comparison function and it works. so my advice for people who might
search the mailinglist in the future:
do not use lambdas in python expressions in trusted fs page templates.
regards, juergen herrmann
_______________________________________________________________________
>> XLhost.de - eXperts in Linux hosting <<
Jürgen Herrmann
Bruderwöhrdstraße 15b, DE-93051 Regensburg
Fon: +49 (0)700 XLHOSTDE [0700 95467833]
Fax: +49 (0)721 151 463027
WEB: http://www.XLhost.de
More information about the Zope
mailing list