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

py2/py3: update classes using __metaclass__

parent a9c92b8a
......@@ -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)
......
......@@ -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
......
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