Commits

Jason R. Coombs committed 81593d7

Updated strings.FoldedCase to support comparison against
objects of other types.

Comments (0)

Files changed (2)

 
 * Issue #3541414 - The ServerConnection and DCCConnection now encode any
   strings as UTF-8 before transmitting.
+* Issue #3527371 - Updated strings.FoldedCase to support comparison against
+  objects of other types.
 
 2.0
 ===
 import string
 
 # from jaraco.util.string
-class FoldedCase(str):
+class FoldedCase(unicode):
     """
     A case insensitive string class; behaves just like str
     except compares equal when the only variation is case.
     4
 
     >>> s.split('O')
-    ['hell', ' w', 'rld']
+    [u'hell', u' w', u'rld']
 
-    >>> names = map(FoldedCase, ['GAMMA', 'alpha', 'Beta'])
-    >>> names.sort()
-    >>> names
-    ['alpha', 'Beta', 'GAMMA']
+    >>> sorted(map(FoldedCase, ['GAMMA', 'alpha', 'Beta']))
+    [u'alpha', u'Beta', u'GAMMA']
+
+    It's still possible to compare against non-FoldedCase dicts
+    >>> s == None
+    False
+    >>> s == 1
+    False
     """
     def __lt__(self, other):
-        return self.lower() < other.lower()
+        if hasattr(other, 'lower'):
+            other = other.lower()
+        return self.lower() < other
 
     def __gt__(self, other):
-        return self.lower() > other.lower()
+        if hasattr(other, 'lower'):
+            other = other.lower()
+        return self.lower() > other
 
     def __eq__(self, other):
-        return self.lower() == other.lower()
+        if hasattr(other, 'lower'):
+            other = other.lower()
+        return self.lower() == other
 
     def __hash__(self):
         return hash(self.lower())