Commit 43726a52 authored by 's avatar

Added a patch to careful_mul to fix a problem with sequence multiplication.

parent 95daedfa
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
############################################################################## ##############################################################################
"""Very Safe Python Expressions """Very Safe Python Expressions
""" """
__rcs_id__='$Id: VSEval.py,v 1.22 1999/08/03 20:09:02 jim Exp $' __rcs_id__='$Id: VSEval.py,v 1.23 1999/10/28 18:02:41 brian Exp $'
__version__='$Revision: 1.22 $'[11:-2] __version__='$Revision: 1.23 $'[11:-2]
from string import translate, strip from string import translate, strip
import string import string
...@@ -100,18 +100,24 @@ def default_slicer(env, s, *ind): ...@@ -100,18 +100,24 @@ def default_slicer(env, s, *ind):
return s[:] return s[:]
def careful_mul(env, *factors): def careful_mul(env, *factors):
# r = result (product of all factors)
# c = count (product of all non-sequence factors)
# s flags whether any of the factors is a sequence
r=c=1
s=None s=None
r=1
for factor in factors: for factor in factors:
try: try:
l=len(factor) l=len(factor)
s=1 s=1
except: l=factor except TypeError:
if s and (l*r) > 1000: raise TypeError, 'Illegal sequence repeat' c=c*factor
if s and c > 1000:
raise TypeError, \
'Illegal sequence repeat (too many repetitions: %d)' % c
r=r*factor r=r*factor
return r return r
default_globals={ default_globals={
'__builtins__':{}, '__builtins__':{},
'__guarded_mul__': careful_mul, '__guarded_mul__': careful_mul,
......
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