Commit b035ec17 authored by Andreas Jung's avatar Andreas Jung

fixed code to allow Python's 'set' module

parent 945ec4b5
......@@ -48,7 +48,7 @@ Zope Changes
Features added
- PythonScripts: added 'Set' class to RestrictedPython (Collector #1918)
- PythonScripts: allow usage of Python's 'sets' module
- added 'fast_listen' directive to http-server and webdav-source-server
sections in etc/zope.conf in order to defer the opening of the sockets
......
......@@ -15,7 +15,7 @@
$Id$
"""
from DocumentTemplate import DT_Util
import SecurityManagement, string, math, random
import SecurityManagement, string, math, random, sets
import DocumentTemplate.sequence
from ZopeGuards import safe_builtins
......@@ -28,6 +28,8 @@ DT_Util.TemplateDict.__allow_access_to_unprotected_subobjects__=1
string.__allow_access_to_unprotected_subobjects__=1
math.__allow_access_to_unprotected_subobjects__=1
random.__allow_access_to_unprotected_subobjects__=1
sets.__allow_access_to_unprotected_subobjects__=1
DocumentTemplate.sequence.__allow_access_to_unprotected_subobjects__=1
......
......@@ -295,6 +295,7 @@ class GuardedListType:
return list.sorted(iterable, cmp=None, key=None, reverse=False)
safe_builtins['list'] = GuardedListType()
class GuardedDictType:
def __call__(self, *args, **kwargs):
return dict(*args, **kwargs)
......@@ -303,6 +304,7 @@ class GuardedDictType:
return dict.fromkeys(S,v)
safe_builtins['dict'] = GuardedDictType()
def guarded_enumerate(seq):
return NullIter(enumerate(guarded_iter(seq)))
safe_builtins['enumerate'] = guarded_enumerate
......
......@@ -206,7 +206,7 @@ class TestPythonScriptNoAq(PythonScriptTestBase):
self.assertEqual(f.get_size(), len(f.read()))
def testSet(self):
res = self._newPS('return len(Set([1,2,3]))')()
res = self._newPS('from sets import Set; return len(Set([1,2,3]))')()
self.assertEqual(res, 3)
def testDateTime(self):
......
......@@ -16,7 +16,7 @@ __version__='$Revision: 1.7 $'[11:-2]
import string, math, random
import DocumentTemplate.sequence
from DateTime.DateTime import DateTime
from sets import Set
import sets
utility_builtins = {}
......@@ -25,7 +25,7 @@ utility_builtins['math'] = math
utility_builtins['random'] = random
utility_builtins['sequence'] = DocumentTemplate.sequence
utility_builtins['DateTime'] = DateTime
utility_builtins['Set'] = Set
utility_builtins['sets'] = sets
def same_type(arg1, *args):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment