From 716179df06a69ec06c0687186f2a3bfd3dccb165 Mon Sep 17 00:00:00 2001 From: Anna Bridge Date: Fri, 28 Oct 2016 15:06:02 +0100 Subject: [PATCH] Fix issue were a method is attempted to be called on a NoneType. In get_mbeds() if the regular expression for looking for a tid fails then a NoneType occurs. The code then attempts to call the group() function on this which causes an exception. This fix adds a check for the regular expression returning a NoneType before trying to call the method. --- mbed_lstools/lstools_win7.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mbed_lstools/lstools_win7.py b/mbed_lstools/lstools_win7.py index 675f8ec..557d02d 100644 --- a/mbed_lstools/lstools_win7.py +++ b/mbed_lstools/lstools_win7.py @@ -161,7 +161,10 @@ def get_mbeds(self): for mbed in self.get_mbed_devices(): mountpoint = re.match('.*\\\\(.:)$', mbed[0]).group(1) # TargetID is a hex string with 10-48 chars - tid = re.search('[&#]([0-9A-Za-z]{10,48})[&#]', mbed[1]).group(1) + m = re.search('[&#]([0-9A-Za-z]{10,48})[&#]', mbed[1]) + if not m: + continue + tid = m.group(1) mbeds += [(mountpoint, tid)] self.debug(self.get_mbeds.__name__, (mountpoint, tid)) return mbeds