Back to index

plone3  3.1.7
Key.py
Go to the documentation of this file.
00001 import OFS
00002 
00003 class Key(OFS.SimpleItem.SimpleItem):
00004     key = None
00005 
00006     def __init__(self, key):
00007         self.key = key
00008 
00009     def __cmp__(self, k):
00010         keylen = len(self.key)
00011         for i in range(0, keylen-1):
00012             if self.key[i] != k.key[i]:
00013                 return self._compare(self.key[i], k.key[i])
00014         return self._compare(self.key[keylen-1], k.key[keylen-1])
00015 
00016     def _compare(self, k1, k2):
00017         # make None end up last
00018         if k1 == None:
00019             if k2 == None:
00020                 return 0
00021             return 1
00022         if k2 == None:
00023             return -1
00024         return cmp(k1, k2)
00025 
00026     def getKey(self):
00027         return self.key
00028 
00029     def __hash__(self):
00030         return hash(self.key)
00031 
00032     def __eq__(self, k):
00033         return self.key == k.key