btstack/tool/uuid128_formats.py
David Lechner 73677349c9 tool: consistently use raw strings for regular expressions
Newer versions of Python raise a SyntaxWarning when a regular expression
contains a backslash that is not part of an escape sequence. To prevent
this warning and future exceptions, use raw strings for all regular
expressions. Even strings without escape sequences are converted for
consistency. Some IDEs will apply special syntax highlighting to raw
strings, which can make it easier to decipher regular expressions.
2025-01-22 08:40:56 +01:00

35 lines
899 B
Python
Executable File

#!/usr/bin/env python3
#
# Parase and dump UUID128 in various formats
import codecs
import io
import os
import re
import string
import sys
usage = '''
Usage: ./uuid128_formats.py UUID128
'''
def twoByteLEFor(value):
return [ (value & 0xff), (value >> 8)]
def parseUUID128(uuid):
parts = re.match(r"([0-9A-Fa-f]{4})([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})([0-9A-Fa-f]{4})([0-9A-Fa-f]{4})", uuid)
uuid_bytes = []
for i in range(8, 0, -1):
uuid_bytes = uuid_bytes + twoByteLEFor(int(parts.group(i),16))
return uuid_bytes
if (len(sys.argv) < 2):
print(usage)
sys.exit(1)
uuid128 = sys.argv[1]
uuid_bytes = parseUUID128(uuid128)
print('UUID128: %s' % uuid128)
print('little endian: %s' % ', '.join( [hex(i) for i in uuid_bytes] ))
print('big endian: %s' % ', '.join( [hex(i) for i in reversed(uuid_bytes)] ))