Commit 1d45d7a1 authored by Jim Fulton's avatar Jim Fulton

new interface and now can use bound methods

parent 8a2d343a
......@@ -16,10 +16,8 @@ modules={}
addForm=HTMLFile('methodAdd', globals())
def add(self, id, title, external_name, REQUEST=None):
def add(self, id, title, module, function, REQUEST=None):
"""Add an external method to a folder"""
names=split(external_name,'.')
module, function = join(names[:-1],'.'), names[-1]
i=ExternalMethod(id,title,module,function)
self._setObject(id,i)
return self.manage_main(self,REQUEST)
......@@ -40,22 +38,16 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent,
{'label':'Access Control', 'action':'manage_access'},
)
def __init__(self, id='', title='', module='', function=''):
if id:
def __init__(self, id, title, module, function):
self.id=id
self.title=title
self._module=module
self._function=function
self.getFunction()
self._p_atime=1
self.manage_edit(title, module, function)
manage_main=HTMLFile('methodEdit', globals())
def manage_edit(self, title, REQUEST=None):
def manage_edit(self, title, module, function, REQUEST=None):
"Change the external method"
self.title=title
names=split(external_name,'.')
module, function = join(names[:-1],'.'), names[-1]
if module[-3:]=='.py': module=module[:-3]
elif module[-4:]=='.py': module=module[:-4]
self._module=module
self._function=function
try: del modules[module]
......@@ -64,11 +56,9 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent,
if REQUEST: return MessageDialog(
title ='Changed %s' % self.id,
message='%s has been updated' % self.id,
action =REQUEST['URL2']+'/manage_main',
action =REQUEST['URL1']+'/manage_main',
target ='manage_main')
def external_name(self): return "%s.%s" % (self._module, self._function)
def getFunction(self):
module=self._module
......@@ -83,10 +73,13 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent,
modules[module]=m
f=m[self._function]
if self.func_defaults != f.func_defaults:
self.func_defaults = f.func_defaults
if hasattr(f,'im_func'): ff=f.im_func
else: ff=f
if self.func_defaults != ff.func_defaults:
self.func_defaults = ff.func_defaults
func_code=FuncCode(f)
func_code=FuncCode(ff,f is not ff)
if func_code != self.func_code: self.func_code=func_code
self._v_f=f
......@@ -99,13 +92,14 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent,
return apply(f,args)
def function(self): return self._function
def module(self): return self._module
class FuncCode:
def __init__(self, f=None):
if f is not None:
self.co_varnames=f.func_code.co_varnames
self.co_argcount=f.func_code.co_argcount
def __init__(self, f, im=0):
self.co_varnames=f.func_code.co_varnames[im:]
self.co_argcount=f.func_code.co_argcount-im
def __cmp__(self,other):
return cmp((self.co_argcount, self.co_varnames),
......
......@@ -16,12 +16,10 @@
<TD ALIGN="LEFT" VALIGN="TOP"><B>Title</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP"><INPUT TYPE="TEXT" NAME="title" SIZE="50"></TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP"><B>External name</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="TEXT" NAME="external_name" SIZE="50">
</TD>
</TR>
<tr> <th>Function name</th>
<td><input name="function" size="30"></td></tr>
<tr> <th>Python module file</th>
<td><input name="module" size="30"></td></tr>
<TR>
<TD></TD>
<TD><BR><INPUT TYPE="SUBMIT" VALUE="Add"></TD>
......
......@@ -19,13 +19,13 @@
<INPUT TYPE="TEXT" NAME="title" SIZE="50" VALUE="<!--#var title-->">
</TD>
</TR>
<tr> <th>Function name</th>
<td><input name="function" size="30"
value="<!--#var function-->"></td></tr>
<tr> <th>Python module file (without suffix)</th>
<td><input name="module" size="30"
value="<!--#var module-->"></td></tr>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP"><B>External name</B></TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="TEXT" NAME="external_name" SIZE="50"
VALUE="<!--#var external_name-->">
</TD>
</TR>
<TR>
<TD></TD>
<TD><BR><INPUT TYPE="SUBMIT" VALUE="Edit"></TD>
......
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