Commit a44cfa0c authored by Evan Simpson's avatar Evan Simpson

Merge to evan-script_fix-merge-3

parent 9ccb2125
# Example code:
# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE = request.RESPONSE
# Return a string identifying this script.
print "This is the", script.meta_type, '"%s"' % script.getId(),
if script.title:
print "(%s)" % html_quote(script.title),
print "in", container.absolute_url()
return printed
......@@ -166,6 +166,15 @@ class CodeBlock:
self.munge_data = {}
self.munge(f.func_code)
stack = []
max_stack = 0
for op in f.func_code.co_code.opcodes:
try: op.execute(stack)
except: stack = []
max_stack = max(max_stack, len(stack))
if max_stack > f.func_code.co_stacksize:
f.func_code.set_stacksize(max_stack)
if not self.errors: self.t = f.as_tuple()
def munge(self, fc, depth=0):
......@@ -198,7 +207,7 @@ class CodeBlock:
window.do_op()
elif op and forbid.get(op.op, 0):
errors.append(self.forbidden % (opname, line))
window.do_op() #???
window.do_op() # This is necessary to track stack usage.
else:
for m in mungers:
handler = getattr(m, opname, None)
......@@ -217,6 +226,7 @@ class CodeBlock:
break
else:
window.do_op()
def __call__(self, *args, **kargs):
F = code_editor.Function(self.t)
F.func_globals = self.globals
......@@ -417,13 +427,10 @@ def GuardedBinaryOps(guards):
def _wrap(w):
load_guard = ((ops.LOAD_FAST,), ((guard,),))
# Load the guard function before the guarded object, call after.
w.insert_code(load_guard, w.before_code_for(spos))
if spos == 0:
w.set_code(0, cf1)
else:
iops = w.insert_code(cf1, w.after_code_for(spos))
# Fix the execution stack.
if w.use_stack: w.stack[spos] = (w.stack[spos][0], iops[0])
iops1 = w.insert_code(load_guard, w.before_code_for(spos))
iops2 = w.insert_code(cf1, w.after_code_for(spos))
# Fix the execution stack.
if w.use_stack: w.stack[spos] = (iops1[0], iops2[0])
def _WriteGuardWrapper():
def model_handler(self, *args):
......
......@@ -252,6 +252,8 @@ class EditableCodeWorker:
self.co_name = name
def set_filename(self, filename):
self.co_filename = filename
def set_stacksize(self, stacksize):
self.co_stacksize = stacksize
def as_tuple(self):
# the assembling might change co_names or co_varnames - so
# make sure it's done *before* we start gathering them.
......
......@@ -329,7 +329,8 @@ class Bindings:
# Try to find unbound parameters in the namespace, if the
# namespace is bound.
if self.getBindingAssignments().isNameAssigned('name_ns'):
for name in self.func_code.co_varnames:
code = self.func_code
for name in code.co_varnames[:code.co_argcount]:
try:
namevals[name] = namespace[name]
except KeyError:
......
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