Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (19 sloc) 817 Bytes
def uuid(value: str) -> bytes:
"""Serializes a string UUID into bytes with a Microsoft COM-compatible
mixed-endian format.
Call :meth:`bytes.hex` on the return value to convert into a string of
hexadecimal digits.
See also Visual Studio's `uuid attribute <>`_.
>>> guid = "B3A6F3E0-2B43-11CF-A2DE-00AA00B93356"
>>> uuid(guid).hex()
def rev(v: bytes) -> bytes:
return bytes(reversed(v))
time_low, time_mid, time_hi, clock_seq, node = [
bytes.fromhex(v) for v in value.split("-")
return b"".join([rev(time_low), rev(time_mid), rev(time_hi), clock_seq, node])
if __name__ == "__main__":
import sys
print(*[f"{b:02x}" for b in uuid(sys.argv[1])])
You can’t perform that action at this time.