tools/pydfu.py: Make the DFU tool work again with Python 2.

This patch will work for both Python 2 and 3.
pull/3959/merge
roland 2018-07-27 07:55:32 +02:00 zatwierdzone przez Damien George
rodzic 434975defa
commit 11a38d5dc5
1 zmienionych plików z 5 dodań i 1 usunięć

Wyświetl plik

@ -61,8 +61,12 @@ __verbose = None
# USB DFU interface
__DFU_INTERFACE = 0
# Python 3 deprecated getargspec in favour of getfullargspec, but
# Python 2 doesn't have the latter, so detect which one to use
import inspect
if 'length' in inspect.getfullargspec(usb.util.get_string).args:
getargspec = getattr(inspect, 'getfullargspec', inspect.getargspec)
if 'length' in getargspec(usb.util.get_string).args:
# PyUSB 1.0.0.b1 has the length argument
def get_string(dev, index):
return usb.util.get_string(dev, 255, index)