Skip to content

Commit 4d9862e

Browse files
committed
revert modifications on properties for now
1 parent 6847b77 commit 4d9862e

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

Lib/test/test_uuid.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -699,18 +699,18 @@ def test_uuid6(self):
699699
mock.patch('random.getrandbits', return_value=fake_clock_seq):
700700
u = self.uuid.uuid6()
701701
equal(u.variant, self.uuid.RFC_4122)
702-
equal(u.version, 6)
702+
equal(u.version, 0b0110) # 6
703703

704-
# time_hi time_mid time_lo
705-
# 00011110100100000001111111001010 0111101001010101 101110010010
706704
timestamp = 137643448267529106
707-
equal(u.time_hi, 0b00011110100100000001111111001010)
708-
equal(u.time_mid, 0b0111101001010101)
709-
equal(u.time_low, 0b101110010010)
705+
# 32 (hi) | 16 (mid) | 12 (lo) == 60 bits of timestamp
706+
equal(timestamp, 0b_00011110100100000001111111001010_0111101001010101_101110010010)
710707
equal(u.time, timestamp)
711-
equal(u.fields[0], u.time_hi)
712-
equal(u.fields[1], u.time_mid)
713-
equal(u.fields[2], u.time_hi_version)
708+
equal(u.fields[0], 0b00011110100100000001111111001010) # 32 high bits of time
709+
equal(u.fields[1], 0b0111101001010101) # 16 bits of time (mid)
710+
equal(u.fields[2], 0b0110_101110010010) # 4 bits of version + 12 low bits of time
711+
equal(u.fields[3], 0b10_010100) # 2 bits of variant + 6 high bits of clock_seq
712+
equal(u.fields[4], 0b11000101) # 8 low bits of clock_seq
713+
equal(u.fields[5], fake_node_value)
714714

715715
def test_uuid7(self):
716716
equal = self.assertEqual

Lib/uuid.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -298,29 +298,17 @@ def bytes_le(self):
298298

299299
@property
300300
def fields(self):
301-
if self.version == 6:
302-
# the first field should be a 32-bit integer
303-
return (self.time_hi, self.time_mid, self.time_hi_version,
304-
self.clock_seq_hi_variant, self.clock_seq_low, self.node)
305301
return (self.time_low, self.time_mid, self.time_hi_version,
306302
self.clock_seq_hi_variant, self.clock_seq_low, self.node)
307303

308304
@property
309305
def time_low(self):
310-
if self.version == 6:
311-
return (self.int >> 64) & 0x0fff
312306
return self.int >> 96
313307

314308
@property
315309
def time_mid(self):
316310
return (self.int >> 80) & 0xffff
317311

318-
@property
319-
def time_hi(self):
320-
if self.version == 6:
321-
return self.int >> 96
322-
return (self.int >> 64) & 0x0fff
323-
324312
@property
325313
def time_hi_version(self):
326314
return (self.int >> 64) & 0xffff
@@ -336,8 +324,16 @@ def clock_seq_low(self):
336324
@property
337325
def time(self):
338326
if self.version == 6:
339-
return (self.time_hi << 28) | (self.time_mid << 12) | self.time_low
340-
return (self.time_hi << 48) | (self.time_mid << 32) | self.time_low
327+
# In version 1, the first field contains the 32 MSBs
328+
# and the field after the version contains the 12 LSBs.
329+
time_hi = self.int >> 96 # == fields[0]
330+
time_lo = (self.int >> 64) & 0x0fff # == fields[2] & 0x0fff
331+
return time_hi << 28 | (self.time_mid << 12) | time_lo
332+
else:
333+
# In version 1, the first field contains the 32 LSBs
334+
# and the field after the version contains the 12 MSBs.
335+
time_hi = (self.int >> 64) & 0x0fff # == fields[2] & 0x0fff
336+
return time_hi << 48 | (self.time_mid << 32) | self.time_low
341337

342338
@property
343339
def clock_seq(self):

0 commit comments

Comments
 (0)