'Generates an opaque, identifier string that is practically
guaranteed to be unique.  If an object is passed, then its
id() is incorporated into the generation.  Relies on md5 and
returns a 32 character long string.'

def unique_id(self, for_object=None):

    r = [time.time(), random.random()]
    if hasattr(os, 'times'):
        r.append(os.times())
    if (for_object is not None):
        r.append(id(for_object))
    content = str(r)
    if six.PY3:
        content = content.encode('utf8')
    md5_hash = md5(content)
    try:
        return md5_hash.hexdigest()
    except AttributeError:
        hexdigest = []
        for char in md5_hash.digest():
            hexdigest.append(('%02x' % ord(char)))
        return ''.join(hexdigest)
