Skip to content

Commit

Permalink
Added computed attribute for mapply to make up for removal of func_* …
Browse files Browse the repository at this point in the history
…attributes from normal state in previous fix
  • Loading branch information
Jim Fulton committed Apr 23, 2002
1 parent 8bec5c5 commit 0100d9d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
17 changes: 10 additions & 7 deletions ExternalMethod.py
Expand Up @@ -16,14 +16,15 @@
This product provides support for external methods, which allow
domain-specific customization of web environments.
"""
__version__='$Revision: 1.47 $'[11:-2]
__version__='$Revision: 1.48 $'[11:-2]
from Globals import Persistent, DTMLFile, MessageDialog, HTML
import OFS.SimpleItem, Acquisition
import AccessControl.Role, sys, os, stat, traceback
from OFS.SimpleItem import pretty_tb
from App.Extensions import getObject, getPath, FuncCode
from Globals import DevelopmentMode
from App.Management import Navigation
from ComputedAttribute import ComputedAttribute

manage_addExternalMethodForm=DTMLFile('dtml/methodAdd', globals())

Expand Down Expand Up @@ -78,8 +79,9 @@ class ExternalMethod(OFS.SimpleItem.Item, Persistent, Acquisition.Explicit,
"""

meta_type = 'External Method'
_v_func_defaults = ()
_v_func_code = None

func_defaults = ComputedAttribute(lambda self: self._v_func_defaults)
func_code = ComputedAttribute(lambda self: self._v_func_code)

ZopeTime=Acquisition.Acquired
HelpSys=Acquisition.Acquired
Expand Down Expand Up @@ -126,12 +128,12 @@ def manage_edit(self, title, module, function, REQUEST=None):
elif module[-4:]=='.pyc': module=module[:-4]
self._module=module
self._function=function
self.getFunction(1,1)
self.getFunction(1)
if REQUEST:
message="External Method Uploaded."
return self.manage_main(self,REQUEST,manage_tabs_message=message)

def getFunction(self, check=0, reload=0):
def getFunction(self, reload=0):

f=getObject(self._module, self._function, reload)
if hasattr(f,'im_func'): ff=f.im_func
Expand Down Expand Up @@ -182,12 +184,13 @@ def __call__(self, *args, **kw):
ts=os.stat(self.filepath())[stat.ST_MTIME]
if (not hasattr(self, '_v_last_read') or
(ts != self._v_last_read)):
self._v_f=self.getFunction(1,1)
self._v_f=self.getFunction(1)
self._v_last_read=ts

if hasattr(self, '_v_f'):
f=self._v_f
else: f=self.getFunction()
else:
f=self.getFunction()

__traceback_info__=args, kw, self._v_func_defaults

Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Expand Up @@ -13,6 +13,6 @@
##############################################################################
"""
$Id: __init__.py,v 1.2 2002/04/22 21:54:48 jim Exp $
$Id: __init__.py,v 1.3 2002/04/23 13:04:20 jim Exp $
"""

12 changes: 11 additions & 1 deletion tests/testExternalMethod.py
Expand Up @@ -14,7 +14,7 @@
"""
Revision information:
$Id: testExternalMethod.py,v 1.2 2002/04/22 21:54:48 jim Exp $
$Id: testExternalMethod.py,v 1.3 2002/04/23 13:04:20 jim Exp $
"""

import math, os
Expand Down Expand Up @@ -45,6 +45,16 @@ def testStorage(self):
em2.__setstate__(state)
self.assertEqual(em2(9), math.sqrt(9))
self.failIf(state.has_key('func_defaults'))

def test_mapply(self):
from ZPublisher.mapply import mapply

em1 = ExternalMethod('em', 'test method', 'Test', 'testf')
self.assertEqual(mapply(em1, (), {'arg1': 4}), math.sqrt(4))
state = em1.__getstate__()
em2 = ExternalMethod.__basicnew__()
em2.__setstate__(state)
self.assertEqual(mapply(em1, (), {'arg1': 9}), math.sqrt(9))



Expand Down

0 comments on commit 0100d9d

Please sign in to comment.