diff -Nru python-libusb1-1.6.3/debian/changelog python-libusb1-1.7/debian/changelog --- python-libusb1-1.6.3/debian/changelog 2017-01-25 12:27:21.000000000 +0000 +++ python-libusb1-1.7/debian/changelog 2019-01-28 02:30:21.000000000 +0000 @@ -1,8 +1,21 @@ -python-libusb1 (1.6.3-1) unstable; urgency=medium +python-libusb1 (1.7-1) unstable; urgency=medium + [ Ondřej Nový ] + * d/control: + + Set Vcs-* to salsa.debian.org. + + Remove ancient X-Python-Version and X-Python3-Version fields. + * d/copyright: Use https protocol in Format field. + * d/watch: Use https protocol. + * Convert git repository from git-dpm to gbp layout. + + [ Arnaud Fontaine ] * New upstream release. + + d/copyright: Update copyright years. + * d/rules: Install examples and docs not only to python2.7 package but + also to {python3,pypy} packages as they are useful to use the library. + * d/control: Bump Standards-Version to 4.3.0. - -- Arnaud Fontaine Wed, 25 Jan 2017 21:27:21 +0900 + -- Arnaud Fontaine Mon, 28 Jan 2019 11:30:21 +0900 python-libusb1 (1.6-1) unstable; urgency=medium diff -Nru python-libusb1-1.6.3/debian/control python-libusb1-1.7/debian/control --- python-libusb1-1.6.3/debian/control 2017-01-25 12:27:11.000000000 +0000 +++ python-libusb1-1.7/debian/control 2019-01-28 02:29:34.000000000 +0000 @@ -12,12 +12,10 @@ Build-Depends-Indep: python-setuptools, python3-setuptools, pypy-setuptools -X-Python-Version: >= 2.7 -X-Python3-Version: >= 3.2 -Standards-Version: 3.9.8 -Homepage: http://github.com/vpelletier/python-libusb1 -Vcs-Git: https://anonscm.debian.org/git/python-modules/packages/python-libusb1.git -Vcs-Browser: https://anonscm.debian.org/cgit/python-modules/packages/python-libusb1.git +Standards-Version: 4.3.0 +Homepage: https://github.com/vpelletier/python-libusb1 +Vcs-Git: https://salsa.debian.org/python-team/modules/python-libusb1.git +Vcs-Browser: https://salsa.debian.org/python-team/modules/python-libusb1 Package: python-libusb1 Architecture: all diff -Nru python-libusb1-1.6.3/debian/copyright python-libusb1-1.7/debian/copyright --- python-libusb1-1.6.3/debian/copyright 2017-01-25 12:27:11.000000000 +0000 +++ python-libusb1-1.7/debian/copyright 2019-01-28 02:12:00.000000000 +0000 @@ -1,14 +1,14 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: libusb1 Upstream-Contact: Vincent Pelletier -Source: http://github.com/vpelletier/python-libusb1 +Source: https://github.com/vpelletier/python-libusb1 Files: * -Copyright: 2010-2016 Vincent Pelletier +Copyright: 2010-2018 Vincent Pelletier License: LGPL-2.1+ Files: debian/* -Copyright: 2016, Arnaud Fontaine +Copyright: 2016-2019, Arnaud Fontaine License: LGPL-2.1+ License: LGPL-2.1+ diff -Nru python-libusb1-1.6.3/debian/docs python-libusb1-1.7/debian/docs --- python-libusb1-1.6.3/debian/docs 2017-01-25 12:27:11.000000000 +0000 +++ python-libusb1-1.7/debian/docs 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -README.rst diff -Nru python-libusb1-1.6.3/debian/examples python-libusb1-1.7/debian/examples --- python-libusb1-1.6.3/debian/examples 2017-01-25 12:27:11.000000000 +0000 +++ python-libusb1-1.7/debian/examples 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -examples/* diff -Nru python-libusb1-1.6.3/debian/gbp.conf python-libusb1-1.7/debian/gbp.conf --- python-libusb1-1.6.3/debian/gbp.conf 1970-01-01 00:00:00.000000000 +0000 +++ python-libusb1-1.7/debian/gbp.conf 2019-01-28 02:06:50.000000000 +0000 @@ -0,0 +1,3 @@ +[DEFAULT] +debian-branch=master +pristine-tar=True diff -Nru python-libusb1-1.6.3/debian/.git-dpm python-libusb1-1.7/debian/.git-dpm --- python-libusb1-1.6.3/debian/.git-dpm 2017-01-25 12:27:11.000000000 +0000 +++ python-libusb1-1.7/debian/.git-dpm 1970-01-01 00:00:00.000000000 +0000 @@ -1,8 +0,0 @@ -# see git-dpm(1) from git-dpm package -0b3d605e55c3d262986d8f4875feb93910278e26 -0b3d605e55c3d262986d8f4875feb93910278e26 -0b3d605e55c3d262986d8f4875feb93910278e26 -0b3d605e55c3d262986d8f4875feb93910278e26 -python-libusb1_1.5.3.orig.tar.gz -ad01473c054431f145f117a163ab66f9da0f4ca7 -53409 diff -Nru python-libusb1-1.6.3/debian/rules python-libusb1-1.7/debian/rules --- python-libusb1-1.6.3/debian/rules 2017-01-25 12:27:11.000000000 +0000 +++ python-libusb1-1.7/debian/rules 2019-01-28 02:22:50.000000000 +0000 @@ -5,3 +5,9 @@ %: dh $@ --with python2,python3,pypy --buildsystem=pybuild + +override_dh_installexamples: + dh_installexamples -A examples/* + +override_dh_installdocs: + dh_installdocs -A README.rst diff -Nru python-libusb1-1.6.3/debian/watch python-libusb1-1.7/debian/watch --- python-libusb1-1.6.3/debian/watch 2017-01-25 12:27:11.000000000 +0000 +++ python-libusb1-1.7/debian/watch 2019-01-28 02:05:54.000000000 +0000 @@ -1,3 +1,3 @@ version=3 opts="dversionmangle=s/\+.*//" \ - http://pypi.debian.net/libusb1/libusb1-(.+)\.(?:zip|tgz|tbz|txz|(?:tar\.(?:gz|bz2|xz))) + https://pypi.debian.net/libusb1/libusb1-(.+)\.(?:zip|tgz|tbz|txz|(?:tar\.(?:gz|bz2|xz))) diff -Nru python-libusb1-1.6.3/examples/hotplug_advanced.py python-libusb1-1.7/examples/hotplug_advanced.py --- python-libusb1-1.6.3/examples/hotplug_advanced.py 2016-08-21 23:20:50.000000000 +0000 +++ python-libusb1-1.7/examples/hotplug_advanced.py 2018-12-13 23:44:20.000000000 +0000 @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (C) 2013-2016 Vincent Pelletier +# Copyright (C) 2013-2018 Vincent Pelletier # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -105,6 +105,7 @@ different key events when the same button is pressed on different devices). Returns whether this device should be ignored. + Cannot call synchronous API. """ self.context = usb1.USBContext() if not self.context.hasCapability(usb1.CAP_HAS_HOTPLUG): diff -Nru python-libusb1-1.6.3/examples/hotplug.py python-libusb1-1.7/examples/hotplug.py --- python-libusb1-1.6.3/examples/hotplug.py 2016-08-21 23:20:50.000000000 +0000 +++ python-libusb1-1.7/examples/hotplug.py 2018-12-13 23:44:20.000000000 +0000 @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (C) 2013-2016 Vincent Pelletier +# Copyright (C) 2013-2018 Vincent Pelletier # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -14,30 +14,32 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +from __future__ import print_function import usb1 def hotplug_callback(context, device, event): - print "Device %s: %s" % ( + print("Device %s: %s" % ( { usb1.HOTPLUG_EVENT_DEVICE_ARRIVED: 'arrived', usb1.HOTPLUG_EVENT_DEVICE_LEFT: 'left', }[event], device, - ) + )) + # Note: cannot call synchronous API in this function. def main(): with usb1.USBContext() as context: if not context.hasCapability(usb1.CAP_HAS_HOTPLUG): - print 'Hotplug support is missing. Please update your libusb version.' + print('Hotplug support is missing. Please update your libusb version.') return - print 'Registering hotplug callback...' + print('Registering hotplug callback...') opaque = context.hotplugRegisterCallback(hotplug_callback) - print 'Callback registered. Monitoring events, ^C to exit' + print('Callback registered. Monitoring events, ^C to exit') try: while True: context.handleEvents() except (KeyboardInterrupt, SystemExit): - print 'Exiting' + print('Exiting') if __name__ == '__main__': main() diff -Nru python-libusb1-1.6.3/examples/listdevs.py python-libusb1-1.7/examples/listdevs.py --- python-libusb1-1.6.3/examples/listdevs.py 2016-08-21 23:20:50.000000000 +0000 +++ python-libusb1-1.7/examples/listdevs.py 2018-12-13 23:44:20.000000000 +0000 @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (C) 2013-2016 Vincent Pelletier +# Copyright (C) 2013-2018 Vincent Pelletier # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -14,12 +14,13 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +from __future__ import print_function import usb1 def main(): with usb1.USBContext() as context: for device in context.getDeviceIterator(skip_on_error=True): - print 'ID %04x:%04x' % (device.getVendorID(), device.getProductID()), '->'.join(str(x) for x in ['Bus %03i' % (device.getBusNumber(), )] + device.getPortNumberList()), 'Device', device.getDeviceAddress() + print('ID %04x:%04x' % (device.getVendorID(), device.getProductID()), '->'.join(str(x) for x in ['Bus %03i' % (device.getBusNumber(), )] + device.getPortNumberList()), 'Device', device.getDeviceAddress()) if __name__ == '__main__': main() diff -Nru python-libusb1-1.6.3/libusb1.egg-info/PKG-INFO python-libusb1-1.7/libusb1.egg-info/PKG-INFO --- python-libusb1-1.6.3/libusb1.egg-info/PKG-INFO 2017-01-25 10:33:55.000000000 +0000 +++ python-libusb1-1.7/libusb1.egg-info/PKG-INFO 2018-12-13 23:45:20.000000000 +0000 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: libusb1 -Version: 1.6.3 +Version: 1.7 Summary: Pure-python wrapper for libusb-1.0 Home-page: http://github.com/vpelletier/python-libusb1 Author: Vincent Pelletier @@ -28,7 +28,7 @@ - CPython_ 2.7+ or 3.4+, pypy_ 2.0+. Older versions may work, but are not recommended as there is no automated regression testing set up for them. - - libusb-1.0_ or libusbx_ + - libusb-1.0_ Supported OSes ============== @@ -404,6 +404,47 @@ descriptors while a poll is already running, causing long pauses - if not deadlocks. + 1.6.4 + ----- + + Fix asynchronous control transfers. + + 1.6.5 + ----- + + Document hotplug handler limitations. + + Run 2to3 when running setup.py with python3, and reduce differences with + python3. + + Properly cast libusb_set_pollfd_notifiers arguments. + Fix null pointer value: POINTER(None) is the type of a pointer which may be a + null pointer, which falls back to c_void_p. But c_void_p() is an actual null + pointer. + + 1.6.6 + ----- + + Expose bare string descriptors (aka string indexes) on USBDevice. + + 1.6.7 + ----- + + get{,ASCII}StringDescriptor now return None for descriptor 0 instead of raising + UnicodeDecodeError. Use getSupportedLanguageList to access it. + Moved getManufacturer, getProduct and getSerialNumber to USBDeviceHandle. Kept + shortcuts for these on USBDevice. + + 1.7 + --- + + get{,ASCII}StringDescriptor now return None for descriptor 0, use + getSupportedLanguageList to get its content. + getManufacturer, getProduct and getSerialNumber are now on USBDeviceHandle, + with backward-compatibility aliases on their original location. + Synchronous bulk and interrupt API exposes number of bytes sent and received + bytes even when a timeout occurs. + .. _CPython: http://www.python.org/ .. _pypy: http://pypy.org/ @@ -416,11 +457,9 @@ .. _Homebrew: http://brew.sh/ - .. _libusb-1.0: http://www.libusb.org/wiki/libusb-1.0 - - .. _libusbx: http://libusb.info/ + .. _libusb-1.0: https://github.com/libusb/libusb/wiki/ - .. _libusb1.0 documentation: http://libusb.org/static/api-1.0/ + .. _libusb1.0 documentation: http://libusb.sourceforge.net/api-1.0/ Keywords: usb libusb Platform: any @@ -431,6 +470,11 @@ Classifier: Programming Language :: Python :: 2.5 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development :: Libraries diff -Nru python-libusb1-1.6.3/PKG-INFO python-libusb1-1.7/PKG-INFO --- python-libusb1-1.6.3/PKG-INFO 2017-01-25 10:33:55.000000000 +0000 +++ python-libusb1-1.7/PKG-INFO 2018-12-13 23:45:20.000000000 +0000 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: libusb1 -Version: 1.6.3 +Version: 1.7 Summary: Pure-python wrapper for libusb-1.0 Home-page: http://github.com/vpelletier/python-libusb1 Author: Vincent Pelletier @@ -28,7 +28,7 @@ - CPython_ 2.7+ or 3.4+, pypy_ 2.0+. Older versions may work, but are not recommended as there is no automated regression testing set up for them. - - libusb-1.0_ or libusbx_ + - libusb-1.0_ Supported OSes ============== @@ -404,6 +404,47 @@ descriptors while a poll is already running, causing long pauses - if not deadlocks. + 1.6.4 + ----- + + Fix asynchronous control transfers. + + 1.6.5 + ----- + + Document hotplug handler limitations. + + Run 2to3 when running setup.py with python3, and reduce differences with + python3. + + Properly cast libusb_set_pollfd_notifiers arguments. + Fix null pointer value: POINTER(None) is the type of a pointer which may be a + null pointer, which falls back to c_void_p. But c_void_p() is an actual null + pointer. + + 1.6.6 + ----- + + Expose bare string descriptors (aka string indexes) on USBDevice. + + 1.6.7 + ----- + + get{,ASCII}StringDescriptor now return None for descriptor 0 instead of raising + UnicodeDecodeError. Use getSupportedLanguageList to access it. + Moved getManufacturer, getProduct and getSerialNumber to USBDeviceHandle. Kept + shortcuts for these on USBDevice. + + 1.7 + --- + + get{,ASCII}StringDescriptor now return None for descriptor 0, use + getSupportedLanguageList to get its content. + getManufacturer, getProduct and getSerialNumber are now on USBDeviceHandle, + with backward-compatibility aliases on their original location. + Synchronous bulk and interrupt API exposes number of bytes sent and received + bytes even when a timeout occurs. + .. _CPython: http://www.python.org/ .. _pypy: http://pypy.org/ @@ -416,11 +457,9 @@ .. _Homebrew: http://brew.sh/ - .. _libusb-1.0: http://www.libusb.org/wiki/libusb-1.0 - - .. _libusbx: http://libusb.info/ + .. _libusb-1.0: https://github.com/libusb/libusb/wiki/ - .. _libusb1.0 documentation: http://libusb.org/static/api-1.0/ + .. _libusb1.0 documentation: http://libusb.sourceforge.net/api-1.0/ Keywords: usb libusb Platform: any @@ -431,6 +470,11 @@ Classifier: Programming Language :: Python :: 2.5 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development :: Libraries diff -Nru python-libusb1-1.6.3/README.rst python-libusb1-1.7/README.rst --- python-libusb1-1.6.3/README.rst 2017-01-25 10:32:55.000000000 +0000 +++ python-libusb1-1.7/README.rst 2018-12-13 23:44:20.000000000 +0000 @@ -18,7 +18,7 @@ - CPython_ 2.7+ or 3.4+, pypy_ 2.0+. Older versions may work, but are not recommended as there is no automated regression testing set up for them. -- libusb-1.0_ or libusbx_ +- libusb-1.0_ Supported OSes ============== @@ -394,6 +394,47 @@ descriptors while a poll is already running, causing long pauses - if not deadlocks. +1.6.4 +----- + +Fix asynchronous control transfers. + +1.6.5 +----- + +Document hotplug handler limitations. + +Run 2to3 when running setup.py with python3, and reduce differences with +python3. + +Properly cast libusb_set_pollfd_notifiers arguments. +Fix null pointer value: POINTER(None) is the type of a pointer which may be a +null pointer, which falls back to c_void_p. But c_void_p() is an actual null +pointer. + +1.6.6 +----- + +Expose bare string descriptors (aka string indexes) on USBDevice. + +1.6.7 +----- + +get{,ASCII}StringDescriptor now return None for descriptor 0 instead of raising +UnicodeDecodeError. Use getSupportedLanguageList to access it. +Moved getManufacturer, getProduct and getSerialNumber to USBDeviceHandle. Kept +shortcuts for these on USBDevice. + +1.7 +--- + +get{,ASCII}StringDescriptor now return None for descriptor 0, use +getSupportedLanguageList to get its content. +getManufacturer, getProduct and getSerialNumber are now on USBDeviceHandle, +with backward-compatibility aliases on their original location. +Synchronous bulk and interrupt API exposes number of bytes sent and received +bytes even when a timeout occurs. + .. _CPython: http://www.python.org/ .. _pypy: http://pypy.org/ @@ -406,8 +447,6 @@ .. _Homebrew: http://brew.sh/ -.. _libusb-1.0: http://www.libusb.org/wiki/libusb-1.0 - -.. _libusbx: http://libusb.info/ +.. _libusb-1.0: https://github.com/libusb/libusb/wiki/ -.. _libusb1.0 documentation: http://libusb.org/static/api-1.0/ +.. _libusb1.0 documentation: http://libusb.sourceforge.net/api-1.0/ diff -Nru python-libusb1-1.6.3/setup.cfg python-libusb1-1.7/setup.cfg --- python-libusb1-1.6.3/setup.cfg 2017-01-25 10:33:55.000000000 +0000 +++ python-libusb1-1.7/setup.cfg 2018-12-13 23:45:20.000000000 +0000 @@ -1,5 +1,4 @@ [egg_info] tag_build = tag_date = 0 -tag_svn_revision = 0 diff -Nru python-libusb1-1.6.3/setup.py python-libusb1-1.7/setup.py --- python-libusb1-1.6.3/setup.py 2017-01-25 10:32:55.000000000 +0000 +++ python-libusb1-1.7/setup.py 2018-12-13 23:44:20.000000000 +0000 @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2016 Vincent Pelletier +# Copyright (C) 2010-2018 Vincent Pelletier # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -16,6 +16,7 @@ from setuptools import setup from codecs import open import os +import sys long_description = open( os.path.join(os.path.dirname(__file__), 'README.rst'), @@ -33,7 +34,7 @@ description=next(x for x in long_description.splitlines() if x.strip()), long_description='.. contents::\n\n' + long_description, keywords='usb libusb', - version='1.6.3', + version='1.7', author='Vincent Pelletier', author_email='plr.vincent@gmail.com', url='http://github.com/vpelletier/python-libusb1', @@ -49,9 +50,15 @@ 'Programming Language :: Python :: 2.5', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Software Development :: Libraries', 'Topic :: System :: Hardware :: Hardware Drivers', ], + use_2to3=sys.version_info >= (3, ), ) diff -Nru python-libusb1-1.6.3/usb1/__init__.py python-libusb1-1.7/usb1/__init__.py --- python-libusb1-1.6.3/usb1/__init__.py 2017-01-25 10:32:55.000000000 +0000 +++ python-libusb1-1.7/usb1/__init__.py 2018-12-13 23:44:20.000000000 +0000 @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2016 Vincent Pelletier +# Copyright (C) 2010-2018 Vincent Pelletier # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -149,8 +149,69 @@ xrange = range long = int # pylint: enable=redefined-builtin + integer_memoryview = memoryview else: BYTE = '\x00' + # Work around python2's memoryview, which only accepts & generates strings. + # For consistency between async control and other async transfers. + # Python 2.7 will not be fixed, so wrap its memoryview. + # Breaks the no-copy promise, but control transfer performance should + # matter less than other types. + class integer_memoryview(object): + def __init__(self, view): + if not isinstance(view, memoryview): + view = memoryview(view) + self.__view = view + + # Many boring magic methods, just to mimic memoryview + def __eq__(self, other): + return self.__view == other + + def __ge__(self, other): + return self.__view >= other + + def __gt__(self, other): + return self.__view > other + + def __le__(self, other): + return self.__view <= other + + def __lt__(self, other): + return self.__view < other + + def __ne__(self, other): + return self.__view != other + + def __hash__(self): + # raises + return hash(self.__view) + + def __delitem__(self, key): + # raises + del self.__view[key] + + def __len__(self): + return len(self.__view) + + # To access format, itemsize, ndim, readonly, shape, strides, + # suboffsets, tobytes, tolist. + def __getattr__(self, name): + return getattr(self.__view, name) + + # Actual payload of this class. + def __getitem__(self, key): + value = self.__view[key] + if isinstance(value, memoryview): + return self.__class__(value) + return ord(value) + + def __setitem__(self, key, value): + if isinstance(value, (int, long)): + value = chr(value) + else: + value = ''.join(chr(x) for x in value) + self.__view[key] = value + # pylint: disable=undefined-variable CONTROL_SETUP = BYTE * CONTROL_SETUP_SIZE # pylint: enable=undefined-variable @@ -401,7 +462,9 @@ self.__initialized = False self.__transfer_buffer = string_buffer # pylint: disable=undefined-variable - self.__transfer_py_buffer = transfer_py_buffer[CONTROL_SETUP_SIZE:] + self.__transfer_py_buffer = integer_memoryview( + transfer_py_buffer, + )[CONTROL_SETUP_SIZE:] # pylint: enable=undefined-variable self.__user_data = user_data libusb1.libusb_fill_control_setup( @@ -1176,8 +1239,8 @@ def getDevice(self): """ - Get an USBDevice instance for the device accessed through this handle. - Useful for example to query its configurations. + Get an USBDevice instance for the device accessed through this handle, + to access to the descriptors available in OS cache. """ return self.__device @@ -1199,6 +1262,30 @@ libusb1.libusb_set_configuration(self.__handle, configuration), ) + def getManufacturer(self): + """ + Get device's manufaturer name. + """ + return self.getASCIIStringDescriptor( + self.__device.device_descriptor.iManufacturer, + ) + + def getProduct(self): + """ + Get device's product name. + """ + return self.getASCIIStringDescriptor( + self.__device.device_descriptor.iProduct, + ) + + def getSerialNumber(self): + """ + Get device's serial number. + """ + return self.getASCIIStringDescriptor( + self.__device.device_descriptor.iSerialNumber, + ) + def claimInterface(self, interface): """ Claim (= get exclusive access to) given interface number. Required to @@ -1317,6 +1404,8 @@ Return value is a unicode string. Return None if there is no such descriptor on device. """ + if descriptor == 0: + return None descriptor_string = bytearray(STRING_LENGTH) try: received = mayRaiseUSBError(libusb1.libusb_get_string_descriptor( @@ -1342,6 +1431,8 @@ Return value is a unicode string. Return None if there is no such descriptor on device. """ + if descriptor == 0: + return None descriptor_string = bytearray(STRING_LENGTH) try: received = mayRaiseUSBError(libusb1.libusb_get_string_descriptor_ascii( @@ -1413,9 +1504,13 @@ def _bulkTransfer(self, endpoint, data, length, timeout): transferred = c_int() - mayRaiseUSBError(libusb1.libusb_bulk_transfer( - self.__handle, endpoint, data, length, byref(transferred), timeout, - )) + try: + mayRaiseUSBError(libusb1.libusb_bulk_transfer( + self.__handle, endpoint, data, length, byref(transferred), timeout, + )) + except USBErrorTimeout as exception: + exception.transferred = transferred.value + raise return transferred.value def bulkWrite(self, endpoint, data, timeout=0): @@ -1430,6 +1525,10 @@ interface (ex: bytearray) for the "data" parameter. Returns the number of bytes actually sent. + + May raise an exception from the USBError family. USBErrorTimeout + exception has a "transferred" property giving the number of bytes sent + up to the timeout. """ # pylint: disable=undefined-variable endpoint = (endpoint & ~ENDPOINT_DIR_MASK) | ENDPOINT_OUT @@ -1448,19 +1547,36 @@ interface (ex: bytearray) for the "data" parameter. Returns received data. + + May raise an exception from the USBError family. USBErrorTimeout + exception has a "received" property giving the bytes received up to the + timeout. """ # pylint: disable=undefined-variable endpoint = (endpoint & ~ENDPOINT_DIR_MASK) | ENDPOINT_IN # pylint: enable=undefined-variable data, data_buffer = create_binary_buffer(length) - transferred = self._bulkTransfer(endpoint, data, length, timeout) + try: + transferred = self._bulkTransfer(endpoint, data, length, timeout) + except USBErrorTimeout as exception: + exception.received = data_buffer[:exception.transferred] + raise return data_buffer[:transferred] def _interruptTransfer(self, endpoint, data, length, timeout): transferred = c_int() - mayRaiseUSBError(libusb1.libusb_interrupt_transfer( - self.__handle, endpoint, data, length, byref(transferred), timeout, - )) + try: + mayRaiseUSBError(libusb1.libusb_interrupt_transfer( + self.__handle, + endpoint, + data, + length, + byref(transferred), + timeout, + )) + except USBErrorTimeout as exception: + exception.transferred = transferred.value + raise return transferred.value def interruptWrite(self, endpoint, data, timeout=0): @@ -1475,6 +1591,10 @@ interface (ex: bytearray) for the "data" parameter. Returns the number of bytes actually sent. + + May raise an exception from the USBError family. USBErrorTimeout + exception has a "transferred" property giving the number of bytes sent + up to the timeout. """ # pylint: disable=undefined-variable endpoint = (endpoint & ~ENDPOINT_DIR_MASK) | ENDPOINT_OUT @@ -1487,18 +1607,31 @@ Synchronous interrupt write. timeout: in milliseconds, how long to wait for data. Set to 0 to disable. - See interruptRead for other parameters description. + See interruptWrite for other parameters description. To avoid memory copies, use an object implementing the writeable buffer interface (ex: bytearray) for the "data" parameter. Returns received data. + + May raise an exception from the USBError family. USBErrorTimeout + exception has a "received" property giving the bytes received up to the + timeout. """ # pylint: disable=undefined-variable endpoint = (endpoint & ~ENDPOINT_DIR_MASK) | ENDPOINT_IN # pylint: enable=undefined-variable data, data_buffer = create_binary_buffer(length) - transferred = self._interruptTransfer(endpoint, data, length, timeout) + try: + transferred = self._interruptTransfer( + endpoint, + data, + length, + timeout, + ) + except USBErrorTimeout as exception: + exception.received = data_buffer[:exception.transferred] + raise return data_buffer[:transferred] def getTransfer(self, iso_packets=0): @@ -1720,6 +1853,10 @@ class USBDevice(object): """ Represents a USB device. + + Exposes USB descriptors which are available from OS without needing to get + a USBDeviceHandle: device descriptor, configuration descriptors, interface + descriptors, setting descritptors, endpoint descriptors. """ __configuration_descriptor_list = () @@ -1942,39 +2079,57 @@ def getSupportedLanguageList(self): """ Get the list of language ids device has string descriptors for. + Note: opens the device temporarily and uses synchronous API. """ return self.open().getSupportedLanguageList() - def _getStringDescriptor(self, descriptor, lang_id): - if descriptor: - return self.open().getStringDescriptor(descriptor, lang_id) - - def _getASCIIStringDescriptor(self, descriptor): - if descriptor: - return self.open().getASCIIStringDescriptor(descriptor) - def getManufacturer(self): """ Get device's manufaturer name. - Note: opens the device temporarily. + + Shortcut for .open().getManufacturer() . """ - return self._getASCIIStringDescriptor( - self.device_descriptor.iManufacturer) + return self.open().getManufacturer() + + def getManufacturerDescriptor(self): + """ + Get the string index of device's manufacturer. + You can pass this value to USBHandle.getASCIIStringDescriptor to get + the actual manufacturer string. + """ + return self.device_descriptor.iManufacturer def getProduct(self): """ Get device's product name. - Note: opens the device temporarily. + + Shortcut for .open().getProduct() . + """ + return self.open().getProduct() + + def getProductDescriptor(self): + """ + Get the string index of device's product name. + You can pass this value to USBHandle.getASCIIStringDescriptor to get + the actual product name string. """ - return self._getASCIIStringDescriptor(self.device_descriptor.iProduct) + return self.device_descriptor.iProduct def getSerialNumber(self): """ Get device's serial number. - Note: opens the device temporarily. + + Shortcut for .open().getSerialNumber() . + """ + return self.open().getSerialNumber() + + def getSerialNumberDescriptor(self): """ - return self._getASCIIStringDescriptor( - self.device_descriptor.iSerialNumber) + Get the string index of device's serial number. + You can pass this value to USBHandle.getASCIIStringDescriptor to get + the actual serial number string. + """ + return self.device_descriptor.iSerialNumber def getNumConfigurations(self): """ @@ -2022,8 +2177,9 @@ __removed_cb = None __poll_cb_user_data = None __libusb_set_pollfd_notifiers = libusb1.libusb_set_pollfd_notifiers - __null_pointer = POINTER(None) + __null_pointer = c_void_p() __KeyError = KeyError + __cast = staticmethod(cast) __auto_open = True # pylint: disable=no-self-argument,protected-access @@ -2321,7 +2477,11 @@ self.__removed_cb = removed_cb self.__poll_cb_user_data = user_data self.__libusb_set_pollfd_notifiers( - self.__context_p, added_cb, removed_cb, user_data) + self.__context_p, + self.__cast(added_cb, libusb1.libusb_pollfd_added_cb_p), + self.__cast(removed_cb, libusb1.libusb_pollfd_removed_cb_p), + user_data, + ) @_validContext def getNextTimeout(self): @@ -2451,6 +2611,9 @@ HOTPLUG_EVENT_DEVICE_LEFT Callback must return whether it must be unregistered (any true value to be unregistered, any false value to be kept registered). + + Note: given callback will be invoked during event handling, meaning + it cannot call any synchronous libusb function. """ def wrapped_callback(context_p, device_p, event, _): assert addressof(context_p.contents) == addressof( diff -Nru python-libusb1-1.6.3/usb1/libusb1.py python-libusb1-1.7/usb1/libusb1.py --- python-libusb1-1.6.3/usb1/libusb1.py 2017-01-25 10:32:55.000000000 +0000 +++ python-libusb1-1.7/usb1/libusb1.py 2018-12-13 23:44:20.000000000 +0000 @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2016 Vincent Pelletier +# Copyright (C) 2010-2018 Vincent Pelletier # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff -Nru python-libusb1-1.6.3/usb1/testUSB1.py python-libusb1-1.7/usb1/testUSB1.py --- python-libusb1-1.6.3/usb1/testUSB1.py 2017-01-25 10:32:55.000000000 +0000 +++ python-libusb1-1.7/usb1/testUSB1.py 2018-12-13 23:44:20.000000000 +0000 @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2016 Vincent Pelletier +# Copyright (C) 2010-2018 Vincent Pelletier # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public