| OLD | NEW | 
|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python | 
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be | 
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. | 
| 5 | 5 | 
| 6 """Script for converting the Web Bluetooth GATT blacklist into the format | 6 """Script for converting the Web Bluetooth GATT blocklist into the format | 
| 7 expected by ContentBrowserClient#GetWebBluetoothBlacklist. | 7 expected by ContentBrowserClient#GetWebBluetoothBlocklist. | 
| 8 | 8 | 
| 9 See: | 9 See: | 
| 10 https://github.com/WebBluetoothCG/registries/blob/master/gatt_blacklist.txt | 10 https://github.com/WebBluetoothCG/registries/blob/master/gatt_blocklist.txt | 
| 11 content/public/browser/content_browser_client.h | 11 content/public/browser/content_browser_client.h | 
| 12 | 12 | 
| 13 Usage: | 13 Usage: | 
| 14   compact_blacklist.py <gatt_blacklist.txt> | 14   compact_blocklist.py <gatt_blocklist.txt> | 
| 15 """ | 15 """ | 
| 16 | 16 | 
| 17 import collections | 17 import collections | 
| 18 import string | 18 import string | 
| 19 import sys | 19 import sys | 
| 20 | 20 | 
| 21 UUID_LENGTH = 36 | 21 UUID_LENGTH = 36 | 
| 22 UUID_BASE_POSTFIX = '-0000-1000-8000-00805f9b34fb' | 22 UUID_BASE_POSTFIX = '-0000-1000-8000-00805f9b34fb' | 
| 23 | 23 | 
| 24 | 24 | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 62   bluetooth_uuid.cc also works the same way. | 62   bluetooth_uuid.cc also works the same way. | 
| 63   """ | 63   """ | 
| 64 | 64 | 
| 65   if uuid[8:] == UUID_BASE_POSTFIX: | 65   if uuid[8:] == UUID_BASE_POSTFIX: | 
| 66     new_uuid = '%x' % int(uuid[:8], 16) | 66     new_uuid = '%x' % int(uuid[:8], 16) | 
| 67     if len(new_uuid) in [4, 8]: | 67     if len(new_uuid) in [4, 8]: | 
| 68       uuid = new_uuid | 68       uuid = new_uuid | 
| 69   return uuid | 69   return uuid | 
| 70 | 70 | 
| 71 | 71 | 
| 72 def Process(line, blacklist): | 72 def Process(line, blocklist): | 
| 73   line = line.strip().lower() | 73   line = line.strip().lower() | 
| 74   if not line or line.startswith('#'): | 74   if not line or line.startswith('#'): | 
| 75     return | 75     return | 
| 76   fields = line.split() | 76   fields = line.split() | 
| 77   if len(fields) not in [1, 2]: | 77   if len(fields) not in [1, 2]: | 
| 78     raise BadLineException('Badly formatted line: %s' % line) | 78     raise BadLineException('Badly formatted line: %s' % line) | 
| 79   uuid = fields[0] | 79   uuid = fields[0] | 
| 80   if not ValidUUID(uuid): | 80   if not ValidUUID(uuid): | 
| 81     raise InvalidUUIDException('Invalid UUID: %s' % line) | 81     raise InvalidUUIDException('Invalid UUID: %s' % line) | 
| 82   uuid = ShortenUUID(uuid) | 82   uuid = ShortenUUID(uuid) | 
| 83   if uuid in blacklist: | 83   if uuid in blocklist: | 
| 84     raise DuplicateUUIDException('Duplicate UUID: %s' % line) | 84     raise DuplicateUUIDException('Duplicate UUID: %s' % line) | 
| 85   if len(fields) == 1: | 85   if len(fields) == 1: | 
| 86     blacklist[uuid] = 'e' | 86     blocklist[uuid] = 'e' | 
| 87   elif fields[1] == 'exclude-writes': | 87   elif fields[1] == 'exclude-writes': | 
| 88     blacklist[uuid] = 'w' | 88     blocklist[uuid] = 'w' | 
| 89   elif fields[1] == 'exclude-reads': | 89   elif fields[1] == 'exclude-reads': | 
| 90     blacklist[uuid] = 'r' | 90     blocklist[uuid] = 'r' | 
| 91   else: | 91   else: | 
| 92     raise InvalidExclusionException('Invalid exclusion value: %s' % line) | 92     raise InvalidExclusionException('Invalid exclusion value: %s' % line) | 
| 93 | 93 | 
| 94 | 94 | 
| 95 def main(): | 95 def main(): | 
| 96   if len(sys.argv) != 2: | 96   if len(sys.argv) != 2: | 
| 97     print('Usage: %s <gatt_blacklist.txt>' % sys.argv[0]) | 97     print('Usage: %s <gatt_blocklist.txt>' % sys.argv[0]) | 
| 98     return 1 | 98     return 1 | 
| 99 | 99 | 
| 100   try: | 100   try: | 
| 101     blacklist = collections.OrderedDict() | 101     blocklist = collections.OrderedDict() | 
| 102     with open(sys.argv[1]) as f: | 102     with open(sys.argv[1]) as f: | 
| 103       for line in f: | 103       for line in f: | 
| 104         Process(line, blacklist) | 104         Process(line, blocklist) | 
| 105     print(','.join('%s:%s' % (uuid, blacklist[uuid]) for uuid in blacklist)) | 105     print(','.join('%s:%s' % (uuid, blocklist[uuid]) for uuid in blocklist)) | 
| 106     return 0 | 106     return 0 | 
| 107   except Exception as e: | 107   except Exception as e: | 
| 108     print('Failed to compact blacklist. %s' % e) | 108     print('Failed to compact blocklist. %s' % e) | 
| 109     return 1 | 109     return 1 | 
| 110 | 110 | 
| 111 | 111 | 
| 112 if __name__ == '__main__': | 112 if __name__ == '__main__': | 
| 113   sys.exit(main()) | 113   sys.exit(main()) | 
| OLD | NEW | 
|---|