From 3e666c005f5c717ca34676b16e314c39335612bb Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 13 Jun 2006 15:18:29 -0400 Subject: [PATCH] Forgot to add this --- sugar/util.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 sugar/util.py diff --git a/sugar/util.py b/sugar/util.py new file mode 100644 index 00000000..9c15edbf --- /dev/null +++ b/sugar/util.py @@ -0,0 +1,21 @@ +import time +import sha +import random +import binascii + +def _stringify_sha(sha_hash): + """Convert binary sha1 hash data into printable characters.""" + print_sha = "" + for char in sha_hash: + print_sha = print_sha + binascii.b2a_hex(char) + return print_sha + +def _sha_data(data): + """sha1 hash some bytes.""" + sha_hash = sha.new() + sha_hash.update(data) + return sha_hash.digest() + +def unique_id(data = ''): + data_string = "%s%s%s" % (time.time(), random.randint(10000, 100000), data) + return _stringify_sha(_sha_data(data_string))