[gedit-latex] __cmp__ 2->3 convert



commit 2265618272ca2977713b7944e16b1103a551a933
Author: Aleksei Lissitsin <aldgracil gmail com>
Date:   Sat Apr 27 20:05:05 2013 +0300

    __cmp__ 2->3 convert

 latex/bibtex/model.py |   18 ++++++++----------
 latex/completion.py   |   16 +++++++++++-----
 latex/file.py         |   15 ++++++++++++---
 latex/outline.py      |   10 ++++++++--
 4 files changed, 39 insertions(+), 20 deletions(-)
---
diff --git a/latex/bibtex/model.py b/latex/bibtex/model.py
index c67227b..36d87ee 100644
--- a/latex/bibtex/model.py
+++ b/latex/bibtex/model.py
@@ -34,16 +34,14 @@ class Type(object):
         self.required_fields = []
         self.optional_fields = []
 
-    def __cmp__(self, other):
-        # FIXME: there must be something simpler...
-        if self.name < other.name:
-            return -1
-        elif self.name > other.name:
-            return 1
-        else:
-            return 0
-
-        #return self.name.__cmp__(other.name)    str has no __cmp__
+    def __lt__(self, other):
+        return self.name < other.name
+
+    def __eq__(self, other):
+        return self.name == other.name
+
+    def __hash__(self):
+        return hash(self.name)
 
 
 class Field(object):
diff --git a/latex/completion.py b/latex/completion.py
index 517cce3..8d25781 100644
--- a/latex/completion.py
+++ b/latex/completion.py
@@ -94,11 +94,17 @@ class Proposal(object):
         """
         raise NotImplementedError
 
-    def __cmp__(self, other):
-        """
-        Compare this proposal to another one
-        """
-        return cmp(self.label.lower(), other.label.lower())
+    def __key__(self):
+        return self.label.lower()
+
+    def __lt__(self, other):
+        return self.__key__() < other.__key__()
+
+    def __eq__(self, other):
+        return self.__key__() == other.__key__()
+
+    def __hash__(self):
+        return hash(self.__key__())
 
 class ProposalPopup(Gtk.Window):
     """
diff --git a/latex/file.py b/latex/file.py
index 6d9d873..d579bd6 100644
--- a/latex/file.py
+++ b/latex/file.py
@@ -249,13 +249,22 @@ class File(object):
     def __str__(self):
         return self.uri
 
-    def __cmp__(self, other):
+    def __key__(self, file):
         try:
-            return self.basename.__cmp__(other.basename)
+            return file.basename
         except AttributeError:        # no File object passed or None
             # returning NotImplemented is bad because we have to
             # compare None with File
-            return False
+            return None
+
+    def __lt__(self, other):
+        return self.__key__(self) < self.__key__(other)
+
+    def __eq__(self, other):
+        return self.__key__(self) == self.__key__(other)
+
+    def __hash__(self):
+        return hash(self.__key__(self))
 
 
 class Folder(File):
diff --git a/latex/outline.py b/latex/outline.py
index 97ec73d..c40ec02 100644
--- a/latex/outline.py
+++ b/latex/outline.py
@@ -193,8 +193,14 @@ class Item(object):
         self.key = key
         self.value = value
 
-    def __cmp__(self, item):
-        return self.key.__cmp__(item.key)
+    def __lt__(self, other):
+        return self.key < other.key
+
+    def __eq__(self, other):
+        return self.key == other.key
+
+    def __hash__(self):
+        return hash(self.key)
 
 
 class OffsetLookupTree(object):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]