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
75ca95de
Commit
75ca95de
authored
Mar 16, 2023
by
Kazuhiko Shiozaki
Committed by
Jérome Perrin
Apr 01, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py2/py3: define OrderableKey that uses legacy cmp for ordering.
parent
37c808d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
product/ERP5Type/Utils.py
product/ERP5Type/Utils.py
+17
-1
product/ERP5Type/tests/testERP5Type.py
product/ERP5Type/tests/testERP5Type.py
+11
-1
No files found.
product/ERP5Type/Utils.py
View file @
75ca95de
...
...
@@ -144,6 +144,19 @@ else:
# Generic sort method
#####################################################
if
six
.
PY2
:
OrderableKey
=
lambda
x
:
x
else
:
class
OrderableKey
(
object
):
def
__init__
(
self
,
value
):
self
.
value
=
value
def
__lt__
(
self
,
other
):
return
cmp
(
self
.
value
,
other
.
value
)
!=
1
def
__repr__
(
self
):
return
'OrderableKey(%r)'
%
self
.
value
sort_kw_cache
=
{}
def
sortValueList
(
value_list
,
sort_on
=
None
,
sort_order
=
None
,
**
kw
):
...
...
@@ -201,7 +214,10 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw):
except
TypeError
:
pass
value_list
.
append
(
x
)
return
value_list
if
six
.
PY2
:
return
value_list
else
:
return
[
OrderableKey
(
e
)
for
e
in
value_list
]
sort_kw
=
{
'key'
:
sortValue
,
'reverse'
:
reverse
}
sort_kw_cache
[(
sort_on
,
sort_order
)]
=
sort_kw
else
:
...
...
product/ERP5Type/tests/testERP5Type.py
View file @
75ca95de
...
...
@@ -38,7 +38,7 @@ from Acquisition import aq_base
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
AccessControl.ZopeGuards
import
guarded_import
from
Products.ERP5Type.tests.utils
import
LogInterceptor
,
createZODBPythonScript
from
Products.ERP5Type.Utils
import
cmp
from
Products.ERP5Type.Utils
import
OrderableKey
,
cmp
class
TestERP5Type
(
ERP5TypeTestCase
,
LogInterceptor
):
"""
...
...
@@ -286,6 +286,16 @@ class TestERP5Type(ERP5TypeTestCase, LogInterceptor):
self
.
assertEqual
(
cmp
(
None
,
''
),
-
1
)
self
.
assertEqual
(
cmp
(
0
,
''
),
-
1
)
def
test_OrderableKey
(
self
):
self
.
assertEqual
(
sorted
([
1
,
''
,
None
],
key
=
lambda
x
:
OrderableKey
(
x
)),
[
None
,
1
,
''
]
)
o1
=
[
OrderableKey
(
e
)
for
e
in
(
None
,
1
)]
o2
=
[
OrderableKey
(
e
)
for
e
in
(
0
,
0
)]
self
.
assertEqual
(
sorted
([
o1
,
o2
]),
[
o1
,
o2
])
self
.
assertEqual
(
sorted
([
o2
,
o1
]),
[
o1
,
o2
])
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestERP5Type
))
...
...
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