zope.untrustedpython-4.0.0/0000775000000000000000000000000012357322552014474 5ustar rootrootzope.untrustedpython-4.0.0/CHANGES.rst0000664000000000000000000000023612106565726016303 0ustar rootroot======= CHANGES ======= 4.0.0 (2013-02-12) ------------------ - Test coverage at 100%. - Package extracted from zope.security, preserving revision history zope.untrustedpython-4.0.0/README.rst0000664000000000000000000000003112106565726016161 0ustar rootrootUntrusted python library zope.untrustedpython-4.0.0/bootstrap.py0000664000000000000000000002443512106565726017077 0ustar rootroot############################################################################## # # Copyright (c) 2006 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """Bootstrap a buildout-based project Simply run this script in a directory containing a buildout.cfg. The script accepts buildout command-line options, so you can use the -c option to specify an alternate configuration file. """ import os, shutil, sys, tempfile, urllib, urllib2, subprocess from optparse import OptionParser if sys.platform == 'win32': def quote(c): if ' ' in c: return '"%s"' % c # work around spawn lamosity on windows else: return c else: quote = str # See zc.buildout.easy_install._has_broken_dash_S for motivation and comments. stdout, stderr = subprocess.Popen( [sys.executable, '-Sc', 'try:\n' ' import ConfigParser\n' 'except ImportError:\n' ' print 1\n' 'else:\n' ' print 0\n'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() has_broken_dash_S = bool(int(stdout.strip())) # In order to be more robust in the face of system Pythons, we want to # run without site-packages loaded. This is somewhat tricky, in # particular because Python 2.6's distutils imports site, so starting # with the -S flag is not sufficient. However, we'll start with that: if not has_broken_dash_S and 'site' in sys.modules: # We will restart with python -S. args = sys.argv[:] args[0:0] = [sys.executable, '-S'] args = map(quote, args) os.execv(sys.executable, args) # Now we are running with -S. We'll get the clean sys.path, import site # because distutils will do it later, and then reset the path and clean # out any namespace packages from site-packages that might have been # loaded by .pth files. clean_path = sys.path[:] import site # imported because of its side effects sys.path[:] = clean_path for k, v in sys.modules.items(): if k in ('setuptools', 'pkg_resources') or ( hasattr(v, '__path__') and len(v.__path__) == 1 and not os.path.exists(os.path.join(v.__path__[0], '__init__.py'))): # This is a namespace package. Remove it. sys.modules.pop(k) is_jython = sys.platform.startswith('java') setuptools_source = 'http://peak.telecommunity.com/dist/ez_setup.py' distribute_source = 'http://python-distribute.org/distribute_setup.py' # parsing arguments def normalize_to_url(option, opt_str, value, parser): if value: if '://' not in value: # It doesn't smell like a URL. value = 'file://%s' % ( urllib.pathname2url( os.path.abspath(os.path.expanduser(value))),) if opt_str == '--download-base' and not value.endswith('/'): # Download base needs a trailing slash to make the world happy. value += '/' else: value = None name = opt_str[2:].replace('-', '_') setattr(parser.values, name, value) usage = '''\ [DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options] Bootstraps a buildout-based project. Simply run this script in a directory containing a buildout.cfg, using the Python that you want bin/buildout to use. Note that by using --setup-source and --download-base to point to local resources, you can keep this script from going over the network. ''' parser = OptionParser(usage=usage) parser.add_option("-v", "--version", dest="version", help="use a specific zc.buildout version") parser.add_option("-d", "--distribute", action="store_true", dest="use_distribute", default=False, help="Use Distribute rather than Setuptools.") parser.add_option("--setup-source", action="callback", dest="setup_source", callback=normalize_to_url, nargs=1, type="string", help=("Specify a URL or file location for the setup file. " "If you use Setuptools, this will default to " + setuptools_source + "; if you use Distribute, this " "will default to " + distribute_source + ".")) parser.add_option("--download-base", action="callback", dest="download_base", callback=normalize_to_url, nargs=1, type="string", help=("Specify a URL or directory for downloading " "zc.buildout and either Setuptools or Distribute. " "Defaults to PyPI.")) parser.add_option("--eggs", help=("Specify a directory for storing eggs. Defaults to " "a temporary directory that is deleted when the " "bootstrap script completes.")) parser.add_option("-t", "--accept-buildout-test-releases", dest='accept_buildout_test_releases', action="store_true", default=False, help=("Normally, if you do not specify a --version, the " "bootstrap script and buildout gets the newest " "*final* versions of zc.buildout and its recipes and " "extensions for you. If you use this flag, " "bootstrap and buildout will get the newest releases " "even if they are alphas or betas.")) parser.add_option("-c", None, action="store", dest="config_file", help=("Specify the path to the buildout configuration " "file to be used.")) options, args = parser.parse_args() if options.eggs: eggs_dir = os.path.abspath(os.path.expanduser(options.eggs)) else: eggs_dir = tempfile.mkdtemp() if options.setup_source is None: if options.use_distribute: options.setup_source = distribute_source else: options.setup_source = setuptools_source if options.accept_buildout_test_releases: args.insert(0, 'buildout:accept-buildout-test-releases=true') try: import pkg_resources import setuptools # A flag. Sometimes pkg_resources is installed alone. if not hasattr(pkg_resources, '_distribute'): raise ImportError except ImportError: ez_code = urllib2.urlopen( options.setup_source).read().replace('\r\n', '\n') ez = {} exec ez_code in ez setup_args = dict(to_dir=eggs_dir, download_delay=0) if options.download_base: setup_args['download_base'] = options.download_base if options.use_distribute: setup_args['no_fake'] = True if sys.version_info[:2] == (2, 4): setup_args['version'] = '0.6.32' ez['use_setuptools'](**setup_args) if 'pkg_resources' in sys.modules: reload(sys.modules['pkg_resources']) import pkg_resources # This does not (always?) update the default working set. We will # do it. for path in sys.path: if path not in pkg_resources.working_set.entries: pkg_resources.working_set.add_entry(path) cmd = [quote(sys.executable), '-c', quote('from setuptools.command.easy_install import main; main()'), '-mqNxd', quote(eggs_dir)] if not has_broken_dash_S: cmd.insert(1, '-S') find_links = options.download_base if not find_links: find_links = os.environ.get('bootstrap-testing-find-links') if not find_links and options.accept_buildout_test_releases: find_links = 'http://downloads.buildout.org/' if find_links: cmd.extend(['-f', quote(find_links)]) if options.use_distribute: setup_requirement = 'distribute' else: setup_requirement = 'setuptools' ws = pkg_resources.working_set setup_requirement_path = ws.find( pkg_resources.Requirement.parse(setup_requirement)).location env = dict( os.environ, PYTHONPATH=setup_requirement_path) requirement = 'zc.buildout' version = options.version if version is None and not options.accept_buildout_test_releases: # Figure out the most recent final version of zc.buildout. import setuptools.package_index _final_parts = '*final-', '*final' def _final_version(parsed_version): for part in parsed_version: if (part[:1] == '*') and (part not in _final_parts): return False return True index = setuptools.package_index.PackageIndex( search_path=[setup_requirement_path]) if find_links: index.add_find_links((find_links,)) req = pkg_resources.Requirement.parse(requirement) if index.obtain(req) is not None: best = [] bestv = None for dist in index[req.project_name]: distv = dist.parsed_version if distv >= pkg_resources.parse_version('2dev'): continue if _final_version(distv): if bestv is None or distv > bestv: best = [dist] bestv = distv elif distv == bestv: best.append(dist) if best: best.sort() version = best[-1].version if version: requirement += '=='+version else: requirement += '<2dev' cmd.append(requirement) if is_jython: import subprocess exitcode = subprocess.Popen(cmd, env=env).wait() else: # Windows prefers this, apparently; otherwise we would prefer subprocess exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env])) if exitcode != 0: sys.stdout.flush() sys.stderr.flush() print ("An error occurred when trying to install zc.buildout. " "Look above this message for any errors that " "were output by easy_install.") sys.exit(exitcode) ws.add_entry(eggs_dir) ws.require(requirement) import zc.buildout.buildout # If there isn't already a command in the args, add bootstrap if not [a for a in args if '=' not in a]: args.append('bootstrap') # if -c was provided, we push it back into args for buildout's main function if options.config_file is not None: args[0:0] = ['-c', options.config_file] zc.buildout.buildout.main(args) if not options.eggs: # clean up temporary egg directory shutil.rmtree(eggs_dir) zope.untrustedpython-4.0.0/buildout.cfg0000664000000000000000000000107012106565726017006 0ustar rootroot[buildout] develop = . parts = test coverage-test coverage-report python [test] recipe = zc.recipe.testrunner eggs = zope.untrustedpython [coverage-test] recipe = zc.recipe.testrunner eggs = zope.untrustedpython defaults = ['--coverage', '${buildout:directory}/coverage'] [coverage-report] recipe = zc.recipe.egg eggs = z3c.coverage scripts = coveragereport=coverage-report arguments = ('${buildout:directory}/coverage', '${buildout:directory}/coverage/report') [python] recipe = zc.recipe.egg eggs = zope.untrustedpython interpreter = python zope.untrustedpython-4.0.0/tox.ini0000664000000000000000000000166312106565726016021 0ustar rootroot[tox] envlist = py26,py27,docs,coverage [testenv] commands = python setup.py test -q # without explicit deps, setup.py test will download a bunch of eggs into $PWD deps = RestrictedPython zope.security zope.testrunner [testenv:coverage] basepython = python2.7 commands = # The installed version messes up nose's test discovery / coverage reporting # So, we uninstall that from the environment, and then install the editable # version, before running nosetests. pip uninstall -y zope.untrustedpython pip install -e . nosetests --with-xunit --with-xcoverage deps = nose coverage nosexcover [testenv:docs] basepython = python2.6 commands = sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html sphinx-build -b doctest -d docs/_build/doctrees docs docs/_build/doctest deps = RestrictedPython zope.security zope.testrunner repoze.sphinx.autointerface zope.untrustedpython-4.0.0/src/0000775000000000000000000000000012357322552015263 5ustar rootrootzope.untrustedpython-4.0.0/src/zope/0000775000000000000000000000000012357322552016240 5ustar rootrootzope.untrustedpython-4.0.0/src/zope/untrustedpython/0000775000000000000000000000000012357322552021537 5ustar rootrootzope.untrustedpython-4.0.0/src/zope/untrustedpython/builtins.py0000664000000000000000000001116512106565726023752 0ustar rootroot############################################################################## # # Copyright (c) 2002 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE # ############################################################################## """Protection of builtin objects. """ from zope.security.proxy import ProxyFactory import new def SafeBuiltins(): builtins = {} from zope.security.checker import NamesChecker import __builtin__ _builtinTypeChecker = NamesChecker( ['__str__', '__repr__', '__name__', '__module__', '__bases__', '__call__']) # It's better to say what is safe than it say what is not safe for name in [ # Names of safe objects. See untrustedinterpreter.txt for a # definition of safe objects. 'ArithmeticError', 'AssertionError', 'AttributeError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'FloatingPointError', 'IOError', 'ImportError', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'OverflowWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TypeError', 'UnboundLocalError', 'UnicodeError', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '__debug__', '__name__', '__doc__', 'abs', 'apply', 'bool', 'buffer', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'divmod', 'filter', 'float', 'frozenset', 'getattr', 'hasattr', 'hash', 'hex', 'id', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'long', 'map', 'max', 'min', 'object', 'oct', 'ord', 'pow', 'property', 'quit', 'range', 'reduce', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip', 'True', 'False', # TODO: dir segfaults with a seg fault due to a bad tuple # check in merge_class_dict in object.c. The assert macro # seems to be doing the wrong think. Basically, if an object # has bases, then bases is assumed to be a tuple. #dir, ]: try: value = getattr(__builtin__, name) except AttributeError: pass else: if isinstance(value, type): value = ProxyFactory(value, _builtinTypeChecker) else: value = ProxyFactory(value) builtins[name] = value from sys import modules def _imp(name, fromlist, prefix=''): module = modules.get(prefix+name) if module is not None: if fromlist or ('.' not in name): return module return modules[prefix+name.split('.')[0]] def __import__(name, globals=None, locals=None, fromlist=()): # Waaa, we have to emulate __import__'s weird semantics. if globals: __name__ = globals.get('__name__') if __name__: # Maybe do a relative import if '__path__' not in globals: # We have an ordinary module, not a package, # so remove last name segment: __name__ = '.'.join(__name__.split('.')[:-1]) if __name__: module = _imp(name, fromlist, __name__+'.') if module is not None: return module module = _imp(name, fromlist) if module is not None: return module raise ImportError(name) builtins['__import__'] = ProxyFactory(__import__) return builtins class ImmutableModule(new.module): def __init__(self, name='__builtins__', **kw): new.module.__init__(self, name) self.__dict__.update(kw) def __setattr__(self, name, v): raise AttributeError(name) def __delattr__(self, name): raise AttributeError(name) SafeBuiltins = ImmutableModule(**SafeBuiltins()) zope.untrustedpython-4.0.0/src/zope/untrustedpython/__init__.py0000664000000000000000000000000212106565726023644 0ustar rootroot# zope.untrustedpython-4.0.0/src/zope/untrustedpython/interpreter.py0000664000000000000000000000367412106565726024472 0ustar rootroot############################################################################## # # Copyright (c) 2002 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE # ############################################################################## """Restricted interpreter. TODO: This code needs a serious security review!!! """ from zope.untrustedpython.builtins import SafeBuiltins from zope.untrustedpython.rcompile import compile def exec_code(code, globals, locals=None): globals['__builtins__'] = SafeBuiltins exec code in globals, locals def exec_src(source, globals, locals=None): globals['__builtins__'] = SafeBuiltins code = compile(source, '', 'exec') exec code in globals, locals class CompiledExpression(object): """A compiled expression """ def __init__(self, source, filename=''): self.source = source self.code = compile(source, filename, 'eval') def eval(self, globals, locals=None): globals['__builtins__'] = SafeBuiltins if locals is None: return eval(self.code, globals) else: return eval(self.code, globals, locals) class CompiledProgram(object): """A compiled expression """ def __init__(self, source, filename=''): self.source = source self.code = compile(source, filename, 'exec') def exec_(self, globals, locals=None, output=None): globals['__builtins__'] = SafeBuiltins if output is not None: globals['untrusted_output'] = output exec self.code in globals, locals zope.untrustedpython-4.0.0/src/zope/untrustedpython/tests.py0000664000000000000000000001410012106565726023253 0ustar rootroot############################################################################## # # Copyright (c) 2001, 2002 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """Tests for zope.security.checker """ import unittest from zope.untrustedpython import interpreter, rcompile from zope.untrustedpython.builtins import SafeBuiltins class Test_SafeBuiltins(unittest.TestCase): def test_simple(self): d = {'__builtins__': SafeBuiltins} exec 'x = str(1)' in d self.assertEqual(d['x'], '1') def test_immutable(self): self.assertRaises( AttributeError, setattr, SafeBuiltins, 'foo', 1) self.assertRaises( AttributeError, delattr, SafeBuiltins, 'foo') def test_no_unsafe_objects(self): self.assertRaises( AttributeError, getattr, SafeBuiltins, 'eval') self.assertRaises( AttributeError, getattr, SafeBuiltins, 'globals') def test_import(self): imp = SafeBuiltins.__import__ import zope.security self.assertEqual(imp('zope.security'), zope) self.assertEqual(imp('zope.security', {}, {}, ['*']), zope.security) self.assertEqual(type(imp('zope.security')), zope.security.proxy.Proxy) def test_no_new_import(self): imp = SafeBuiltins.__import__ import zope.security security = zope.security import sys del sys.modules['zope.security'] self.assertRaises(ImportError, imp, 'zope.security') sys.modules['zope.security'] = security def test_relative_import(self): imp = SafeBuiltins.__import__ import zope.security self.assertEqual( imp('security', {'__name__': 'zope', '__path__': []}), zope.security) self.assertEqual( imp('security', {'__name__': 'zope.foo'}), zope.security) class Test_Interpreter(unittest.TestCase): def test_simple(self): d = {} interpreter.exec_src("x=1", d) self.assertEqual(d['x'], 1) self.assertEqual(d['__builtins__'], SafeBuiltins) def test_proxied(self): d = {} interpreter.exec_src('str=str', d) from zope.security.proxy import Proxy self.assertEqual(type(d['str']), Proxy) def test_no_builtins_mutations(self): from zope.security.interfaces import ForbiddenAttribute d = {} interpreter.exec_src("x=1", d) self.assertRaises( ForbiddenAttribute, interpreter.exec_src, '__builtins__.__dict__["x"] = 1', d) self.assertRaises( ForbiddenAttribute, interpreter.exec_src, 'del __builtins__.__dict__["str"]', d) self.assertRaises( ForbiddenAttribute, interpreter.exec_src, '__builtins__.__dict__.update({"x": 1})', d) def test_no_exec(self): d = {} self.assertRaises(SyntaxError, interpreter.exec_src, "exec 'x=1'", d) def test_exec_code(self): d = {} code = compile('x=2', '', 'exec') interpreter.exec_code(code, d) self.assertEqual(d['x'], 2) class Test_Compiled(unittest.TestCase): def test_CompiledProgram_simple(self): p = interpreter.CompiledProgram('x=2') d = {} p.exec_(d) self.assertEqual(d['x'], 2) def test_CompiledProgram_output_capturing(self): p = interpreter.CompiledProgram('print "Hello world!"') import StringIO f = StringIO.StringIO() p.exec_({}, output=f) self.assertEqual(f.getvalue(), 'Hello world!\n') def test_CompiledExpression_simple(self): p = interpreter.CompiledExpression('x*2') self.assertEqual(p.eval({'x': 2}), 4) self.assertEqual(p.eval({}, {'x': 2}), 4) def test_CompiledCode_simple(self): code = rcompile.compile("21 * 2", "", "eval") self.assertEqual(eval(code), 42) self.assertRaises( TypeError, rcompile.compile, object(), '', 'eval') def test_CompiledCode_statements(self): exec rcompile.compile("x = 1", "", "exec") self.assertEqual(x, 1) def test_CompiledCode_no_exec(self): self.assertRaises( SyntaxError, rcompile.compile, "exec 'x = 2'", "", "exec") self.assertRaises( SyntaxError, rcompile.compile, "raise KeyError('x')", "", "exec") self.assertRaises( SyntaxError, rcompile.compile, "try: pass\nexcept: pass", "", "exec") def test_CompiledCode_explicit_writable(self): import StringIO f = StringIO.StringIO() code = rcompile.compile( "print >> f, 'hi',\nprint >> f, 'world'", '', 'exec') exec code in {'f': f} self.assertEqual(f.getvalue(), 'hi world\n') def test_CompiledCode_default_output(self): def _exec(code, locals): exec code in locals code = rcompile.compile("print 'hi',\nprint 'world'", '', 'exec') self.assertRaises(NameError, _exec, code, {}) import StringIO f = StringIO.StringIO() _exec(code, {'untrusted_output': f}) self.assertEqual(f.getvalue(), 'hi world\n') class Test_RestrictionMutator(unittest.TestCase): def test_error_no_line_info(self): rm = rcompile.RestrictionMutator() rm.error(None, 'nothing') self.assertEqual(rm.errors, ['nothing']) def test_suite(): return unittest.TestSuite(( unittest.makeSuite(Test_SafeBuiltins), unittest.makeSuite(Test_Interpreter), unittest.makeSuite(Test_Compiled), unittest.makeSuite(Test_RestrictionMutator), )) zope.untrustedpython-4.0.0/src/zope/untrustedpython/rcompile.py0000664000000000000000000000620212106565726023727 0ustar rootroot############################################################################## # # Copyright (c) 2004 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """compile() equivalent that produces restricted code. Only 'eval' is supported at this time. """ import compiler.pycodegen import RestrictedPython.RCompile from RestrictedPython.SelectCompiler import ast def compile(text, filename, mode): if not isinstance(text, basestring): raise TypeError("Compiled source must be string") gen = RExpression(text, str(filename), mode) gen.compile() return gen.getCode() class RExpression(RestrictedPython.RCompile.RestrictedCompileMode): CodeGeneratorClass = compiler.pycodegen.ExpressionCodeGenerator def __init__(self, source, filename, mode = "eval"): self.mode = mode RestrictedPython.RCompile.RestrictedCompileMode.__init__( self, source, filename) self.rm = RestrictionMutator() # The security checks are performed by a set of six functions that # must be provided by the restricted environment. _getattr_name = ast.Name("getattr") class RestrictionMutator: def __init__(self): self.errors = [] self.warnings = [] self.used_names = {} def error(self, node, info): """Records a security error discovered during compilation.""" lineno = getattr(node, 'lineno', None) if lineno is not None and lineno > 0: self.errors.append('Line %d: %s' % (lineno, info)) else: self.errors.append(info) def visitGetattr(self, node, walker): """Converts attribute access to a function call. 'foo.bar' becomes 'getattr(foo, "bar")'. Also prevents augmented assignment of attributes, which would be difficult to support correctly. """ node = walker.defaultVisitNode(node) return ast.CallFunc(_getattr_name, [node.expr, ast.Const(node.attrname)]) def visitExec(self, node, walker): self.error(node, "exec statements are not supported") def visitPrint(self, node, walker): """Make sure prints always have a destination If we get a print without a destination, make the default destination untrusted_output. """ node = walker.defaultVisitNode(node) if node.dest is None: node.dest = ast.Name('untrusted_output') return node visitPrintnl = visitPrint def visitRaise(self, node, walker): self.error(node, "raise statements are not supported") def visitTryExcept(self, node, walker): self.error(node, "try/except statements are not supported") zope.untrustedpython-4.0.0/src/zope/__init__.py0000664000000000000000000000007012106565726020352 0ustar rootroot__import__('pkg_resources').declare_namespace(__name__) zope.untrustedpython-4.0.0/src/zope.untrustedpython.egg-info/0000775000000000000000000000000012357322552023230 5ustar rootrootzope.untrustedpython-4.0.0/src/zope.untrustedpython.egg-info/zip-safe0000664000000000000000000000000112106565726024664 0ustar rootroot zope.untrustedpython-4.0.0/src/zope.untrustedpython.egg-info/top_level.txt0000664000000000000000000000000512106565744025761 0ustar rootrootzope zope.untrustedpython-4.0.0/src/zope.untrustedpython.egg-info/dependency_links.txt0000664000000000000000000000000112106565744027302 0ustar rootroot zope.untrustedpython-4.0.0/src/zope.untrustedpython.egg-info/SOURCES.txt0000664000000000000000000000115612106565744025123 0ustar rootrootCHANGES.rst MANIFEST.in README.rst bootstrap.py buildout.cfg setup.py tox.ini src/zope/__init__.py src/zope.untrustedpython.egg-info/PKG-INFO src/zope.untrustedpython.egg-info/SOURCES.txt src/zope.untrustedpython.egg-info/dependency_links.txt src/zope.untrustedpython.egg-info/namespace_packages.txt src/zope.untrustedpython.egg-info/requires.txt src/zope.untrustedpython.egg-info/top_level.txt src/zope.untrustedpython.egg-info/zip-safe src/zope/untrustedpython/__init__.py src/zope/untrustedpython/builtins.py src/zope/untrustedpython/interpreter.py src/zope/untrustedpython/rcompile.py src/zope/untrustedpython/tests.pyzope.untrustedpython-4.0.0/src/zope.untrustedpython.egg-info/namespace_packages.txt0000664000000000000000000000000512106565744027562 0ustar rootrootzope zope.untrustedpython-4.0.0/src/zope.untrustedpython.egg-info/requires.txt0000664000000000000000000000005112106565744025630 0ustar rootrootsetuptools RestrictedPython zope.securityzope.untrustedpython-4.0.0/src/zope.untrustedpython.egg-info/PKG-INFO0000664000000000000000000000232412106565744024332 0ustar rootrootMetadata-Version: 1.1 Name: zope.untrustedpython Version: 4.0.0 Summary: Zope Untrusted Python Library Home-page: http://github.com/zopefoundation/zope.untrustedpython Author: Zope Foundation and Contributors Author-email: zope-dev@zope.org License: ZPL 2.1 Description: Untrusted python library ======= CHANGES ======= 4.0.0 (2013-02-12) ------------------ - Test coverage at 100%. - Package extracted from zope.security, preserving revision history Keywords: zope untrusted python Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Zope Public License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Natural Language :: English Classifier: Operating System :: OS Independent Classifier: Topic :: Internet :: WWW/HTTP Classifier: Framework :: Zope3 zope.untrustedpython-4.0.0/setup.cfg0000664000000000000000000000007312106565752016320 0ustar rootroot[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 zope.untrustedpython-4.0.0/MANIFEST.in0000664000000000000000000000023512106565726016236 0ustar rootrootinclude *.rst include *.txt include tox.ini include bootstrap.py include buildout.cfg recursive-include src * recursive-include doc * global-exclude *.pyc zope.untrustedpython-4.0.0/PKG-INFO0000664000000000000000000000232412106565752015575 0ustar rootrootMetadata-Version: 1.1 Name: zope.untrustedpython Version: 4.0.0 Summary: Zope Untrusted Python Library Home-page: http://github.com/zopefoundation/zope.untrustedpython Author: Zope Foundation and Contributors Author-email: zope-dev@zope.org License: ZPL 2.1 Description: Untrusted python library ======= CHANGES ======= 4.0.0 (2013-02-12) ------------------ - Test coverage at 100%. - Package extracted from zope.security, preserving revision history Keywords: zope untrusted python Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Zope Public License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Natural Language :: English Classifier: Operating System :: OS Independent Classifier: Topic :: Internet :: WWW/HTTP Classifier: Framework :: Zope3 zope.untrustedpython-4.0.0/setup.py0000664000000000000000000000514012106565726016212 0ustar rootroot############################################################################# # # Copyright (c) 2006 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## # This package is developed by the Zope Toolkit project, documented here: # http://docs.zope.org/zopetoolkit # When developing and releasing this package, please follow the documented # Zope Toolkit policies as described by this documentation. ############################################################################## """Setup for zope.security package """ import os from setuptools import find_packages, setup here = os.path.abspath(os.path.dirname(__file__)) def read(*rnames): return open(os.path.join(os.path.dirname(__file__), *rnames)).read() setup(name='zope.untrustedpython', version='4.0.0', author='Zope Foundation and Contributors', author_email='zope-dev@zope.org', description='Zope Untrusted Python Library', long_description=( read('README.rst') + '\n\n' + read('CHANGES.rst') ), keywords = "zope untrusted python", classifiers = [ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', 'Intended Audience :: Developers', 'License :: OSI Approved :: Zope Public License', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: Implementation :: CPython', 'Natural Language :: English', 'Operating System :: OS Independent', 'Topic :: Internet :: WWW/HTTP', 'Framework :: Zope3'], url='http://github.com/zopefoundation/zope.untrustedpython', license='ZPL 2.1', packages=find_packages('src'), package_dir = {'': 'src'}, namespace_packages=['zope'], install_requires=[ 'setuptools', 'RestrictedPython', 'zope.security', ], test_suite = 'zope.untrustedpython.tests.test_suite', include_package_data = True, zip_safe = True, )