Skip to content

Commit bdf214f

Browse files
committed
gh-150226: Speed up uuid UUID string parsing
1 parent 1daad8a commit bdf214f

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/uuid.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,12 @@ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
213213
if int is not None:
214214
pass
215215
elif hex is not None:
216-
hex = hex.replace('urn:', '').replace('uuid:', '')
216+
original_hex = hex
217+
hex = hex.removeprefix('urn:uuid:')
217218
hex = hex.strip('{}').replace('-', '')
219+
if len(hex) != 32:
220+
hex = original_hex.replace('urn:', '').replace('uuid:', '')
221+
hex = hex.strip('{}').replace('-', '')
218222
if len(hex) != 32:
219223
raise ValueError('badly formed hexadecimal UUID string')
220224
int = int_(hex, 16)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Speed up construction of :class:`uuid.UUID` from documented string formats.

0 commit comments

Comments
 (0)