Skip to content

Commit

Permalink
Merge to evan-script_fix-merge-3
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Simpson committed Apr 11, 2001
1 parent 63727f8 commit d12b04c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
13 changes: 13 additions & 0 deletions www/default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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
23 changes: 15 additions & 8 deletions zbytecodehacks/VSExec.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ def __init__(self, src, name='<function>', filename='<string>'):
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):
Expand Down Expand Up @@ -198,7 +207,7 @@ def munge(self, fc, depth=0):
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)
Expand All @@ -217,6 +226,7 @@ def munge(self, fc, depth=0):
break
else:
window.do_op()

def __call__(self, *args, **kargs):
F = code_editor.Function(self.t)
F.func_globals = self.globals
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions zbytecodehacks/code_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ def set_name(self, name):
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.
Expand Down

0 comments on commit d12b04c

Please sign in to comment.