@@ -426,27 +426,32 @@ def _load_usb_known_devices(cls) -> Dict[str, Dict[str, Tuple[str, str]]]:
426426 vendor_name : Optional [str ] = None
427427 for line in usb_ids .readlines ():
428428 line = line .rstrip ()
429- if line .startswith ("#" ):
430- # skip comments
431- continue
432429 if not line :
433430 # skip empty lines
434431 continue
435- if line .startswith ("\t \t " ):
436- # skip interfaces
432+ first_char = line [0 ]
433+ if first_char == "#" :
434+ # skip comments
437435 continue
438- if line . startswith ( "C " ) :
436+ if first_char == "C" and len ( line ) >= 2 and line [ 1 ] == " " :
439437 # description of classes starts here, we can finish
440438 break
441- if line .startswith ("\t " ):
439+ if first_char == "\t " :
440+ if len (line ) >= 2 and line [1 ] == "\t " :
441+ # skip interfaces
442+ continue
443+ # device line
444+ parts = line [1 :].split (" " , 2 )
445+ if len (parts ) < 3 :
446+ continue
442447 # save vendor, device pair
443- device_id , _ , device_name = line [ 1 :]. split ( " " , 2 )
448+ device_id , _ , device_name = parts
444449 if vendor_id is None or vendor_name is None :
445450 continue
446- result [vendor_id ][device_id ] = vendor_name , device_name
451+ result [vendor_id ][device_id ] = ( vendor_name , device_name )
447452 else :
448- # new vendor
449- vendor_id , _ , vendor_name = line [:]. split ( " " , 2 )
453+ parts = line . split ( " " , 2 )
454+ vendor_id , _ , vendor_name = parts
450455 result [vendor_id ] = {}
451456
452457 cls ._usb_known_devices = result
0 commit comments