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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Titouan Soulard
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:
...
@@ -572,6 +572,41 @@ if six.PY3:
else
:
else
:
ensure_list
=
lambda
x
:
x
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
# Globals initialization
#####################################################
#####################################################
...
...
product/ERP5Type/mixin/component.py
View file @
d12a23fe
...
@@ -122,7 +122,8 @@ class RecordablePropertyMetaClass(ExtensionClass):
...
@@ -122,7 +122,8 @@ class RecordablePropertyMetaClass(ExtensionClass):
# ghosting/unghosting Portal Types
# ghosting/unghosting Portal Types
return
ExtensionClass
.
__new__
(
ExtensionClass
,
name
,
bases
,
dictionary
)
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
Mixin used for all ZODB Components. Most of the code is generic, thus actual
ZODB Components should have almost nothing to defined...
ZODB Components should have almost nothing to defined...
...
@@ -145,8 +146,6 @@ class ComponentMixin(PropertyRecordableMixin, Base):
...
@@ -145,8 +146,6 @@ class ComponentMixin(PropertyRecordableMixin, Base):
state, checkConsistency() is called to check id, reference, version and
state, checkConsistency() is called to check id, reference, version and
errors/warnings messages (set when the Component is modified).
errors/warnings messages (set when the Component is modified).
"""
"""
__metaclass__
=
RecordablePropertyMetaClass
isPortalContent
=
1
isPortalContent
=
1
isRADContent
=
1
isRADContent
=
1
isDelivery
=
ConstantGetter
(
'isDelivery'
,
value
=
True
)
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