Commit 0bb5dddb authored by Jérome Perrin's avatar Jérome Perrin

patches/ExternalMethod update patch for Zope4

In the changes from ExternalMethod 2.13.1 -> 4.5, now ExternalMethod
define __code__ (and __defaults__) to a computed attribute calling
getFunction, but getFunction is different in our patched class, so
when unwrapMethod tries to get __code__, it will raise and mapply
will not consider the external method as being callable, so a simple
__repr__ of the ExternalMethod will be used as response body when
published.

By defining __code__ to something using our patched logic, this
problem does not happen.

There's also a TODO because DevelopmentMode is now True, which uses
a different code path which was causing TypeError, because getPath
returns None, which os.stat does not accept.
parent 27717221
...@@ -24,7 +24,7 @@ class _(PatchClass(ExternalMethod)): ...@@ -24,7 +24,7 @@ class _(PatchClass(ExternalMethod)):
reloadIfChanged = getFuncDefaults = getFuncCode = filepath = None reloadIfChanged = getFuncDefaults = getFuncCode = filepath = None
@property @property
def func_defaults(self): def __defaults__(self):
"""Return a tuple of default values. """Return a tuple of default values.
The first value is for the "second" parameter (self is ommited) The first value is for the "second" parameter (self is ommited)
...@@ -33,10 +33,12 @@ class _(PatchClass(ExternalMethod)): ...@@ -33,10 +33,12 @@ class _(PatchClass(ExternalMethod)):
will have func_defaults = ('', ) will have func_defaults = ('', )
""" """
return self._getFunction()[1] return self._getFunction()[1]
func_defaults = __defaults__
@property @property
def func_code(self): def __code__(self):
return self._getFunction()[2] return self._getFunction()[2]
func_code = __code__
@property @property
def func_args(self): def func_args(self):
...@@ -57,6 +59,7 @@ class _(PatchClass(ExternalMethod)): ...@@ -57,6 +59,7 @@ class _(PatchClass(ExternalMethod)):
if component_module is None: if component_module is None:
# Fall back on filesystem # Fall back on filesystem
if not reload: if not reload:
# TODO Zope4: DevelopmentMode is True ( on Zope2 Globals.DevelopmentMode was False )
from Products.ERP5Type.Globals import DevelopmentMode from Products.ERP5Type.Globals import DevelopmentMode
if DevelopmentMode: if DevelopmentMode:
try: try:
...@@ -65,10 +68,11 @@ class _(PatchClass(ExternalMethod)): ...@@ -65,10 +68,11 @@ class _(PatchClass(ExternalMethod)):
last_read = None last_read = None
path = getPath('Extensions', self._module, path = getPath('Extensions', self._module,
suffixes=('', 'py', 'pyc')) suffixes=('', 'py', 'pyc'))
ts = os.stat(path)[stat.ST_MTIME] if path:
if last_read != ts: ts = os.stat(path)[stat.ST_MTIME]
self._v_fs = ts, path if last_read != ts:
reload = True self._v_fs = ts, path
reload = True
f = getObject(self._module, self._function, reload) f = getObject(self._module, self._function, reload)
else: else:
f = getattr(component_module, self._function) f = getattr(component_module, self._function)
......
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