def GetParentDeviceByType(device, parent_type):
 parent_type = parent_type.encode('mac_roman')
 while (IORegistryEntryGetName(device) != parent_type):
  parent = ctypes.c_void_p()
  response = iokit.IORegistryEntryGetParentEntry(device, 'IOService'.encode('mac_roman'), ctypes.byref(parent))
  if (response != 0):
   return None
  device = parent
 return device

def GetParentDeviceByType ( device , parent_type ) : parent_type = parent_type . encode ( 'mac_roman' ) while ( IORegistryEntryGetName ( device ) != parent_type ) : parent = ctypes . c_void_p ( ) response = iokit . IORegistryEntryGetParentEntry ( device , 'IOService' . encode ( 'mac_roman' ) , ctypes . byref ( parent ) ) if ( response != 0 ) : return None device = parent return device
find the first parent of a device that implements the parent_type .