Commit eaae74a0 authored by Jérome Perrin's avatar Jérome Perrin

*: keep using func_code and not yet __code__ with scripts

On Zope2, python scripts do not have __code__, they only have
func_code (and same for __defauls__/func_defaults).
We tried to backport the support of __code__ from Zope4 as a Zope2
patch - it was SlapOS patch 4fa33dfc6 (erp5: py3: `func_{code,defaults}`
was replaced in Python3 by `__{code,defaults}__`., 2022-04-25),
but this patch was incomplete. We tried to backport more, but then
realized that we don't need to use __code__ on ERP5 master yet,
because ERP5 master branch is still supporting Zope2 only.

This patch revert a small part of a17bb910 (py2/py3: Make Products
code compatible with both python2 and python3., 2022-04-13), the part
where we use f.__code__ where f might be a python script. For now,
we'll apply this patch only on the Zope4 branch.

A few places where f.func_code was used and f was a for sure not a
python script but a simple class method or function are kept here, as
__code__ support is missing only on in ZODB scripts.
parent 83e69b6b
Pipeline #21684 failed with stage
in 0 seconds
......@@ -164,7 +164,7 @@ class Alarm(XMLObject, PeriodicityMixin):
activate_kw['tag'] = '%s_%x' % (self.getRelativeUrl(), getrandbits(32))
tag = activate_kw['tag']
method = getattr(self, method_id)
func_code = method.__code__
func_code = method.func_code
try:
has_kw = func_code.co_flags & CO_VARKEYWORDS
except AttributeError:
......
......@@ -41,7 +41,7 @@ class Accessor(Method):
def __getinitargs__(self):
init = getattr(self, '__init__', None)
if init is not None:
varnames = init.__code__.co_varnames
varnames = init.func_code.co_varnames
args = []
for name in varnames:
if name == 'self':
......
......@@ -181,7 +181,7 @@ class Predicate(XMLObject):
try:
result = method(self)
except TypeError:
if method.__code__.co_argcount != isinstance(method, MethodType):
if method.func_code.co_argcount != isinstance(method, MethodType):
raise
# backward compatibilty with script that takes no argument
warn('Predicate %s uses an old-style method (%s) that does not'
......
......@@ -71,8 +71,8 @@ class InteractorMethod(Method):
self.after_action_list = []
self.before_action_list = []
self.method = method
self.__code__ = self.func_code = method.__code__
self.__defaults__ = self.func_defaults = method.__defaults__
self.func_code = method.func_code
self.func_defaults = method.func_defaults
self.__name__ = method.__name__
def registerBeforeAction(self, action, args, kw):
......
......@@ -234,7 +234,7 @@ def deprecated(message=''):
@simple_decorator
def _deprecated(wrapped):
m = message or "Use of '%s' function (%s, line %s) is deprecated." % (
wrapped.__name__, wrapped.__module__, wrapped.__code__.co_firstlineno)
wrapped.__name__, wrapped.__module__, wrapped.func_code.co_firstlineno)
def deprecated(*args, **kw):
warnings.warn(m, DeprecationWarning, 2)
return wrapped(*args, **kw)
......
......@@ -44,7 +44,7 @@ def volatileCached(self, func):
self._v_SimpleItem_Item_vCache = cache_dict = {}
# Use whole func_code as a key, as it is the only reliable way to identify a
# function.
key = func.__code__
key = func.func_code
try:
return cache_dict[key]
except KeyError:
......
......@@ -1452,7 +1452,7 @@ class Catalog(Folder,
if meta_type in self.HAS_ARGUMENT_SRC_METATYPE_SET:
return method.arguments_src.split()
elif meta_type in self.HAS_FUNC_CODE_METATYPE_SET:
return method.__code__.co_varnames[:method.__code__.co_argcount]
return method.func_code.co_varnames[:method.func_code.co_argcount]
# Note: Raising here would completely prevent indexation from working.
# Instead, let the method actually fail when called, so _catalogObjectList
# can log the error and carry on.
......@@ -1838,7 +1838,7 @@ class Catalog(Folder,
else:
search_key = self.getSearchKey(key, 'RelatedKey')
else:
func_code = script.__code__
func_code = script.func_code
search_key = (
AdvancedSearchKeyWrapperForScriptableKey if (
# 5: search_value (under any name), "search_key", "group",
......
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