From 6bc745fe45bf4077fddcf5aa5aec4fa5fc41bcf9 Mon Sep 17 00:00:00 2001 From: 9m66p93w <9m66p93w@users.noreply.github.com> Date: Sun, 27 Oct 2013 22:55:01 -0400 Subject: [PATCH] Replace built-in hash function with hashlib. The built-in hash function returns inconsistent values in Python 3. --- radicale/ical.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/radicale/ical.py b/radicale/ical.py index 3b6bd68..162e3d1 100644 --- a/radicale/ical.py +++ b/radicale/ical.py @@ -27,6 +27,7 @@ Define the main classes of a collection as seen from the server. import os import posixpath +import hashlib from uuid import uuid4 from random import randint from contextlib import contextmanager @@ -109,7 +110,9 @@ class Item(object): "\nEND:", "\nX-RADICALE-NAME:%s\nEND:" % self._name) def __hash__(self): - return hash(self.text) + m = hashlib.md5() + m.update(self.text.encode('utf-8')) + return m.hexdigest() def __eq__(self, item): return isinstance(item, Item) and self.text == item.text @@ -437,7 +440,9 @@ class Collection(object): @property def etag(self): """Etag from collection.""" - return '"%s"' % hash(self.text) + m = hashlib.md5() + m.update(self.text.encode('utf-8')) + return '"%s"' % m.hexdigest() @property def name(self):