Package ldaptor :: Module insensitive
[hide private]
[frames] | no frames]

Source Code for Module ldaptor.insensitive

1 -class InsensitiveString(str):
2 """A str subclass that performs all matching without regard to case.""" 3
4 - def __eq__(self, other):
5 if isinstance(other, basestring): 6 return self.lower() == other.lower() 7 else: 8 return super(InsensitiveString, self).__eq__(other)
9
10 - def __ne__(self, other):
11 if isinstance(other, basestring): 12 return self.lower() != other.lower() 13 else: 14 return super(InsensitiveString, self).__ne__(self, other)
15
16 - def __ge__(self, other):
17 if isinstance(other, basestring): 18 return self.lower() >= other.lower() 19 else: 20 return super(InsensitiveString, self).__ge__(self, other)
21
22 - def __gt__(self, other):
23 if isinstance(other, basestring): 24 return self.lower() > other.lower() 25 else: 26 return super(InsensitiveString, self).__gt__(self, other)
27
28 - def __le__(self, other):
29 if isinstance(other, basestring): 30 return self.lower() <= other.lower() 31 else: 32 return super(InsensitiveString, self).__le__(self, other)
33
34 - def __lt__(self, other):
35 if isinstance(other, basestring): 36 return self.lower() < other.lower() 37 else: 38 return super(InsensitiveString, self).__lt__(self, other)
39
40 - def __hash__(self):
41 return hash(self.lower())
42
43 - def __contains__(self, other):
44 if isinstance(other, basestring): 45 return other.lower() in self.lower() 46 else: 47 return super(InsensitiveString, self).__contains__(self, other)
48
49 - def __getslice__(self, *a, **kw):
50 r = super(InsensitiveString, self).__getslice__(*a, **kw) 51 return self.__class__(r)
52