Skip to content

Commit bab18c0

Browse files
committed
Improve Mac performance for mbedls (#225)
Try quick way first and fall back to robust way if it fails
1 parent b5a9026 commit bab18c0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/mbed_os_tools/detect/darwin.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ def _plist_from_popen(popen):
4242
if not out:
4343
return []
4444
try:
45-
# Beautiful soup ensures the XML is properly formed after it is parsed
46-
# so that it can be used by other less lenient commands without problems
47-
xml_representation = BeautifulSoup(out.decode('utf8'), 'xml')
48-
if not xml_representation.get_text():
49-
# The output is not in the XML format
45+
try:
46+
# Try simple and fast first if this fails fall back to the slower but better process
5047
return loads(out)
51-
return loads(xml_representation.decode().encode('utf8'))
48+
except ExpatError:
49+
# Beautiful soup ensures the XML is properly formed after it is parsed
50+
# so that it can be used by other less lenient commands without problems
51+
xml_representation = BeautifulSoup(out.decode('utf8'), 'xml')
52+
53+
if not xml_representation.get_text():
54+
# The output is not in the XML format
55+
return loads(out)
56+
return loads(xml_representation.decode().encode('utf8'))
5257
except ExpatError:
5358
return []
5459

0 commit comments

Comments
 (0)