Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
3c669886
Commit
3c669886
authored
Sep 12, 2016
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace `__cmp__` with Python 3 compatible ordering methods.
parent
ecc18276
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
38 deletions
+49
-38
src/App/Extensions.py
src/App/Extensions.py
+14
-9
src/Products/Five/browser/tests/test_menu.py
src/Products/Five/browser/tests/test_menu.py
+3
-2
src/Products/Five/viewlet/README.txt
src/Products/Five/viewlet/README.txt
+6
-5
src/Products/PageTemplates/tests/rr.pt
src/Products/PageTemplates/tests/rr.pt
+1
-1
src/Shared/DC/Scripts/Signature.py
src/Shared/DC/Scripts/Signature.py
+15
-10
src/ZPublisher/HTTPRequest.py
src/ZPublisher/HTTPRequest.py
+9
-11
src/ZTUtils/Tree.py
src/ZTUtils/Tree.py
+1
-0
No files found.
src/App/Extensions.py
View file @
3c669886
...
...
@@ -14,6 +14,7 @@
Extensions currently include external methods.
"""
from
functools
import
total_ordering
import
imp
import
os
...
...
@@ -23,20 +24,24 @@ import Products
from
zExceptions
import
NotFound
class
FuncCode
:
@
total_ordering
class
FuncCode
(
object
):
def
__init__
(
self
,
f
,
im
=
0
):
self
.
co_varnames
=
f
.
func_code
.
co_varnames
[
im
:]
self
.
co_argcount
=
f
.
func_code
.
co_argcount
-
im
def
__cmp__
(
self
,
other
):
if
other
is
None
:
return
1
try
:
return
cmp
((
self
.
co_argcount
,
self
.
co_varnames
),
(
other
.
co_argcount
,
other
.
co_varnames
))
except
Exception
:
return
1
def
__eq__
(
self
,
other
):
if
not
isinstance
(
other
,
FuncCode
):
return
False
return
((
self
.
co_argcount
,
self
.
co_varnames
)
==
(
other
.
co_argcount
,
other
.
co_varnames
))
def
__lt__
(
self
,
other
):
if
not
isinstance
(
other
,
FuncCode
):
return
False
return
((
self
.
co_argcount
,
self
.
co_varnames
)
<
(
other
.
co_argcount
,
other
.
co_varnames
))
def
_getPath
(
home
,
prefix
,
name
,
suffixes
):
...
...
src/Products/Five/browser/tests/test_menu.py
View file @
3c669886
...
...
@@ -47,7 +47,8 @@ def test_menu():
Sort menu items by title so we get a stable testable result:
>>> menu.sort(lambda x, y: cmp(x['title'], y['title']))
>>> from operator import itemgetter
>>> menu.sort(key=itemgetter('title'))
>>> from pprint import pprint
>>> pprint(menu[0])
{'action': '@@cockatiel_menu_public.html',
...
...
@@ -99,7 +100,7 @@ def test_menu():
>>> len(menu)
7
>>> menu.sort(
lambda x, y: cmp(x['title'], y['title']
))
>>> menu.sort(
key=itemgetter('title'
))
>>> pprint(menu[0])
{'action': '@@cockatiel_menu_protected.html',
'description': u'',
...
...
src/Products/Five/viewlet/README.txt
View file @
3c669886
...
...
@@ -754,6 +754,8 @@ two features are not part of the view logic, they should be treated with
independent components. In this example, we are going to only implement
sorting using a simple utility:
>>> from operator import attrgetter
>>> class ISorter(zope.interface.Interface):
...
... def sort(values):
...
...
@@ -763,7 +765,7 @@ sorting using a simple utility:
... zope.interface.implements(ISorter)
...
... def sort(self, values):
... return sorted(values,
lambda x, y: cmp(x.__name__, y.__name__
))
... return sorted(values,
key=attrgetter('__name__'
))
>>> zope.component.provideUtility(SortByName(), name='name')
...
...
@@ -771,10 +773,9 @@ sorting using a simple utility:
... zope.interface.implements(ISorter)
...
... def sort(self, values):
... return sorted(
... values,
... lambda x, y: cmp(size.interfaces.ISized(x).sizeForSorting(),
... size.interfaces.ISized(y).sizeForSorting()))
... def _key(value):
... return size.interfaces.ISized(value).sizeForSorting()
... return sorted(values, key=_key)
>>> zope.component.provideUtility(SortBySize(), name='size')
...
...
src/Products/PageTemplates/tests/rr.pt
View file @
3c669886
<html>
<body>
<ul
tal:define=
"refs options/refs;
refs python:sorted(refs,
lambda x,y: cmp(x.order, y.order)
)"
>
refs python:sorted(refs,
key=lambda x: x.order
)"
>
<li
tal:repeat=
"ref refs"
tal:content=
"ref"
/>
</ul>
</body>
...
...
src/Shared/DC/Scripts/Signature.py
View file @
3c669886
...
...
@@ -15,26 +15,31 @@
This provides support for simulating function signatures
"""
from
functools
import
total_ordering
class
FuncCode
:
@
total_ordering
class
FuncCode
(
object
):
def
__init__
(
self
,
varnames
,
argcount
):
self
.
co_varnames
=
varnames
self
.
co_argcount
=
argcount
def
__cmp__
(
self
,
other
):
if
other
is
None
:
return
1
try
:
return
cmp
((
self
.
co_argcount
,
self
.
co_varnames
),
(
other
.
co_argcount
,
other
.
co_varnames
))
except
Exception
:
return
1
def
__eq__
(
self
,
other
):
if
not
isinstance
(
other
,
FuncCode
):
return
False
return
((
self
.
co_argcount
,
self
.
co_varnames
)
==
(
other
.
co_argcount
,
other
.
co_varnames
))
# This is meant to be imported directly into a class.
def
__lt__
(
self
,
other
):
if
not
isinstance
(
other
,
FuncCode
):
return
False
return
((
self
.
co_argcount
,
self
.
co_varnames
)
<
(
other
.
co_argcount
,
other
.
co_varnames
))
def
_setFuncSignature
(
self
,
defaults
=
None
,
varnames
=
(),
argcount
=-
1
):
# This is meant to be imported directly into a class.
# Simplify calls.
if
argcount
<
0
and
varnames
:
argcount
=
len
(
varnames
)
...
...
src/ZPublisher/HTTPRequest.py
View file @
3c669886
...
...
@@ -1743,7 +1743,7 @@ def parse_cookie(text,
return
parse_cookie
(
text
[
l
:],
result
)
class
record
:
class
record
(
object
)
:
# Allow access to record methods and values from DTML
__allow_access_to_unprotected_subobjects__
=
1
...
...
@@ -1766,21 +1766,19 @@ class record:
return
self
.
__dict__
[
key
]
def
__str__
(
self
):
L1
=
self
.
__dict__
.
items
()
L1
.
sort
()
return
", "
.
join
(
"%s: %s"
%
item
for
item
in
L1
)
return
", "
.
join
(
"%s: %s"
%
item
for
item
in
sorted
(
self
.
__dict__
.
items
()))
def
__repr__
(
self
):
# return repr( self.__dict__ )
L1
=
self
.
__dict__
.
items
()
L1
.
sort
()
return
'{%s}'
%
', '
.
join
(
"'%s': %s"
%
(
item
[
0
],
repr
(
item
[
1
]))
for
item
in
L1
)
"'%s': %s"
%
(
item
[
0
],
repr
(
item
[
1
]))
for
item
in
sorted
(
self
.
__dict__
.
items
()))
def
__
cmp
__
(
self
,
other
):
return
(
cmp
(
type
(
self
),
type
(
other
))
or
cmp
(
self
.
__class__
,
other
.
__class__
)
or
cmp
(
self
.
__dict__
.
items
(),
other
.
__dict__
.
items
())
)
def
__
eq
__
(
self
,
other
):
if
not
isinstance
(
other
,
record
):
return
False
return
self
.
__dict__
.
items
()
==
other
.
__dict__
.
items
(
)
def
_filterPasswordFields
(
items
):
...
...
src/ZTUtils/Tree.py
View file @
3c669886
...
...
@@ -300,6 +300,7 @@ def decodeExpansion(s, nth=None, maxsize=8192):
nth_pair
=
None
if
nth
is
not
None
:
nth_pair
=
(
None
,
None
)
obid
=
None
for
step
in
s
.
split
(
':'
):
if
step
.
startswith
(
'_'
):
pop
=
len
(
step
)
-
1
...
...
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