[Zope-Checkins] CVS: Zope2 - __init__.py:1.1 testRestrictions.py:1.5
shane@digicool.com
shane@digicool.com
Wed, 23 May 2001 14:03:01 -0400 (EDT)
Update of /cvs-repository/Zope2/lib/python/RestrictedPython/tests
In directory korak.digicool.com:/tmp/cvs-serv14041
Modified Files:
testRestrictions.py
Added Files:
__init__.py
Log Message:
Enabled tests to run both from the command line and by testrunner.
--- Added File __init__.py in package Zope2 ---
'''Python package.'''
--- Updated File testRestrictions.py in package Zope2 --
--- testRestrictions.py 2001/05/17 21:42:00 1.4
+++ testRestrictions.py 2001/05/23 18:03:00 1.5
@@ -9,22 +9,16 @@
from RestrictedPython import compile_restricted, PrintCollector
from RestrictedPython.Eval import RestrictionCapableEval
import security_in_syntax
+from types import FunctionType
-def package_home(globals_dict):
- __name__=globals_dict['__name__']
- if __name__ == '__main__':
- return os.getcwd()
- m=sys.modules[__name__]
- if hasattr(m,'__path__'):
- r=m.__path__[0]
- elif "." in __name__:
- r=sys.modules[__name__[:rfind(__name__,'.')]].__path__[0]
- else:
- r=__name__
- return os.path.join(os.getcwd(), r)
+if __name__=='__main__':
+ sys.path.append(os.path.join(os.pardir, os.pardir))
+ here = os.curdir
+else:
+ from App.Common import package_home
+ from RestrictedPython import tests
+ here = package_home(tests.__dict__)
-FunctionType = type(package_home)
-
def _getindent(line):
"""Returns the indentation level of the given line."""
indent = 0
@@ -55,7 +49,7 @@
def create_rmodule():
global rmodule
- fn = os.path.join(package_home(globals()), 'restricted_module.py')
+ fn = os.path.join(here, 'restricted_module.py')
f = open(fn, 'r')
source = f.read()
f.close()
@@ -64,10 +58,11 @@
# Now compile it for real
code = compile_restricted(source, fn, 'exec')
rmodule = {'__builtins__':None}
+ builtins = getattr(__builtins__, '__dict__', __builtins__)
for name in ('map', 'reduce', 'int', 'pow', 'range', 'filter',
'len', 'chr', 'ord',
):
- rmodule[name] = getattr(__builtins__, name)
+ rmodule[name] = builtins[name]
exec code in rmodule
create_rmodule()
@@ -202,7 +197,7 @@
def checkSyntaxSecurity(self):
# Ensures that each of the functions in security_in_syntax.py
# throws a SyntaxError when using compile_restricted.
- fn = os.path.join(package_home(globals()), 'security_in_syntax.py')
+ fn = os.path.join(here, 'security_in_syntax.py')
f = open(fn, 'r')
source = f.read()
f.close()