summaryrefslogtreecommitdiff
path: root/serial
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2014-08-01 01:38:04 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2014-08-01 01:38:04 +0000
commitc5ca0035ab7ead3199d63024afa3dd8786b1cc9c (patch)
tree7ccee1e1cb423c489e2494d0d7787d6e4e06e103 /serial
parent0eb13de9799897a80f3fb91bef32a5c631c05bb4 (diff)
downloadpyserial-c5ca0035ab7ead3199d63024afa3dd8786b1cc9c.tar.gz
[Bug pyserial:163] serial.tools.list_ports.grep() fails if it encounters None type
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@499 f19166aa-fa4f-0410-85c2-fa1106f25c8a
Diffstat (limited to 'serial')
-rw-r--r--serial/tools/list_ports_osx.py38
1 files changed, 20 insertions, 18 deletions
diff --git a/serial/tools/list_ports_osx.py b/serial/tools/list_ports_osx.py
index c9ed615..242f468 100644
--- a/serial/tools/list_ports_osx.py
+++ b/serial/tools/list_ports_osx.py
@@ -180,24 +180,26 @@ def comports():
info = []
# First, add the callout device file.
- info.append(get_string_property(service, "IOCalloutDevice"))
-
- # If the serial port is implemented by a
- usb_device = GetParentDeviceByType(service, "IOUSBDevice")
- if usb_device != None:
- info.append(get_string_property(usb_device, "USB Product Name"))
-
- info.append(
- "USB VID:PID=%x:%x SNR=%s"%(
- get_int_property(usb_device, "idVendor"),
- get_int_property(usb_device, "idProduct"),
- get_string_property(usb_device, "USB Serial Number"))
- )
- else:
- info.append('n/a')
- info.append('n/a')
-
- ports.append(info)
+ device = get_string_property(service, "IOCalloutDevice")
+ if device:
+ info.append(device)
+
+ # If the serial port is implemented by a
+ usb_device = GetParentDeviceByType(service, "IOUSBDevice")
+ if usb_device is not None:
+ info.append(get_string_property(usb_device, "USB Product Name") or 'n/a')
+
+ info.append(
+ "USB VID:PID=%x:%x SNR=%s"%(
+ get_int_property(usb_device, "idVendor"),
+ get_int_property(usb_device, "idProduct"),
+ get_string_property(usb_device, "USB Serial Number"))
+ )
+ else:
+ info.append('n/a')
+ info.append('n/a')
+
+ ports.append(info)
return ports