Skip to content

Commit

Permalink
Clean up indentation and trailing whitespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martijn Pieters committed Aug 14, 2002
1 parent 5a1de47 commit c896fc6
Show file tree
Hide file tree
Showing 24 changed files with 112 additions and 130 deletions.
13 changes: 6 additions & 7 deletions Eval.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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 Python Expressions
"""
__rcs_id__='$Id: Eval.py,v 1.4 2001/11/28 15:51:11 matt Exp $'
__version__='$Revision: 1.4 $'[11:-2]
__rcs_id__='$Id: Eval.py,v 1.5 2002/08/14 21:44:31 mj Exp $'
__version__='$Revision: 1.5 $'[11:-2]

from string import translate, strip
import string
Expand Down Expand Up @@ -84,8 +84,8 @@ def prepUnrestrictedCode(self):
i=0
code=co.co_code
l=len(code)
LOAD_NAME=101
HAVE_ARGUMENT=90
LOAD_NAME=101
HAVE_ARGUMENT=90
while(i < l):
c=ord(code[i])
if c==LOAD_NAME:
Expand Down Expand Up @@ -119,4 +119,3 @@ def eval(self, mapping):

def __call__(self, **kw):
return self.eval(kw)

14 changes: 5 additions & 9 deletions Guards.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
#
##############################################################################
from __future__ import nested_scopes

__version__='$Revision: 1.7 $'[11:-2]
__version__='$Revision: 1.8 $'[11:-2]

import new

Expand Down Expand Up @@ -58,7 +58,7 @@ def __setitem__(self, index, val):
def __setattr__(self, attr, val):
setattr(write(ob), attr, val)
return Wrapper()
return guard
return guard


def _write_wrapper():
Expand Down Expand Up @@ -100,7 +100,7 @@ def guard(ob, safetype=safetype, Wrapper=Wrapper):
return ob
# Hand the object to the Wrapper instance, then return the instance.
return Wrapper(ob)
return guard
return guard
full_write_guard = _full_write_guard()

def guarded_setattr(object, name, value):
Expand All @@ -110,7 +110,3 @@ def guarded_setattr(object, name, value):
def guarded_delattr(object, name):
delattr(full_write_guard(object), name)
safe_builtins['delattr'] = guarded_delattr




7 changes: 3 additions & 4 deletions Limits.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
#
##############################################################################

__version__='$Revision: 1.3 $'[11:-2]
__version__='$Revision: 1.4 $'[11:-2]

limited_builtins = {}

Expand Down Expand Up @@ -44,4 +44,3 @@ def limited_tuple(seq):
raise TypeError, 'cannot convert string to tuple'
return tuple(seq)
limited_builtins['tuple'] = limited_tuple

7 changes: 3 additions & 4 deletions MutatingWalker.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
#
##############################################################################

__version__='$Revision: 1.5 $'[11:-2]
__version__='$Revision: 1.6 $'[11:-2]

from SelectCompiler import ast

Expand Down Expand Up @@ -72,4 +72,3 @@ def dispatchNode(self, node):

def walk(tree, visitor):
return MutatingWalker(visitor).dispatchNode(tree)

6 changes: 3 additions & 3 deletions PrintCollector.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
#
##############################################################################

__version__='$Revision: 1.3 $'[11:-2]
__version__='$Revision: 1.4 $'[11:-2]

class PrintCollector:
'''Collect written text, and return it when called.'''
Expand Down
7 changes: 3 additions & 4 deletions RCompile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
#
##############################################################################
"""Compiles restricted code using the compiler module from the
Python standard library.
"""

__version__='$Revision: 1.2 $'[11:-2]
__version__='$Revision: 1.3 $'[11:-2]


from compiler import ast, parse, misc, syntax
Expand Down Expand Up @@ -146,4 +146,3 @@ def compile_restricted(source, filename, mode):
"'eval' or 'single'")
gen.compile()
return gen.getCode()

66 changes: 33 additions & 33 deletions RCompile_2_1.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
#
##############################################################################

__version__='$Revision: 1.2 $'[11:-2]
__version__='$Revision: 1.3 $'[11:-2]

import sys
from traceback import format_exception_only
Expand Down Expand Up @@ -56,7 +56,7 @@ def compile_restricted_function(p, body, name, filename):
if err:
if len(err) > 1:
# Drop the first line of the error and adjust the next two.
err[1].pop(0)
err[1].pop(0)
err[1][0] = 'parameters: %s\n' % err[1][0][10:-8]
err[1][1] = ' ' + err[1][1]
return err
Expand Down Expand Up @@ -94,38 +94,38 @@ def compile_restricted_exec(s, filename='<string>', nested_scopes=1):
return gen.getCode(), (), rm.warnings, rm.used_names

if 1:
def compile_restricted_eval(s, filename='<string>', nested_scopes=1):
'''Compile a restricted expression.'''
r = compile_restricted_exec('def f(): return \\\n' + s, filename,
nested_scopes)
err = r[1]
if err:
if len(err) > 1:
err.pop(0) # Discard first line of error
else:
# Extract the code object representing the function body
r = (r[0].co_consts[1],) + r[1:]
return r
def compile_restricted_eval(s, filename='<string>', nested_scopes=1):
'''Compile a restricted expression.'''
r = compile_restricted_exec('def f(): return \\\n' + s, filename,
nested_scopes)
err = r[1]
if err:
if len(err) > 1:
err.pop(0) # Discard first line of error
else:
# Extract the code object representing the function body
r = (r[0].co_consts[1],) + r[1:]
return r

else:

def compile_restricted_eval(s, filename='<string>'):
'''Compile a restricted expression.'''
rm = RestrictionMutator()
tree, err = tryParsing(s, 'eval')
if err:
err[1].pop(0) # Discard first line of error
return err
MutatingWalker.walk(tree, rm)
if rm.errors:
return None, rm.errors, rm.warnings, rm.used_names
# XXX No "EvalCodeGenerator" exists
# so here's a hack that gets around it.
gen = pycodegen.ModuleCodeGenerator(filename)
gen.emit('SET_LINENO', 0)
visitor.walk(tree, gen)
gen.emit('RETURN_VALUE')
return gen.getCode(), (), rm.warnings, rm.used_names
def compile_restricted_eval(s, filename='<string>'):
'''Compile a restricted expression.'''
rm = RestrictionMutator()
tree, err = tryParsing(s, 'eval')
if err:
err[1].pop(0) # Discard first line of error
return err
MutatingWalker.walk(tree, rm)
if rm.errors:
return None, rm.errors, rm.warnings, rm.used_names
# XXX No "EvalCodeGenerator" exists
# so here's a hack that gets around it.
gen = pycodegen.ModuleCodeGenerator(filename)
gen.emit('SET_LINENO', 0)
visitor.walk(tree, gen)
gen.emit('RETURN_VALUE')
return gen.getCode(), (), rm.warnings, rm.used_names

DEBUG = 0
def compile_restricted(source, filename, mode):
Expand Down
7 changes: 3 additions & 4 deletions RestrictionMutator.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
#
##############################################################################
'''
RestrictionMutator modifies a tree produced by
compiler.transformer.Transformer, restricting and enhancing the
code in various ways before sending it to pycodegen.
'''
__version__='$Revision: 1.9 $'[11:-2]
__version__='$Revision: 1.10 $'[11:-2]

from SelectCompiler import ast, parse, OP_ASSIGN, OP_DELETE, OP_APPLY

Expand Down Expand Up @@ -271,4 +271,3 @@ def visitModule(self, node, walker):
def visitAugAssign(self, node, walker):
node.node.in_aug_assign = 1
return walker.defaultVisitNode(node)

8 changes: 4 additions & 4 deletions SafeMapping.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
#
##############################################################################
__doc__='''Read-only Mapping class based on MultiMapping
$Id: SafeMapping.py,v 1.2 2001/11/28 15:51:11 matt Exp $'''
__version__='$Revision: 1.2 $'[11:-2]
$Id: SafeMapping.py,v 1.3 2002/08/14 21:44:31 mj Exp $'''
__version__='$Revision: 1.3 $'[11:-2]

from MultiMapping import MultiMapping

Expand Down
8 changes: 3 additions & 5 deletions SelectCompiler.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
#
##############################################################################
'''
Compiler selector.
$Id: SelectCompiler.py,v 1.3 2001/12/22 16:39:05 Brian Exp $
$Id: SelectCompiler.py,v 1.4 2002/08/14 21:44:31 mj Exp $
'''

import sys
Expand Down Expand Up @@ -40,5 +40,3 @@
compile_restricted_function, \
compile_restricted_exec, \
compile_restricted_eval


8 changes: 4 additions & 4 deletions Utilities.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
#
##############################################################################

__version__='$Revision: 1.6 $'[11:-2]
__version__='$Revision: 1.7 $'[11:-2]

import string, math, random, whrandom
import DocumentTemplate.sequence
Expand Down Expand Up @@ -65,7 +65,7 @@ def reorder(s, with=None, without=()):
if type(i) is tt and len(i)==2: k, v = i
else: k= v = i
if h(k): del d[k]

for i in with:
if type(i) is tt and len(i)==2: k, v = i
else: k= v = i
Expand Down
Loading

0 comments on commit c896fc6

Please sign in to comment.