BUG: Fix Python 3 support for Cythonized Security object

Python 3 for some reason doesn't like usage of the cmp() built-in, so
instead of using cmp(), just subtract the two ints being compared.

In addition to making this work with Python 3, it should also be more
performant since it no longer requires calling the cmp() method.
This commit is contained in:
Jonathan Kamens
2015-03-05 14:25:04 -05:00
parent 716bdbb7cd
commit aa585b1cf8
+5 -5
View File
@@ -99,7 +99,7 @@ cdef class Security:
retvals = [True, True, False, True, False, False]
return retvals[op]
compared = cmp(self.sid, other_as_int)
compared = self.sid - other_as_int
# Handle == and != first because they're significantly more common
# operations.
@@ -111,16 +111,16 @@ cdef class Security:
return compared != 0
elif op == 0:
# <
return compared == -1
return compared < 0
elif op == 1:
# <=
return compared == -1 or compared == 0
return compared <= 0
elif op == 4:
# >
return compared == 1
return compared > 0
elif op == 5:
# >=
return compared == 1 or compared == 0
return compared >= 0
def __str__(self):
if self.symbol: