Commit 9dbe48b4 authored by Arnaud Fontaine's avatar Arnaud Fontaine

py3: Products.ERP5Type.dynamic.

parent e9c618bf
...@@ -98,7 +98,7 @@ class AccessorHolderModuleType(ModuleType): ...@@ -98,7 +98,7 @@ class AccessorHolderModuleType(ModuleType):
""" """
Clear the content of the module Clear the content of the module
""" """
for klass in self.__dict__.values(): for klass in ensure_list(self.__dict__.values()):
if isinstance(klass, AccessorHolderType): if isinstance(klass, AccessorHolderType):
# Delete these attributes (computed on the portal type class # Delete these attributes (computed on the portal type class
# from its accessor holder) before deleting the class itself # from its accessor holder) before deleting the class itself
...@@ -336,7 +336,7 @@ def applyCategoryAsRelatedValueAccessor(accessor_holder, ...@@ -336,7 +336,7 @@ def applyCategoryAsRelatedValueAccessor(accessor_holder,
accessor = RelatedValue.IdListGetter(accessor_name + 'RelatedIds', category_id) accessor = RelatedValue.IdListGetter(accessor_name + 'RelatedIds', category_id)
accessor_holder.registerAccessor(accessor, read_permission) accessor_holder.registerAccessor(accessor, read_permission)
for accessor_class, accessor_name_list in related_accessor_definition_dict.items(): for accessor_class, accessor_name_list in related_accessor_definition_dict.iteritems():
for accessor_name in accessor_name_list: for accessor_name in accessor_name_list:
accessor = accessor_class(accessor_name % uppercase_category_id, category_id) accessor = accessor_class(accessor_name % uppercase_category_id, category_id)
accessor_holder.registerAccessor(accessor, read_permission) accessor_holder.registerAccessor(accessor, read_permission)
......
...@@ -30,11 +30,13 @@ ...@@ -30,11 +30,13 @@
# There is absolutely no reason to use relative imports when loading a Component # There is absolutely no reason to use relative imports when loading a Component
from __future__ import absolute_import from __future__ import absolute_import
import six
import sys import sys
import imp import imp
import collections import collections
from six import reraise from six import reraise
from Products.ERP5Type.Utils import ensure_list
from Products.ERP5.ERP5Site import getSite from Products.ERP5.ERP5Site import getSite
from Products.ERP5Type import product_path as ERP5Type_product_path from Products.ERP5Type import product_path as ERP5Type_product_path
from . import aq_method_lock from . import aq_method_lock
...@@ -51,6 +53,12 @@ class ComponentVersionPackage(ModuleType): ...@@ -51,6 +53,12 @@ class ComponentVersionPackage(ModuleType):
""" """
__path__ = [] __path__ = []
try:
ModuleNotFoundError
except NameError: # < 3.6
class ModuleNotFoundError(ImportError):
pass
class ComponentDynamicPackage(ModuleType): class ComponentDynamicPackage(ModuleType):
""" """
A top-level component is a package as it contains modules, this is required A top-level component is a package as it contains modules, this is required
...@@ -420,8 +428,10 @@ class ComponentDynamicPackage(ModuleType): ...@@ -420,8 +428,10 @@ class ComponentDynamicPackage(ModuleType):
# load_module(), and returning module 'name' in contrary to __import__ # load_module(), and returning module 'name' in contrary to __import__
# returning 'erp5' (requiring fromlist parameter which is slower) # returning 'erp5' (requiring fromlist parameter which is slower)
return import_module(fullname) return import_module(fullname)
except ModuleNotFoundError:
pass
except ImportError as e: except ImportError as e:
if str(e) != "No module named " + name: if six.PY3 or str(e) != "No module named " + name:
LOG("ERP5Type.dynamic", WARNING, LOG("ERP5Type.dynamic", WARNING,
"Could not load Component module %r" % fullname, error=True) "Could not load Component module %r" % fullname, error=True)
...@@ -443,10 +453,10 @@ class ComponentDynamicPackage(ModuleType): ...@@ -443,10 +453,10 @@ class ComponentDynamicPackage(ModuleType):
# Force reload of ModuleSecurityInfo() as it may have been changed in # Force reload of ModuleSecurityInfo() as it may have been changed in
# the source code # the source code
for modsec_dict in _moduleSecurity, _appliedModuleSecurity: for modsec_dict in _moduleSecurity, _appliedModuleSecurity:
for k in modsec_dict.keys(): for k in ensure_list(modsec_dict.keys()):
if k.startswith(self._namespace): if k.startswith(self._namespace):
del modsec_dict[k] del modsec_dict[k]
for k, v in MNAME_MAP.items(): for k, v in ensure_list(MNAME_MAP.items()):
if v.startswith(self._namespace): if v.startswith(self._namespace):
del MNAME_MAP[k] del MNAME_MAP[k]
...@@ -454,7 +464,7 @@ class ComponentDynamicPackage(ModuleType): ...@@ -454,7 +464,7 @@ class ComponentDynamicPackage(ModuleType):
if k.startswith('Products.'): if k.startswith('Products.'):
del sys.modules[k] del sys.modules[k]
for name, module in package.__dict__.items(): for name, module in ensure_list(package.__dict__.items()):
if name[0] == '_' or not isinstance(module, ModuleType): if name[0] == '_' or not isinstance(module, ModuleType):
continue continue
......
...@@ -28,6 +28,7 @@ from __future__ import absolute_import ...@@ -28,6 +28,7 @@ from __future__ import absolute_import
# #
############################################################################## ##############################################################################
from Products.ERP5Type.Utils import ensure_list
from types import ModuleType from types import ModuleType
from . import aq_method_lock from . import aq_method_lock
import sys import sys
...@@ -82,7 +83,7 @@ class RefManager(dict): ...@@ -82,7 +83,7 @@ class RefManager(dict):
Remove cache items with no Request Left. Remove cache items with no Request Left.
""" """
for (current_last_sync, for (current_last_sync,
(request_obj_weakset, _)) in self.items(): (request_obj_weakset, _)) in ensure_list(self.items()):
if not request_obj_weakset: if not request_obj_weakset:
del self[current_last_sync] del self[current_last_sync]
......
...@@ -244,7 +244,7 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder): ...@@ -244,7 +244,7 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder):
erp5.portal_type.XXX, GhostBaseMetaClass instance, *TAIL erp5.portal_type.XXX, GhostBaseMetaClass instance, *TAIL
""" """
if not cls.__isghost__: if not cls.__isghost__:
for attr in cls.__dict__.keys(): for attr in ensure_list(cls.__dict__.keys()):
if attr not in ('__module__', if attr not in ('__module__',
'__doc__', '__doc__',
'__setstate__', '__setstate__',
...@@ -317,7 +317,7 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder): ...@@ -317,7 +317,7 @@ class PortalTypeMetaClass(GhostBaseMetaClass, PropertyHolder):
result = PropertyHolder._getPropertyHolderItemList(cls) result = PropertyHolder._getPropertyHolderItemList(cls)
for parent in cls.mro(): for parent in cls.mro():
if parent.__module__.startswith('erp5.accessor_holder'): if parent.__module__.startswith('erp5.accessor_holder'):
for x in parent.__dict__.items(): for x in parent.__dict__.iteritems():
if x[0] not in PropertyHolder.RESERVED_PROPERTY_SET: if x[0] not in PropertyHolder.RESERVED_PROPERTY_SET:
result.append(x) result.append(x)
return result return result
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
# #
############################################################################## ##############################################################################
import six
import os import os
import inspect import inspect
import transaction import transaction
...@@ -36,7 +37,7 @@ from Products.ERP5Type.mixin.temporary import TemporaryDocumentMixin ...@@ -36,7 +37,7 @@ from Products.ERP5Type.mixin.temporary import TemporaryDocumentMixin
from Products.ERP5Type.Base import resetRegisteredWorkflowMethod from Products.ERP5Type.Base import resetRegisteredWorkflowMethod
from . import aq_method_lock from . import aq_method_lock
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type.Utils import setDefaultClassProperties from Products.ERP5Type.Utils import setDefaultClassProperties, ensure_list
from Products.ERP5Type import document_class_registry, mixin_class_registry from Products.ERP5Type import document_class_registry, mixin_class_registry
from Products.ERP5Type.dynamic.accessor_holder import createAllAccessorHolderList from Products.ERP5Type.dynamic.accessor_holder import createAllAccessorHolderList
from Products.ERP5Type.Accessor.Constant import Getter as ConstantGetter from Products.ERP5Type.Accessor.Constant import Getter as ConstantGetter
...@@ -60,6 +61,8 @@ ACQUIRE_LOCAL_ROLE_GETTER_DICT = { ...@@ -60,6 +61,8 @@ ACQUIRE_LOCAL_ROLE_GETTER_DICT = {
for acquire_local_role in (False, True) for acquire_local_role in (False, True)
} }
if six.PY3:
StandardError = Exception
def _importFilesystemClass(classpath): def _importFilesystemClass(classpath):
try: try:
module_path, class_name = classpath.rsplit('.', 1) module_path, class_name = classpath.rsplit('.', 1)
...@@ -540,7 +543,7 @@ def synchronizeDynamicModules(context, force=False): ...@@ -540,7 +543,7 @@ def synchronizeDynamicModules(context, force=False):
erp5.accessor_holder.clear() erp5.accessor_holder.clear()
erp5.accessor_holder.property_sheet.clear() erp5.accessor_holder.property_sheet.clear()
for name in erp5.accessor_holder.portal_type.__dict__.keys(): for name in ensure_list(erp5.accessor_holder.portal_type.__dict__.keys()):
if name[0] != '_': if name[0] != '_':
delattr(erp5.accessor_holder.portal_type, name) delattr(erp5.accessor_holder.portal_type, name)
......
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