From 0543484e4ef9d9ba1a48e1656142de223b948c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Wed, 15 Mar 2023 13:46:48 +0900 Subject: [PATCH] py2/py3: update classes using __metaclass__ --- .../module.erp5.WorkingCopy.py | 16 ++++++++-------- .../module.erp5.ExpandPolicy.py | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/bt5/erp5_forge/ModuleComponentTemplateItem/portal_components/module.erp5.WorkingCopy.py b/bt5/erp5_forge/ModuleComponentTemplateItem/portal_components/module.erp5.WorkingCopy.py index 2f83429c52..0040dc3c8e 100644 --- a/bt5/erp5_forge/ModuleComponentTemplateItem/portal_components/module.erp5.WorkingCopy.py +++ b/bt5/erp5_forge/ModuleComponentTemplateItem/portal_components/module.erp5.WorkingCopy.py @@ -43,6 +43,7 @@ from Products.ERP5.Document.BusinessTemplate import BusinessTemplateFolder from Products.ERP5Type.Utils import simple_decorator from six import string_types as basestring from six.moves import range +import six @simple_decorator def selfcached(func): @@ -78,20 +79,19 @@ def issubdir(parent, child): return parent == child or child.startswith(parent + os.sep) ImplicitType = type(Implicit) +class WorkingCopyMetaClass(ImplicitType): + def __init__(cls, name, bases, d): # pylint: disable=no-self-argument,super-init-not-called + ImplicitType.__init__(cls, name, bases, d) # pylint: disable=non-parent-init-called + if cls.reference: + cls._registry.append((cls.reference, cls)) -class WorkingCopy(Implicit): + +class WorkingCopy(six.with_metaclass(WorkingCopyMetaClass, Implicit)): __allow_access_to_unprotected_subobjects__ = 1 _registry = [] reference = None - class __metaclass__(ImplicitType): - - def __init__(cls, name, bases, d): # pylint: disable=no-self-argument,super-init-not-called - ImplicitType.__init__(cls, name, bases, d) # pylint: disable=non-parent-init-called - if cls.reference: - cls._registry.append((cls.reference, cls)) - def __init__(self, path=None, restricted=False): if path: self.working_copy = self.checkWorkingPath(path, restricted) diff --git a/product/ERP5/bootstrap/erp5_core/ModuleComponentTemplateItem/portal_components/module.erp5.ExpandPolicy.py b/product/ERP5/bootstrap/erp5_core/ModuleComponentTemplateItem/portal_components/module.erp5.ExpandPolicy.py index 6c631ce97c..5536ec34ca 100644 --- a/product/ERP5/bootstrap/erp5_core/ModuleComponentTemplateItem/portal_components/module.erp5.ExpandPolicy.py +++ b/product/ERP5/bootstrap/erp5_core/ModuleComponentTemplateItem/portal_components/module.erp5.ExpandPolicy.py @@ -27,6 +27,7 @@ ############################################################################## +import six from time import time import transaction from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod @@ -54,16 +55,17 @@ policy_dict = {} # {None: preferred, 'foo_bar': FooBar} VERTICAL_EXPAND_TIMEOUT = 5 # XXX: hardcoded for the moment -class _Policy(object): +class _PolicyMetaClass(type): + """Automatically register policies in policy_dict""" + def __init__(cls, name, bases, d): + type.__init__(cls, name, bases, d) + if name[0] != '_': + policy_dict[convertToLowerCase(name)[1:]] = cls + + +class _Policy(six.with_metaclass(_PolicyMetaClass, object)): """Base class of policies for RuleMixin.expand and SimulationMovement.expand """ - class __metaclass__(type): - """Automatically register policies in policy_dict""" - def __init__(cls, name, bases, d): - type.__init__(cls, name, bases, d) - if name[0] != '_': - policy_dict[convertToLowerCase(name)[1:]] = cls - def __init__(self, activate_kw=None): self.activate_kw = activate_kw -- 2.30.9