entry: Hash entries by their UID (when possible)
authorW. Trevor King <wking@tremily.us>
Sun, 30 Jun 2013 18:14:08 +0000 (14:14 -0400)
committerW. Trevor King <wking@tremily.us>
Sun, 30 Jun 2013 20:24:29 +0000 (16:24 -0400)
From RFC 5545, section 3.8.4.7 (Unique Identifier):

  Conformance:  The property MUST be specified in the "VEVENT",
      "VTODO", "VJOURNAL", or "VFREEBUSY" calendar components.

pycalendar/entry.py

index 90e0bac0b060cf64c301abf86b9346fa60bc9a74..315a2284080607f36ca061d45619dc3c966d4a63 100644 (file)
@@ -69,6 +69,13 @@ class Entry (dict):
             self.process()
 
     def __hash__(self):
+        if self.type in [
+                'VEVENT',
+                'VFREEBUSY',
+                'VJOURNAL',
+                'VTODO',
+                ] or 'UID' in self:
+            return hash(_text.unescape(self['UID']))
         return id(self)
 
     def __str__(self):