Changeset 921:11f9fb4fb178


Ignore:
Timestamp:
04/27/19 12:06:32 (6 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
Phase:
public
Message:

Fixed ordering for classes that used cmp (re #347).

Location:
src/mlx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/fsuipc.py

    r919 r921  
    1313import codecs
    1414import math
     15from functools import total_ordering
    1516
    1617if os.name == "nt" and "FORCE_PYUIPC_SIM" not in os.environ:
     
    197198                Handler._callSafe(lambda: self._callback(None, self._extra))
    198199
     200    @total_ordering
    199201    class PeriodicRequest(object):
    200202        """A periodic request."""
     
    250252            pass
    251253
    252         def __cmp__(self, other):
    253             """Compare two periodic requests. They are ordered by their next
    254             firing times."""
    255             return cmp(self._nextFire, other._nextFire)
     254        def __eq__(self, other):
     255            """Equality comparison by the firing times"""
     256            return self._nextFire == other._nextFire
     257
     258        def __ne__(self, other):
     259            """Non-equality comparison by the firing times"""
     260            return self._nextFire != other._nextFire
     261
     262        def __lt__(self, other):
     263            """Less-than comparison by the firing times"""
     264            return self._nextFire < other._nextFire
    256265
    257266    def __init__(self, connectionListener,
  • src/mlx/logger.py

    r919 r921  
    77import time
    88import bisect
     9from functools import total_ordering
    910
    1011#--------------------------------------------------------------------------------------
     
    3435    increasing IDs."""
    3536
     37    @total_ordering
    3638    class Entry(object):
    3739        """An entry in the log."""
     
    119121                                id = self._id)
    120122
    121         def __cmp__(self, other):
    122             """Compare two entries
    123 
    124             First their timestamps are compared, and if those are equal, then
    125             their IDs."""
    126             result = cmp(self._timestamp, other.timestamp)
    127             if result==0:
    128                 result = cmp(self._id, other._id)
    129             return result
     123        def __eq__(self, other):
     124            """Equality comparison"""
     125            return self._timestamp == other.timestamp and \
     126                self._id == other._id
     127
     128        def __ne__(self, other):
     129            """Non-equality comparison"""
     130            return self._timestamp != other.timestamp or \
     131                self._id != other._id
     132
     133        def __lt__(self, other):
     134            """Less-than comparison"""
     135            return self._timestamp < other.timestamp or \
     136                (self._timestamp == other.timestamp and
     137                 self._id < other._id)
    130138
    131139    class Fault(object):
  • src/mlx/xplane.py

    r919 r921  
    1212import codecs
    1313import math
     14from functools import total_ordering
    1415
    1516from xplra import XPlane, MultiGetter, MultiSetter, ProtocolException
     
    148149        return True
    149150
     151@total_ordering
    150152class PeriodicRequest(object):
    151153    """A periodic request."""
     
    198200        pass
    199201
    200     def __cmp__(self, other):
    201         """Compare two periodic requests. They are ordered by their next
    202         firing times."""
    203         return cmp(self._nextFire, other._nextFire)
     202    def __eq__(self, other):
     203        """Equality comparison by the firing times"""
     204        return self._nextFire == other._nextFire
     205
     206    def __ne__(self, other):
     207        """Non-equality comparison by the firing times"""
     208        return self._nextFire != other._nextFire
     209
     210    def __lt__(self, other):
     211        """Less-than comparison by the firing times"""
     212        return self._nextFire < other._nextFire
    204213
    205214class PeriodicDataRequest(PeriodicRequest):
Note: See TracChangeset for help on using the changeset viewer.