mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-23 19:20:51 +00:00
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.
35 lines
899 B
Python
Executable File
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)] ))
|