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
Paul Graydon
erp5
Commits
2fe6533d
Commit
2fe6533d
authored
Apr 23, 2022
by
Arnaud Fontaine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py3: Make metaclass with ExtensionClass work on both python2 and python3.
parent
3d968036
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
3 deletions
+41
-3
product/ERP5Type/Utils.py
product/ERP5Type/Utils.py
+39
-0
product/ERP5Type/mixin/component.py
product/ERP5Type/mixin/component.py
+2
-3
No files found.
product/ERP5Type/Utils.py
View file @
2fe6533d
...
...
@@ -550,6 +550,45 @@ def checkPythonSourceCode(source_code_str, portal_type=None):
#LOG('Utils', INFO, 'Checking time (pylint): %.2f' % (time.time() - started))
return
message_list
#####################################################
# Python 2-3 compat
#####################################################
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 @
2fe6533d
...
...
@@ -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