Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2b8b08

Browse files
committed
remove dedicated constant folding
1 parent ccb972b commit e2b8b08

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

Lib/uuid.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,15 @@ class SafeUUID:
8585
unknown = None
8686

8787

88-
_UINT_128_MAX = 0xffff_ffff_ffff_ffff_ffff_ffff_ffff_ffff
88+
_UINT_128_MAX = (1 << 128) - 1
8989
# 128-bit mask to clear the variant and version bits of a UUID integral value
90-
#
91-
# This is equivalent to the 2-complement of '(0xc000 << 48) | (0xf000 << 64)'.
92-
_RFC_4122_CLEARFLAGS_MASK = 0xffff_ffff_ffff_0fff_3fff_ffff_ffff_ffff
90+
_RFC_4122_CLEARFLAGS_MASK = ~((0xf000 << 64) | (0xc000 << 48))
9391
# RFC 4122 variant bits and version bits to activate on a UUID integral value.
94-
#
95-
# The values are equivalent to '(version << 76) | (0x8000 << 48)'.
96-
_RFC_4122_VERSION_1_FLAGS = 0x0000_0000_0000_1000_8000_0000_0000_0000
97-
_RFC_4122_VERSION_3_FLAGS = 0x0000_0000_0000_3000_8000_0000_0000_0000
98-
_RFC_4122_VERSION_4_FLAGS = 0x0000_0000_0000_4000_8000_0000_0000_0000
99-
_RFC_4122_VERSION_5_FLAGS = 0x0000_0000_0000_5000_8000_0000_0000_0000
100-
_RFC_4122_VERSION_8_FLAGS = 0x0000_0000_0000_8000_8000_0000_0000_0000
92+
_RFC_4122_VERSION_1_FLAGS = ((1 << 76) | (0x8000 << 48))
93+
_RFC_4122_VERSION_3_FLAGS = ((3 << 76) | (0x8000 << 48))
94+
_RFC_4122_VERSION_4_FLAGS = ((4 << 76) | (0x8000 << 48))
95+
_RFC_4122_VERSION_5_FLAGS = ((5 << 76) | (0x8000 << 48))
96+
_RFC_4122_VERSION_8_FLAGS = ((8 << 76) | (0x8000 << 48))
10197

10298

10399
class UUID:
@@ -214,17 +210,17 @@ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
214210
raise ValueError('fields is not a 6-tuple')
215211
(time_low, time_mid, time_hi_version,
216212
clock_seq_hi_variant, clock_seq_low, node) = fields
217-
if not 0 <= time_low <= 0xffff_ffff:
213+
if not 0 <= time_low < (1 << 32):
218214
raise ValueError('field 1 out of range (need a 32-bit value)')
219-
if not 0 <= time_mid <= 0xffff:
215+
if not 0 <= time_mid < (1 << 16):
220216
raise ValueError('field 2 out of range (need a 16-bit value)')
221-
if not 0 <= time_hi_version <= 0xffff:
217+
if not 0 <= time_hi_version < (1 << 16):
222218
raise ValueError('field 3 out of range (need a 16-bit value)')
223-
if not 0 <= clock_seq_hi_variant <= 0xff:
219+
if not 0 <= clock_seq_hi_variant < (1 << 8):
224220
raise ValueError('field 4 out of range (need an 8-bit value)')
225-
if not 0 <= clock_seq_low <= 0xff:
221+
if not 0 <= clock_seq_low < (1 << 8):
226222
raise ValueError('field 5 out of range (need an 8-bit value)')
227-
if not 0 <= node <= 0xffff_ffff_ffff:
223+
if not 0 <= node < (1 << 48):
228224
raise ValueError('field 6 out of range (need a 48-bit value)')
229225
clock_seq = (clock_seq_hi_variant << 8) | clock_seq_low
230226
int = ((time_low << 96) | (time_mid << 80) |

0 commit comments

Comments
 (0)