Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
specifiers = urlparts.netloc.split(':')
plcomps = specifiers + [''] * 2
try:
plcomps[0] = vdict.get(plcomps[0], plcomps[0])
if plcomps[0]:
vendor = to_int(plcomps[0])
else:
vendor = None
product_ids = pdict.get(vendor, None)
if not product_ids:
product_ids = pdict[default_vendor]
plcomps[1] = product_ids.get(plcomps[1], plcomps[1])
if plcomps[1]:
try:
product = to_int(plcomps[1])
except ValueError:
raise UsbToolsError('Product %s is not referenced' %
plcomps[1])
else:
product = None
except (IndexError, ValueError):
raise UsbToolsError('Invalid device URL: %s' %
urlunsplit(urlparts))
sernum = None
idx = None
bus = None
address = None
locators = specifiers[2:]
if len(locators) > 1:
try:
bus = int(locators[0], 16)
URL syntax:
protocol://vendor:product[:serial|:index|:bus:addr]/interface
"""
urlparts = urlsplit(urlstr)
if scheme != urlparts.scheme:
raise UsbToolsError("Invalid URL: %s" % urlstr)
try:
if not urlparts.path:
raise UsbToolsError('URL string is missing device port')
path = urlparts.path.strip('/')
if path == '?' or (not path and urlstr.endswith('?')):
report_devices = True
else:
interface = to_int(path)
report_devices = False
except (IndexError, ValueError):
raise UsbToolsError('Invalid device URL: %s' % urlstr)
candidates, idx = cls.enumerate_candidates(urlparts, vdict, pdict,
default_vendor)
if report_devices:
UsbTools.show_devices(scheme, vdict, pdict, candidates)
raise SystemExit(candidates and
'Please specify the USB device' or
'No USB-Serial device has been detected')
if idx is None:
if len(candidates) > 1:
raise UsbToolsError("%d USB devices match URL '%s'" %
(len(candidates), urlstr))
idx = 0
try:
'in_isochronous': (2, 0),
'out_isochronous': (2, 1),
'suspend_pull_down': (2, 2),
'has_serial': (2, 3),
}
if name in confs:
val = to_bool(value, permissive=False, allow_int=True)
offset, bit = confs[name]
mask = 1 << bit
if val:
self._eeprom[0x08+offset] |= mask
else:
self._eeprom[0x0a+offset] &= ~mask
return
if name == 'power_max':
val = to_int(value) >> 1
self._eeprom[0x09] = val
return
if name in self.properties:
raise NotImplementedError("Change to '%s' is not yet supported" %
name)
raise ValueError("Unknown property '%s'" % name)
self._set_cbus_func(int(mobj.group(1)), value, out)
self._dirty.add(name)
return
mobj = match(r'([abcd])bus_(drive|slow_slew|schmitt)', name)
if mobj:
self._set_bus_control(mobj.group(1), mobj.group(2), value, out)
self._dirty.add(name)
return
hwords = {
'vendor_id': 0x02,
'product_id': 0x04,
'type': 0x06,
'usb_version': 0x0c
}
if name in hwords:
val = to_int(value)
if not 0 <= val <= 0xFFFF:
raise ValueError('Invalid value for %s' % name)
offset = hwords[name]
self._eeprom[offset:offset+2] = spack('