Skip to content

Commit 1227759

Browse files
committed
chore: Always specify byteorder for Python 3.9
1 parent 14683ee commit 1227759

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ulid/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,18 @@ def randomness(self) -> bytes:
7575
if current_timestamp == self.prev_timestamp:
7676
if self.prev_randomness == constants.MAX_RANDOMNESS:
7777
raise ValueError("Randomness within same millisecond exhausted")
78-
randomness = (int.from_bytes(self.prev_randomness) + 1).to_bytes(
79-
constants.RANDOMNESS_LEN, byteorder="big"
80-
)
78+
randomness = self.increment_bytes(self.prev_randomness)
8179
else:
8280
randomness = os.urandom(constants.RANDOMNESS_LEN)
8381

8482
self.prev_randomness = randomness
8583
self.prev_timestamp = current_timestamp
8684
return randomness
8785

86+
def increment_bytes(self, value: bytes) -> bytes:
87+
length = len(value)
88+
return (int.from_bytes(value, byteorder="big") + 1).to_bytes(length, byteorder="big")
89+
8890

8991
@functools.total_ordering
9092
class ULID:

0 commit comments

Comments
 (0)