Using the set object within page templates
How can I use a set object within a page template? When I attempt to create a set (e.g. tal:define="myset python:set(some_list)"), zope complains that the name 'set' is not defined. Thanks! fm
Python sets are not available from with ZPT since ZPT and PythonScripts run within a sandbox. Write an external method or move your code to trusted code (Zope product). -aj --On 26. September 2005 13:38:55 -0500 Floyd May <Fmay@okcareertech.org> wrote:
How can I use a set object within a page template?
When I attempt to create a set (e.g. tal:define="myset python:set(some_list)"), zope complains that the name 'set' is not defined.
Thanks!
fm _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
A more interesting question: shouldn't it be available by default? It's a basic data strucure along the lines of lists and dicts, right? Or have I missed a use case for it where it may be scary to use in a Python Script? :) -- Alexander Limi On Mon, 26 Sep 2005 20:41:18 +0200, Andreas Jung <lists@andreas-jung.com> wrote:
Python sets are not available from with ZPT since ZPT and PythonScripts run within a sandbox. Write an external method or move your code to trusted code (Zope product).
-aj
--On 26. September 2005 13:38:55 -0500 Floyd May <Fmay@okcareertech.org> wrote:
How can I use a set object within a page template?
When I attempt to create a set (e.g. tal:define="myset python:set(some_list)"), zope complains that the name 'set' is not defined.
Thanks!
fm _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- _____________________________________________________________________ Alexander Limi · Chief Architect · Plone Solutions · Norway Consulting · Training · Development · http://www.plonesolutions.com _____________________________________________________________________ Plone Co-Founder · http://plone.org · Connecting Content Plone Foundation · http://plone.org/foundation · Protecting Plone
Alexander Limi wrote:
A more interesting question: shouldn't it be available by default?
It's a basic data strucure along the lines of lists and dicts, right? Or have I missed a use case for it where it may be scary to use in a Python Script? :)
No, it's just an object type that came along since the default list of acceptable things in python scripts was last updated. Should be trivial to change, but stick a collector entry in for it anyway... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Alexander Limi wrote at 2005-9-28 20:40 +0200:
A more interesting question: shouldn't it be available by default?
It's a basic data strucure along the lines of lists and dicts, right? Or have I missed a use case for it where it may be scary to use in a Python Script? :)
Paranoic people would want to have similar DOS attack protection as for other similar data types (e.g. lists). This would make some work... I expect you could get a "patches welcome" :-) -- Dieter
Floyd May wrote:
How can I use a set object within a page template?
When I attempt to create a set (e.g. tal:define="myset python:set(some_list)"), zope complains that the name 'set' is not defined.
If you only need to read from some native python objects, you can make a simple wrapper. You can wrap a set() in this class and return it from python. _marker = [] class Zello: """ Zello (Zellophane) A minimal wrapper for viewing native python objects in pagetemplates. If you try to view attributes on simple Python objects you get a Permission error. This is pretty simple to fix in your own objects by setting: __allow_access_to_unprotected_subobjects__ = 1 For some built in objects you cannot do this. This class just puts a transparent wrapper around such objects:: wrapped = Zello(datetime(2005, 10, 12)) So you can write this zpt code: <span tal:replace="wrapped/year" /> If you wrap a Zope object with it, you basically remove all security checkcs. So don't do that. """ __allow_access_to_unprotected_subobjects__ = 1 def __init__(self, obj): self._obj = obj def __getattr__(self, attr, default=_marker): if default is _marker: return getattr(self._obj, attr) else: return getattr(self._obj, attr, default) def __getitem__(self, key): return self._obj[key] -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science
Floyd May wrote at 2005-9-26 13:38 -0500:
How can I use a set object within a page template?
When I attempt to create a set (e.g. tal:define="myset python:set(some_list)"), zope complains that the name 'set' is not defined.
It is right, because "set" is not listed in "RestrictedPython.Guards.safe_builtins". These definitions together with "RestrictedPython.Utilities.utility_builtins" define the set of built in names for untrusted code. Almost surely, you will also need to "allow_type" the "set" -- in order to access the methods of set objects. You can access "allow_type" (in trusted code) from "AccessControl". -- Dieter
participants (6)
-
Alexander Limi -
Andreas Jung -
Chris Withers -
Dieter Maurer -
Floyd May -
Max M