Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export UUID in the compat module #43

Merged
merged 1 commit into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions python/uuid_utils/compat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import uuid
from uuid import UUID

import uuid_utils

Expand All @@ -8,39 +8,39 @@ def uuid1(node=None, clock_seq=None):
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."""
return uuid.UUID(int=uuid_utils.uuid1(node, clock_seq).int)
return UUID(int=uuid_utils.uuid1(node, clock_seq).int)


def uuid3(namespace, name):
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
namespace = uuid_utils.UUID(namespace.hex) if namespace else namespace
return uuid.UUID(int=uuid_utils.uuid3(namespace, name).int)
return UUID(int=uuid_utils.uuid3(namespace, name).int)


def uuid4():
"""Generate a random UUID."""
return uuid.UUID(int=uuid_utils.uuid4().int)
return UUID(int=uuid_utils.uuid4().int)


def uuid5(namespace, name):
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
namespace = uuid_utils.UUID(namespace.hex) if namespace else namespace
return uuid.UUID(int=uuid_utils.uuid5(namespace, name).int)
return UUID(int=uuid_utils.uuid5(namespace, name).int)


def uuid6(node=None, timestamp=None):
"""Generate a version 6 UUID using the given timestamp and a host ID.
This is similar to version 1 UUIDs,
except that it is lexicographically sortable by timestamp.
"""
return uuid.UUID(int=uuid_utils.uuid6(node, timestamp).int)
return UUID(int=uuid_utils.uuid6(node, timestamp).int)


def uuid7(timestamp=None):
"""Generate a version 7 UUID using a time value and random bytes."""
return uuid.UUID(int=uuid_utils.uuid7(timestamp).int)
return UUID(int=uuid_utils.uuid7(timestamp).int)


def uuid8(bytes):
"""Generate a custom UUID comprised almost entirely of user-supplied bytes.."""
return uuid.UUID(bytes=uuid_utils.uuid8(bytes).bytes)
return UUID(bytes=uuid_utils.uuid8(bytes).bytes)
Loading