comparison test/test_templating.py @ 5414:3fa026621f69

Python 3 preparation: comparisons. Python 3 no longer has the cmp function, or cmp= arguments to sorting functions / methods (key= must be used instead), and requires rich comparison methods such as __lt__ to be defined instead of using __cmp__. All of the comparison mechanisms supported in Python 3 are also supported in Python 2. This patch makes the corresponding changes in Roundup to use key functions and rich comparison methods. In the case of the JournalPassword and Permission classes, only __eq__ and __ne__ are defined as I don't see ordered comparisons as useful there (and for Permission, the old __cmp__ function didn't try to provide a valid ordering). In the case of the Date class, I kept the __cmp__ method and implemented the others in terms of it, to avoid excess repetitiveness in duplicating implementation code for all six rich comparison methods. In roundup/admin.py, help_commands_html used operator.attrgetter to produce the second argument of sorted() - which would be reasonable for a key function, but the second argument is the cmp function in Python 2, not a key function (and the key function must be a named argument not a positional argument in Python 3). That function appears to be completely unused, so I expect that code never worked. This patch adds the missing key= to that sorted() call, but it would also be reasonable to remove the unused function completely instead.
author Joseph Myers <jsm@polyomino.org.uk>
date Wed, 25 Jul 2018 00:39:37 +0000
parents d26921b851c3
children b0359a7c5b6d
comparison
equal deleted inserted replaced
5413:7a41dd2abbbd 5414:3fa026621f69
352 352
353 class HTMLProperty(HTMLInputMixin, HTMLPermissions): 353 class HTMLProperty(HTMLInputMixin, HTMLPermissions):
354 def __init__(self, client, classname, nodeid, prop, name, value, 354 def __init__(self, client, classname, nodeid, prop, name, value,
355 def __repr__(self): 355 def __repr__(self):
356 def __str__(self): 356 def __str__(self):
357 def __cmp__(self, other): 357 def __lt__(self, other):
358 def __le__(self, other):
359 def __eq__(self, other):
360 def __ne__(self, other):
361 def __gt__(self, other):
362 def __ge__(self, other):
358 def is_edit_ok(self): 363 def is_edit_ok(self):
359 def is_view_ok(self): 364 def is_view_ok(self):
360 365
361 class StringHTMLProperty(HTMLProperty): 366 class StringHTMLProperty(HTMLProperty):
362 def _hyper_repl(self, match): 367 def _hyper_repl(self, match):
416 def reverse(self): 421 def reverse(self):
417 def plain(self, escape=0): 422 def plain(self, escape=0):
418 def field(self, size=30, showid=0): 423 def field(self, size=30, showid=0):
419 def menu(self, size=None, height=None, showid=0, additional=[], 424 def menu(self, size=None, height=None, showid=0, additional=[],
420 425
421 def make_sort_function(db, classname, sort_on=None): 426 def make_key_function(db, classname, sort_on=None):
422 def sortfunc(a, b): 427 def keyfunc(a):
423 428
424 def find_sort_key(linkcl): 429 def find_sort_key(linkcl):
425 430
426 def handleListCGIValue(value): 431 def handleListCGIValue(value):
427 432

Roundup Issue Tracker: http://roundup-tracker.org/