The point was to have a 16bytes key for uuid that depends on
uuid.getnode(), time.time(), and a random component. The specific way
the key is built can be changed if there is a good argument for it.

Before we just used uuid.uuid4() an the problem was that when running
on a HA cluster with replicated VM workers uuid.uuid4() was generating
conflicts between session keys and file upload names.

On 14 Lug, 17:24, Craig Younkins <cyounk...@gmail.com> wrote:
> The following is the code in 1.80 for UUID generation from gluon/utils.py.
> Can someone explain to me what is going on here? What's with all the
> bitshifting?
>
> web2py_uuid_locker = thread.allocate_lock()
> node_id = uuid.getnode()
> milliseconds = int(time.time() * 1e3)
>
> def rotate(i):
>     a = random.randrange(256)
>     b = (node_id >> 4*i) % 256
>     c = (milliseconds >> 4*i) % 256
>     return (a + b + c) % 256
>
> def web2py_uuid():
>     web2py_uuid_locker.acquire()
>     try:
>         bytes = [chr(rotate(i)) for i in range(16)]
>         return str(uuid.UUID(bytes=bytes, version=4))
>     finally:
>         web2py_uuid_locker.release()
>
> --
> Craig Younkins

Reply via email to