From 1cdaf97f20e84ea9cb80e97708f10627e24b6988 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 14 Jun 2006 18:42:44 +0000 Subject: Switch from Groups to grouping services based on activity UID --- (limited to 'sugar/util.py') diff --git a/sugar/util.py b/sugar/util.py index 9c15edb..6f70495 100644 --- a/sugar/util.py +++ b/sugar/util.py @@ -19,3 +19,20 @@ def _sha_data(data): def unique_id(data = ''): data_string = "%s%s%s" % (time.time(), random.randint(10000, 100000), data) return _stringify_sha(_sha_data(data_string)) + + +ACTIVITY_UID_LEN = 40 + +def is_hex(s): + return s.strip(string.hexdigits) == '' + +def validate_activity_uid(uid): + """Validate an activity UID.""" + if type(uid) != type(""): + return False + if len(uid) != ACTIVITY_UID_LEN: + return False + if not is_hex(uid): + return False + return True + -- cgit v0.9.1