Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
139
Merge Requests
139
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
d12a23fe
Commit
d12a23fe
authored
Apr 23, 2022
by
Arnaud Fontaine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py3: Make metaclass work on both python2 and python3.
parent
c1dc16aa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
3 deletions
+37
-3
product/ERP5Type/Utils.py
product/ERP5Type/Utils.py
+35
-0
product/ERP5Type/mixin/component.py
product/ERP5Type/mixin/component.py
+2
-3
No files found.
product/ERP5Type/Utils.py
View file @
d12a23fe
...
...
@@ -572,6 +572,41 @@ if six.PY3:
else
:
ensure_list
=
lambda
x
:
x
def
with_metaclass
(
meta
,
*
bases
):
"""
Function from jinja2/_compat.py. License: BSD (copy/paste here for
ExtensionClass)
Use it like this::
class BaseForm(object):
pass
class FormType(type):
pass
class Form(with_metaclass(FormType, BaseForm)):
pass
This requires a bit of explanation: the basic idea is to make a
dummy metaclass for one level of class instantiation that replaces
itself with the actual metaclass. Because of internal type checks
we also need to make sure that we downgrade the custom metaclass
for one level to something closer to type (that's why __call__ and
__init__ comes back from type etc.).
This has the advantage over six.with_metaclass of not introducing
dummy classes into the final MRO.
"""
class
metaclass
(
meta
):
__call__
=
type
.
__call__
__init__
=
type
.
__init__
def
__new__
(
cls
,
name
,
this_bases
,
d
):
if
this_bases
is
None
:
import
ExtensionClass
return
ExtensionClass
.
ExtensionClass
.
__new__
(
cls
,
name
,
(),
d
)
return
meta
(
name
,
bases
,
d
)
return
metaclass
(
'temporary_class'
,
None
,
{})
#####################################################
# Globals initialization
#####################################################
...
...
product/ERP5Type/mixin/component.py
View file @
d12a23fe
...
...
@@ -122,7 +122,8 @@ class RecordablePropertyMetaClass(ExtensionClass):
# ghosting/unghosting Portal Types
return
ExtensionClass
.
__new__
(
ExtensionClass
,
name
,
bases
,
dictionary
)
class
ComponentMixin
(
PropertyRecordableMixin
,
Base
):
from
Products.ERP5Type.Utils
import
with_metaclass
class
ComponentMixin
(
with_metaclass
(
RecordablePropertyMetaClass
,
type
(
'NewBase'
,
(
PropertyRecordableMixin
,
Base
),
{}))):
"""
Mixin used for all ZODB Components. Most of the code is generic, thus actual
ZODB Components should have almost nothing to defined...
...
...
@@ -145,8 +146,6 @@ class ComponentMixin(PropertyRecordableMixin, Base):
state, checkConsistency() is called to check id, reference, version and
errors/warnings messages (set when the Component is modified).
"""
__metaclass__
=
RecordablePropertyMetaClass
isPortalContent
=
1
isRADContent
=
1
isDelivery
=
ConstantGetter
(
'isDelivery'
,
value
=
True
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment