3 UZ@sJddlZejddkZGdddeZGdddeZGdddeZdS) Nc@s2eZdZdZdZdZd ddZddZdd ZdS) USBz) Interace to usb.ids from hwdata package z/usr/share/hwdata/usb.idsNc Cs|r ||_ntj|_d|_|jo&tj rit_trDt|jdd}n t|j}d}d}d}xb|jD]T}|d7}|j}|jdr|jdrfPnqfqft |dkrqfqf|jdr2|dj }t |d krd j |dd} nd } y| tj|d|d|<Wn,t k r.t jjd j||jYnXqf|jd rt|dj }d j |dd} | igtj|d|<qf|dj }d j |dd} |tjkr| igtj|<qf| tj|d<qfWdS)z Load pci.ids from file to internal data structure. parameter 'filename' can specify location of this file z ISO8859-1)encodingrN#z8# List of known device classes, subclasses and protocolsz  z!Unknown line at line {0} in {1}.  )filenamercachedevicesinPy3kopen readlinessplit startswithlenlowerjoin TypeErrorsysstderrwriteformat) selfr flinenovendordevicelinelZ interface_idZinterface_name device_name vendor_namer$/usr/lib/python3.6/hwdata.py__init__sN           z USB.__init__cCs2|j}|jr,|tjkr&tj|dSdSndS)z~ Return description of vendor. Parameter is two byte code in hexa. If vendor is unknown None is returned. rN)rr rr )rrr$r$r% get_vendorOs  zUSB.get_vendorcCsZ|j}|j}|jrT|tjkrN|tj|dkrHtj|d|dSdSqVdSndS)z Return description of device. Parameters are two byte code variables in hexa. If device is unknown None is returned. rrN)rr rr )rrrr$r$r% get_device\s zUSB.get_device)N) __name__ __module__ __qualname____doc__r r r&r'r(r$r$r$r%rs  4 rc@s2eZdZdZdZdZd ddZddZdd ZdS) PCIz) Interace to pci.ids from hwdata package z/usr/share/hwdata/pci.idsNc Cs(|r ||_ntj|_d|_|jo&tj r$it_trDt|jdd}n t|j}d}x|jD]}|j}|jdrvq\q\t |dkrq\q\|jdrq\q\|jdr|dj }d j |dd}|tj|d|<q\|dj }d j |dd}|t tjj kr|igtj|<q\|tj|d<q\WdS) z Load pci.ids from file to internal data structure. parameter 'filename' can specify location of this file rz ISO8859-1)rNrrz r r)r r-r r rrrrrrrrlistkeys) rr rrr r!rr"r#r$r$r%r&rs6       z PCI.__init__cCs:|j}|jr4|ttjjkr.tj|dSdSndS)z~ Return description of vendor. Parameter is two byte code in hexa. If vendor is unknown None is returned. rN)rr r.r-r r/)rrr$r$r%r's zPCI.get_vendorcCsf|j}|j}|jr`|ttjjkrZ|ttj|djkrTtj|d|SdSqbdSndS)z Return description of device. Parameters are two byte code variables in hexa. If device is unknown None is returned. rN)rr r.r-r r/)rrrr$r$r%r(szPCI.get_device)N) r)r*r+r,r r r&r'r(r$r$r$r%r-ms  & r-c@s*eZdZdZdZdZdddZddZdS) PNPz) Interace to pnp.ids from hwdata package z/usr/share/hwdata/pnp.idsNcCs|r ||_ntj|_d|_|jrtj rit_trBt|jdd}n t|j}xZ|jD]N}|j}|jdrpqVqVt |dkrqVqV|dj }dj |ddtj|<qVWdS)z Load pnp.ids from file to internal data structure. parameter 'filename' can specify location of this file rz ISO8859-1)rrrrN) r r0r VENDORSrrrrrrupperr)rr rr r! vendor_idr$r$r%r&s"    z PNP.__init__cCs6|j}|jr0|ttjjkr*tj|SdSndS)z Return description of vendor. Parameter is 3 character long id of vendor. If vendor is unknown None is returned. N)r2r r.r0r1r/)rr3r$r$r%r's  zPNP.get_vendor)N)r)r*r+r,r r1r&r'r$r$r$r%r0s  r0)r version_inforobjectrr-r0r$r$r$r%sWI