MCPcopy Index your code
hub / github.com/python/cpython / uuid8

Function uuid8

Lib/uuid.py:909–932  ·  view source on GitHub ↗

Generate a UUID from three custom blocks. * 'a' is the first 48-bit chunk of the UUID (octets 0-5); * 'b' is the mid 12-bit chunk (octets 6-7); * 'c' is the last 62-bit chunk (octets 8-15). When a value is not specified, a pseudo-random value is generated.

(a=None, b=None, c=None)

Source from the content-addressed store, hash-verified

907
908
909def uuid8(a=None, b=None, c=None):
910 """Generate a UUID from three custom blocks.
911
912 * 'a' is the first 48-bit chunk of the UUID (octets 0-5);
913 * 'b' is the mid 12-bit chunk (octets 6-7);
914 * 'c' is the last 62-bit chunk (octets 8-15).
915
916 When a value is not specified, a pseudo-random value is generated.
917 """
918 if a is None:
919 import random
920 a = random.getrandbits(48)
921 if b is None:
922 import random
923 b = random.getrandbits(12)
924 if c is None:
925 import random
926 c = random.getrandbits(62)
927 int_uuid_8 = (a & 0xffff_ffff_ffff) << 80
928 int_uuid_8 |= (b & 0xfff) << 64
929 int_uuid_8 |= c & 0x3fff_ffff_ffff_ffff
930 # by construction, the variant and version bits are already cleared
931 int_uuid_8 |= _RFC_4122_VERSION_8_FLAGS
932 return UUID._from_int(int_uuid_8)
933
934
935def main():

Callers

nothing calls this directly

Calls 2

_from_intMethod · 0.80
getrandbitsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…