MCPcopy Index your code
hub / github.com/RustPython/RustPython / uuid1

Function uuid1

Lib/uuid.py:726–761  ·  view source on GitHub ↗

Generate a UUID from a host ID, sequence number, and the current time. If 'node' is not given, getnode() is used to obtain the hardware address. If 'clock_seq' is given, it is used as the sequence number; otherwise a random 14-bit sequence number is chosen.

(node=None, clock_seq=None)

Source from the content-addressed store, hash-verified

724_last_timestamp = None
725
726def uuid1(node=None, clock_seq=None):
727 """Generate a UUID from a host ID, sequence number, and the current time.
728 If 'node' is not given, getnode() is used to obtain the hardware
729 address. If 'clock_seq' is given, it is used as the sequence number;
730 otherwise a random 14-bit sequence number is chosen."""
731
732 # When the system provides a version-1 UUID generator, use it (but don't
733 # use UuidCreate here because its UUIDs don't conform to RFC 4122).
734 if _generate_time_safe is not None and node is clock_seq is None:
735 uuid_time, safely_generated = _generate_time_safe()
736 try:
737 is_safe = SafeUUID(safely_generated)
738 except ValueError:
739 is_safe = SafeUUID.unknown
740 return UUID(bytes=uuid_time, is_safe=is_safe)
741
742 global _last_timestamp
743 nanoseconds = time.time_ns()
744 # 0x01b21dd213814000 is the number of 100-ns intervals between the
745 # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
746 timestamp = nanoseconds // 100 + 0x01b21dd213814000
747 if _last_timestamp is not None and timestamp <= _last_timestamp:
748 timestamp = _last_timestamp + 1
749 _last_timestamp = timestamp
750 if clock_seq is None:
751 import random
752 clock_seq = random.getrandbits(14) # instead of stable storage
753 time_low = timestamp & 0xffffffff
754 time_mid = (timestamp >> 32) & 0xffff
755 time_hi_version = (timestamp >> 48) & 0x0fff
756 clock_seq_low = clock_seq & 0xff
757 clock_seq_hi_variant = (clock_seq >> 8) & 0x3f
758 if node is None:
759 node = getnode()
760 return UUID(fields=(time_low, time_mid, time_hi_version,
761 clock_seq_hi_variant, clock_seq_low, node), version=1)
762
763def uuid3(namespace, name):
764 """Generate a UUID from the MD5 hash of a namespace UUID and a name."""

Callers

nothing calls this directly

Calls 4

SafeUUIDClass · 0.85
UUIDClass · 0.85
getnodeFunction · 0.85
getrandbitsMethod · 0.45

Tested by

no test coverage detected