libusb 1.0.26rc4__zip → 1.0.27.post1__zip

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/.readthedocs.yml +1 -1
  2. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/CHANGES.rst +23 -0
  3. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/MANIFEST.in +1 -2
  4. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/PKG-INFO +38 -13
  5. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/README.rst +2 -1
  6. libusb-1.0.27.post1/examples/_win32.py +149 -0
  7. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/examples/dpfp.py +19 -13
  8. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/examples/dpfp_threaded.py +1 -2
  9. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/examples/ezusb.py +10 -9
  10. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/examples/fxload.py +13 -8
  11. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/examples/hotplugtest.py +28 -15
  12. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/examples/listdevs.py +4 -3
  13. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/examples/sam3u_benchmark.py +11 -4
  14. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/examples/testlibusb.py +7 -4
  15. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/examples/xusb.py +152 -77
  16. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/pyproject.toml +34 -34
  17. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/__about__.py +1 -2
  18. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/__init__.py +1 -2
  19. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_config.py +1 -2
  20. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_dll.py +1 -2
  21. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_libusb.py +852 -611
  22. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_platform/__init__.py +1 -2
  23. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_platform/_linux/__init__.py +1 -2
  24. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_platform/_macos/__init__.py +1 -2
  25. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_platform/_windows/__init__.py +1 -2
  26. libusb-1.0.27.post1/src/libusb/_platform/_windows/x64/libusb-1.0.dll +0 -0
  27. libusb-1.0.27.post1/src/libusb/_platform/_windows/x86/libusb-1.0.dll +0 -0
  28. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb.egg-info/PKG-INFO +38 -13
  29. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb.egg-info/SOURCES.txt +6 -1
  30. libusb-1.0.27.post1/src/libusb.egg-info/requires.txt +16 -0
  31. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/tests/__init__.py +1 -2
  32. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/tests/__main__.py +1 -2
  33. libusb-1.0.27.post1/tests/_win32.py +149 -0
  34. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/tests/test_main.py +1 -2
  35. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/tests/testlib.py +99 -4
  36. libusb-1.0.27.post1/tests/tman_init_context.py +105 -0
  37. libusb-1.0.27.post1/tests/tman_set_option.py +215 -0
  38. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/tests/tman_stress.py +35 -20
  39. libusb-1.0.27.post1/tests/tman_stress_mt.py +300 -0
  40. libusb-1.0.27.post1/tests/umockdev.py_ +1147 -0
  41. libusb-1.0.26rc4/examples/win32.py +0 -73
  42. libusb-1.0.26rc4/src/libusb/_platform/_windows/x64/libusb-1.0.dll +0 -0
  43. libusb-1.0.26rc4/src/libusb/_platform/_windows/x86/libusb-1.0.dll +0 -0
  44. libusb-1.0.26rc4/src/libusb.egg-info/requires.txt +0 -16
  45. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/LICENSE +0 -0
  46. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/docs/CHANGES.rst +0 -0
  47. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/docs/README.rst +0 -0
  48. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/docs/_static/libusb.png +0 -0
  49. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/docs/_templates/.keep +0 -0
  50. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/docs/conf.py +0 -0
  51. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/docs/index.rst +0 -0
  52. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/setup.cfg +0 -0
  53. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/__config__.py +0 -0
  54. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_platform/_linux/aarch64/libusb-1.0.so +0 -0
  55. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_platform/_linux/x64/libusb-1.0.so +0 -0
  56. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_platform/_linux/x86/libusb-1.0.so +0 -0
  57. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_platform/_macos/x64/10.7/libusb-1.0.0.dylib +0 -0
  58. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_platform/_macos/x64/11.6/libusb-1.0.0.dylib +0 -0
  59. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/_platform/_macos/x86/.keep +0 -0
  60. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb/libusb.cfg +0 -0
  61. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb.egg-info/dependency_links.txt +0 -0
  62. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb.egg-info/not-zip-safe +0 -0
  63. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/src/libusb.egg-info/top_level.txt +0 -0
  64. {libusb-1.0.26rc4 → libusb-1.0.27.post1}/tests/data/.keep +0 -0
@@ -2,7 +2,7 @@ version: 2
2
2
  build:
3
3
  os: "ubuntu-22.04"
4
4
  tools:
5
- python: "3.11"
5
+ python: "3.12"
6
6
  python:
7
7
  install:
8
8
  - method: pip
@@ -1,6 +1,29 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 1.0.27.post1 (2024-08-13)
5
+ -------------------------
6
+ - Add support for Python 3.13
7
+ - Setup (dependencies) update.
8
+ - Improvements and cleanup for win32.
9
+ - Source code refactoring and cleanup.
10
+
11
+ 1.0.27 (2024-02-05)
12
+ -------------------
13
+ - | The API has been fully updated to version 1.0.27 (libusb v.1.0.27
14
+ | is fully backward compatible with v.1.0.26).
15
+ - | For Windows the shared library binaries have been updated to version
16
+ | 1.0.27. For Linux and macOS, the shared library binaries remain at
17
+ | version 1.0.26.
18
+ - Bugfixes for options -i and -w in examples/xusb.py
19
+
20
+ 1.0.26 (2024-02-05)
21
+ -------------------
22
+ - | The API has been partially updated to version 1.0.27, but still
23
+ | only supports version 1.0.26.
24
+ - Improvements and some little bugfixes.
25
+ - Examples and tests are upgraded to 1.0.27.
26
+
4
27
  1.0.26rc4 (2024-01-25)
5
28
  ----------------------
6
29
  - Setup update (now based on tox >= 4.0).
@@ -1,6 +1,5 @@
1
1
  # Copyright (c) 2016 Adam Karpierz
2
- # Licensed under the zlib/libpng License
3
- # https://opensource.org/license/zlib
2
+ # SPDX-License-Identifier: Zlib
4
3
 
5
4
  include README.rst
6
5
  include CHANGES.rst
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libusb
3
- Version: 1.0.26rc4
3
+ Version: 1.0.27.post1
4
4
  Summary: Python binding for the libusb C library.
5
5
  Author: Adam Karpierz
6
6
  Author-email: adam@karpierz.net
@@ -26,27 +26,28 @@ Classifier: Programming Language :: Python :: 3.9
26
26
  Classifier: Programming Language :: Python :: 3.10
27
27
  Classifier: Programming Language :: Python :: 3.11
28
28
  Classifier: Programming Language :: Python :: 3.12
29
+ Classifier: Programming Language :: Python :: 3.13
29
30
  Classifier: Programming Language :: Python :: 3 :: Only
30
31
  Classifier: Programming Language :: Python :: Implementation :: CPython
31
32
  Classifier: Programming Language :: Python :: Implementation :: PyPy
32
33
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
33
- Requires-Python: <4.0.0,>=3.8.1
34
+ Requires-Python: <4.0.0,>=3.8.10
34
35
  Description-Content-Type: text/x-rst; charset=UTF-8
35
36
  License-File: LICENSE
36
- Requires-Dist: setuptools>=68.2.2
37
- Requires-Dist: pkg-about>=1.1.5
37
+ Requires-Dist: setuptools>=72.2.0
38
+ Requires-Dist: pkg-about>=1.1.8
38
39
  Provides-Extra: doc
39
40
  Requires-Dist: Sphinx>=7.1.2; extra == "doc"
40
- Requires-Dist: sphinx-toolbox>=3.5.0; extra == "doc"
41
- Requires-Dist: sphinx-tabs>=3.4.1; extra == "doc"
42
- Requires-Dist: sphinx-copybutton>=0.5.1; extra == "doc"
43
- Requires-Dist: sphinxcontrib-spelling>=7.7.0; extra == "doc"
44
- Requires-Dist: sphinx-lint>=0.6.7; extra == "doc"
41
+ Requires-Dist: sphinx-toolbox>=3.7.0; extra == "doc"
42
+ Requires-Dist: sphinx-tabs>=3.4.5; extra == "doc"
43
+ Requires-Dist: sphinx-copybutton>=0.5.2; extra == "doc"
44
+ Requires-Dist: sphinxcontrib-spelling>=8.0.0; extra == "doc"
45
+ Requires-Dist: sphinx-lint>=0.9.1; extra == "doc"
45
46
  Requires-Dist: restructuredtext-lint>=1.4.0; extra == "doc"
46
- Requires-Dist: nbsphinx>=0.8.10; extra == "doc"
47
+ Requires-Dist: nbsphinx>=0.9.4; extra == "doc"
47
48
  Provides-Extra: test
48
- Requires-Dist: deepdiff>=6.7.1; extra == "test"
49
- Requires-Dist: rich>=13.7.0; extra == "test"
49
+ Requires-Dist: deepdiff>=7.0.1; extra == "test"
50
+ Requires-Dist: rich>=13.7.1; extra == "test"
50
51
 
51
52
  libusb
52
53
  ======
@@ -128,7 +129,7 @@ Prerequisites:
128
129
  + Python 3.8 or higher
129
130
 
130
131
  * https://www.python.org/
131
- * with C libusb 1.0.26 is a primary test environment.
132
+ * with C libusb 1.0.27 is a primary test environment.
132
133
 
133
134
  + pip and setuptools
134
135
 
@@ -191,10 +192,34 @@ Authors
191
192
  .. _Development page: https://github.com/karpierz/libusb
192
193
  .. _PyPI record: https://pypi.org/project/libusb/
193
194
  .. _Documentation: https://libusb.readthedocs.io/
195
+ .. _USB Vendors: https://devicehunt.com/all-usb-vendors
194
196
 
195
197
  Changelog
196
198
  =========
197
199
 
200
+ 1.0.27.post1 (2024-08-13)
201
+ -------------------------
202
+ - Add support for Python 3.13
203
+ - Setup (dependencies) update.
204
+ - Improvements and cleanup for win32.
205
+ - Source code refactoring and cleanup.
206
+
207
+ 1.0.27 (2024-02-05)
208
+ -------------------
209
+ - | The API has been fully updated to version 1.0.27 (libusb v.1.0.27
210
+ | is fully backward compatible with v.1.0.26).
211
+ - | For Windows the shared library binaries have been updated to version
212
+ | 1.0.27. For Linux and macOS, the shared library binaries remain at
213
+ | version 1.0.26.
214
+ - Bugfixes for options -i and -w in examples/xusb.py
215
+
216
+ 1.0.26 (2024-02-05)
217
+ -------------------
218
+ - | The API has been partially updated to version 1.0.27, but still
219
+ | only supports version 1.0.26.
220
+ - Improvements and some little bugfixes.
221
+ - Examples and tests are upgraded to 1.0.27.
222
+
198
223
  1.0.26rc4 (2024-01-25)
199
224
  ----------------------
200
225
  - Setup update (now based on tox >= 4.0).
@@ -78,7 +78,7 @@ Prerequisites:
78
78
  + Python 3.8 or higher
79
79
 
80
80
  * https://www.python.org/
81
- * with C libusb 1.0.26 is a primary test environment.
81
+ * with C libusb 1.0.27 is a primary test environment.
82
82
 
83
83
  + pip and setuptools
84
84
 
@@ -141,3 +141,4 @@ Authors
141
141
  .. _Development page: https://github.com/karpierz/libusb
142
142
  .. _PyPI record: https://pypi.org/project/libusb/
143
143
  .. _Documentation: https://libusb.readthedocs.io/
144
+ .. _USB Vendors: https://devicehunt.com/all-usb-vendors
@@ -0,0 +1,149 @@
1
+ # Copyright (c) 2013 Adam Karpierz
2
+ # SPDX-License-Identifier: Zlib
3
+
4
+ import ctypes
5
+ from ctypes import windll
6
+ from ctypes import wintypes
7
+ from ctypes import WINFUNCTYPE
8
+ from ctypes.wintypes import (
9
+ CHAR, WCHAR, BOOLEAN, BOOL, BYTE, WORD, DWORD, SHORT, USHORT, INT,
10
+ UINT, LONG, ULONG, LARGE_INTEGER, ULARGE_INTEGER, FLOAT, DOUBLE,
11
+ LPBYTE, PBYTE, LPWORD, PWORD, LPDWORD, PDWORD, LPLONG, PLONG, LPSTR,
12
+ LPCSTR, LPVOID, LPCVOID, LPVOID as PVOID, HANDLE, LPHANDLE, PHANDLE,
13
+ WPARAM, LPARAM, FILETIME, LPFILETIME,
14
+ )
15
+
16
+ from ctypes.wintypes import WPARAM as ULONG_PTR # workaround
17
+ PULONG_PTR = ctypes.POINTER(ULONG_PTR)
18
+
19
+ ULONG32 = ctypes.c_uint32
20
+ ULONGLONG = ctypes.c_uint64
21
+ DWORDLONG = ctypes.c_uint64
22
+ SIZE_T = ctypes.c_size_t
23
+
24
+ WAIT_ABANDONED = 0x00000080
25
+ WAIT_OBJECT_0 = 0x00000000
26
+ WAIT_TIMEOUT = 0x00000102
27
+ WAIT_FAILED = 0xFFFFFFFF
28
+
29
+ IGNORE = 0
30
+ INFINITE = 0xFFFFFFFF
31
+
32
+ FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100
33
+ FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000
34
+ FORMAT_MESSAGE_FROM_HMODULE = 0x00000800
35
+ FORMAT_MESSAGE_FROM_STRING = 0x00000400
36
+ FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
37
+ FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
38
+ FORMAT_MESSAGE_MAX_WIDTH_MASK = 0x000000FF
39
+
40
+ GetCurrentProcess = windll.kernel32.GetCurrentProcess
41
+ GetCurrentProcess.restype = HANDLE
42
+ GetCurrentProcess.argtypes = []
43
+
44
+ GetProcessTimes = windll.kernel32.GetProcessTimes
45
+ GetProcessTimes.restype = BOOL
46
+ GetProcessTimes.argtypes = [HANDLE,
47
+ LPFILETIME,
48
+ LPFILETIME,
49
+ LPFILETIME,
50
+ LPFILETIME]
51
+
52
+ class SECURITY_ATTRIBUTES(ctypes.Structure):
53
+ _fields_ = [
54
+ ("nLength", DWORD),
55
+ ("lpSecurityDescriptor", LPVOID),
56
+ ("bInheritHandle", BOOL),
57
+ ]
58
+ LPSECURITY_ATTRIBUTES = ctypes.POINTER(SECURITY_ATTRIBUTES)
59
+
60
+ LPTHREAD_START_ROUTINE = WINFUNCTYPE(DWORD, LPVOID)
61
+ CreateThread = windll.kernel32.CreateThread
62
+ CreateThread.restype = HANDLE
63
+ CreateThread.argtypes = [LPSECURITY_ATTRIBUTES,
64
+ SIZE_T,
65
+ LPTHREAD_START_ROUTINE,
66
+ LPVOID,
67
+ DWORD,
68
+ LPDWORD]
69
+
70
+ WaitForSingleObject = windll.kernel32.WaitForSingleObject
71
+ WaitForSingleObject.restype = DWORD
72
+ WaitForSingleObject.argtypes = [HANDLE,
73
+ DWORD]
74
+
75
+ SetEvent = windll.kernel32.SetEvent
76
+ SetEvent.restype = BOOL
77
+ SetEvent.argtypes = [HANDLE]
78
+
79
+ CreateSemaphore = windll.kernel32.CreateSemaphoreA
80
+ CreateSemaphore.restype = HANDLE
81
+ CreateSemaphore.argtypes = [LPSECURITY_ATTRIBUTES,
82
+ LONG,
83
+ LONG,
84
+ LPCSTR]
85
+
86
+ ReleaseSemaphore = windll.kernel32.ReleaseSemaphore
87
+ ReleaseSemaphore.restype = BOOL
88
+ ReleaseSemaphore.argtypes = [HANDLE,
89
+ LONG,
90
+ LPLONG]
91
+
92
+ Sleep = windll.kernel32.Sleep
93
+ Sleep.restype = None
94
+ Sleep.argtypes = [DWORD]
95
+
96
+ PHANDLER_ROUTINE = WINFUNCTYPE(BOOL, DWORD)
97
+ SetConsoleCtrlHandler = windll.kernel32.SetConsoleCtrlHandler
98
+ SetConsoleCtrlHandler.restype = BOOL
99
+ SetConsoleCtrlHandler.argtypes = [PHANDLER_ROUTINE,
100
+ BOOL]
101
+
102
+ CloseHandle = windll.kernel32.CloseHandle
103
+ CloseHandle.restype = BOOL
104
+ CloseHandle.argtypes = [HANDLE]
105
+
106
+ GetLastError = windll.kernel32.GetLastError
107
+ GetLastError.restype = DWORD
108
+ GetLastError.argtypes = []
109
+
110
+ FormatMessageA = windll.kernel32.FormatMessageA
111
+ FormatMessageA.restype = DWORD
112
+ FormatMessageA.argtypes = [DWORD,
113
+ LPCVOID,
114
+ DWORD,
115
+ DWORD,
116
+ LPSTR,
117
+ DWORD,
118
+ LPVOID]
119
+
120
+ class SYSTEMTIME(ctypes.Structure):
121
+ _fields_ = [
122
+ ("wYear", WORD),
123
+ ("wMonth", WORD),
124
+ ("wDayOfWeek", WORD),
125
+ ("wDay", WORD),
126
+ ("wHour", WORD),
127
+ ("wMinute", WORD),
128
+ ("wSecond", WORD),
129
+ ("wMilliseconds", WORD),
130
+ ]
131
+ LPSYSTEMTIME = ctypes.POINTER(SYSTEMTIME)
132
+
133
+ GetLocalTime = windll.kernel32.GetLocalTime
134
+ GetLocalTime.restype = None
135
+ GetLocalTime.argtypes = [LPSYSTEMTIME]
136
+
137
+ SetLocalTime = windll.kernel32.SetLocalTime
138
+ SetLocalTime.restype = BOOL
139
+ SetLocalTime.argtypes = [LPSYSTEMTIME]
140
+
141
+ GetSystemTime = windll.kernel32.GetSystemTime
142
+ GetSystemTime.restype = None
143
+ GetSystemTime.argtypes = [LPSYSTEMTIME]
144
+
145
+ SetSystemTime = windll.kernel32.SetSystemTime
146
+ SetSystemTime.restype = BOOL
147
+ SetSystemTime.argtypes = [LPSYSTEMTIME]
148
+
149
+ del ctypes
@@ -1,6 +1,5 @@
1
1
  # Copyright (c) 2016 Adam Karpierz
2
- # Licensed under the zlib/libpng License
3
- # https://opensource.org/license/zlib
2
+ # SPDX-License-Identifier: Zlib
4
3
 
5
4
  # libusb example program to manipulate U.are.U 4000B fingerprint scanner.
6
5
  # Copyright © 2007 Daniel Drake <dsd@gentoo.org>
@@ -32,19 +31,21 @@ import ctypes as ct
32
31
 
33
32
  import libusb as usb
34
33
  from libusb._platform import defined, is_posix, is_windows
35
- if is_windows: import win32
34
+ if is_windows: import _win32 as win32
35
+
36
+ usb_strerror = lambda r: usb.strerror(r).decode("utf-8")
36
37
 
37
38
  if defined("DPFP_THREADED"):
38
39
 
39
40
  if is_posix:
40
41
 
41
- THREAD_RETURN_VALUE = NULL
42
42
  semaphore_t = ct.POINTER(sem_t)
43
43
  thread_t = pthread_t
44
44
  thread_return_t = ct.c_void_p
45
+ THREAD_RETURN_VALUE = NULL
45
46
 
46
47
  def semaphore_create() -> semaphore_t:
47
- name = "/org.libusb.example.dpfp_threaded:%d" % int(getpid())
48
+ name = "/org.libusb.example.dpfp_threaded:{:d}".format(int(getpid()))
48
49
  semaphore: semaphore_t = sem_open(name, O_CREAT | O_EXCL, 0, 0)
49
50
  if semaphore == SEM_FAILED:
50
51
  return NULL;
@@ -61,7 +62,7 @@ if defined("DPFP_THREADED"):
61
62
  def semaphore_destroy(semaphore: semaphore_t):
62
63
  sem_close(semaphore)
63
64
 
64
- # void *(*thread_entry)(arg: ct.c_void_p)
65
+ # thread_return_t (*thread_entry)(arg: ct.c_void_p)
65
66
  def thread_create(thread: ct.POINTER(thread_t),
66
67
  thread_entry,
67
68
  arg: ct.c_void_p) -> int:
@@ -73,7 +74,6 @@ if defined("DPFP_THREADED"):
73
74
 
74
75
  elif is_windows:
75
76
 
76
- THREAD_RETURN_VALUE = 0
77
77
  semaphore_t = win32.HANDLE
78
78
  thread_t = win32.HANDLE
79
79
  if defined("__CYGWIN__"):
@@ -81,6 +81,7 @@ if defined("DPFP_THREADED"):
81
81
  else:
82
82
  #thread_return_t = ct.c_uint
83
83
  thread_return_t = win32.DWORD
84
+ THREAD_RETURN_VALUE = 0
84
85
 
85
86
  def semaphore_create() -> semaphore_t:
86
87
  return win32.CreateSemaphore(None, 0, 1, None)
@@ -543,7 +544,6 @@ def alloc_transfers() -> int:
543
544
 
544
545
  #static
545
546
  def sighandler(signum, frame):
546
-
547
547
  request_exit(1)
548
548
 
549
549
 
@@ -571,9 +571,12 @@ def main(argv=sys.argv[1:]):
571
571
  global irq_transfer
572
572
  global do_exit
573
573
 
574
- r = usb.init(None)
574
+ r = (usb.init_context(None, None, 0)
575
+ if hasattr(usb, "init_context") else
576
+ usb.init(None))
575
577
  if r < 0:
576
- print("failed to initialise libusb {} - {}".format(r, usb.strerror(r)), file=sys.stderr)
578
+ print("failed to initialise libusb {} - {}".format(r, usb_strerror(r)),
579
+ file=sys.stderr)
577
580
  sys.exit(1)
578
581
 
579
582
  r = find_dpfp_device()
@@ -584,7 +587,8 @@ def main(argv=sys.argv[1:]):
584
587
 
585
588
  r = usb.claim_interface(devh, 0)
586
589
  if r < 0:
587
- print("claim interface error {} - {}".format(r, usb.strerror(r)), file=sys.stderr)
590
+ print("claim interface error {} - {}".format(r, usb_strerror(r)),
591
+ file=sys.stderr)
588
592
  return abs(r)
589
593
  print("claimed interface")
590
594
 
@@ -642,12 +646,14 @@ def main(argv=sys.argv[1:]):
642
646
  if img_transfer:
643
647
  r = usb.cancel_transfer(img_transfer)
644
648
  if r < 0:
645
- print("failed to cancel transfer {} - {}".format(r, usb.strerror(r)), file=sys.stderr)
649
+ print("failed to cancel transfer {} - {}".format(r, usb_strerror(r)),
650
+ file=sys.stderr)
646
651
 
647
652
  if irq_transfer:
648
653
  r = usb.cancel_transfer(irq_transfer)
649
654
  if r < 0:
650
- print("failed to cancel transfer {} - {}".format(r, usb.strerror(r)), file=sys.stderr)
655
+ print("failed to cancel transfer {} - {}".format(r, usb_strerror(r)),
656
+ file=sys.stderr)
651
657
 
652
658
  while img_transfer or irq_transfer:
653
659
  if usb.handle_events(None) < 0:
@@ -1,6 +1,5 @@
1
1
  # Copyright (c) 2016 Adam Karpierz
2
- # Licensed under the zlib/libpng License
3
- # https://opensource.org/license/zlib
2
+ # SPDX-License-Identifier: Zlib
4
3
 
5
4
  # libusb example program to manipulate U.are.U 4000B fingerprint scanner.
6
5
  # Copyright © 2007 Daniel Drake <dsd@gentoo.org>
@@ -1,6 +1,5 @@
1
1
  # Copyright (c) 2016 Adam Karpierz
2
- # Licensed under the zlib/libpng License
3
- # https://opensource.org/license/zlib
2
+ # SPDX-License-Identifier: Zlib
4
3
 
5
4
  # Copyright © 2001 Stephen Williams (steve@icarus.com)
6
5
  # Copyright © 2001-2002 David Brownell (dbrownell@users.sourceforge.net)
@@ -29,6 +28,8 @@ import ctypes as ct
29
28
 
30
29
  import libusb as usb
31
30
 
31
+ usb_error_name = lambda status: usb.error_name(status).decode("utf-8")
32
+
32
33
  FX_TYPE_UNDEFINED = -1
33
34
  FX_TYPE_AN21 = 0 # Original AnchorChips parts
34
35
  FX_TYPE_FX1 = 1 # Updated Cypress versions
@@ -170,7 +171,7 @@ def ezusb_write(device, label, opcode, addr, data, size) -> int:
170
171
  global verbose
171
172
 
172
173
  if verbose > 1:
173
- logerror("{}, addr {:#010x} len %4u ({:#06x})\n",
174
+ logerror("{}, addr {:#010x} len {:4d} ({:#06x})\n",
174
175
  label, addr, size, size)
175
176
  status = usb.control_transfer(device,
176
177
  usb.LIBUSB_ENDPOINT_OUT |
@@ -183,7 +184,7 @@ def ezusb_write(device, label, opcode, addr, data, size) -> int:
183
184
  1000)
184
185
  if status != ct.c_int(size).value:
185
186
  if status < 0:
186
- logerror("{}: {}\n", label, usb.error_name(status))
187
+ logerror("{}: {}\n", label, usb_error_name(status))
187
188
  else:
188
189
  logerror("{} ==> {}\n", label, status)
189
190
 
@@ -205,7 +206,7 @@ def ezusb_read(device, label, opcode, addr, data, size) -> int:
205
206
  global verbose
206
207
 
207
208
  if verbose > 1:
208
- logerror("{}, addr {:#010x} len %4u ({:#06x})\n",
209
+ logerror("{}, addr {:#010x} len {:4d} ({:#06x})\n",
209
210
  label, addr, size, size)
210
211
  status = usb.control_transfer(device,
211
212
  usb.LIBUSB_ENDPOINT_IN |
@@ -218,7 +219,7 @@ def ezusb_read(device, label, opcode, addr, data, size) -> int:
218
219
  1000)
219
220
  if status != ct.c_int(size).value:
220
221
  if status < 0:
221
- logerror("{}: {}\n", label, usb.error_name(status))
222
+ logerror("{}: {}\n", label, usb_error_name(status))
222
223
  else:
223
224
  logerror("{} ==> {}\n", label, status)
224
225
 
@@ -255,7 +256,7 @@ def ezusb_cpucs(device, addr, do_run: bool) -> bool:
255
256
  (not do_run or status != usb.LIBUSB_ERROR_IO)):
256
257
  mesg = "can't modify CPUCS"
257
258
  if status < 0:
258
- logerror("{}: {}\n", mesg, usb.error_name(status))
259
+ logerror("{}: {}\n", mesg, usb_error_name(status))
259
260
  else:
260
261
  logerror("{}\n", mesg)
261
262
  return False
@@ -287,7 +288,7 @@ def ezusb_fx3_jump(device, addr) -> bool:
287
288
  if status != 0 and status != usb.LIBUSB_ERROR_IO:
288
289
  mesg = "failed to send jump command"
289
290
  if status < 0:
290
- logerror("{}: {}\n", mesg, usb.error_name(status))
291
+ logerror("{}: {}\n", mesg, usb_error_name(status))
291
292
  else:
292
293
  logerror("{}\n", mesg)
293
294
  return False
@@ -396,7 +397,7 @@ def parse_ihex(image, context, is_external, poke) -> int:
396
397
  break;
397
398
 
398
399
  if rec_type != 0:
399
- logerror("unsupported record type: %u\n", rec_type)
400
+ logerror("unsupported record type: {:d}\n", rec_type)
400
401
  return -3
401
402
 
402
403
  if size * 2 + 11 > strlen(buf):
@@ -1,6 +1,5 @@
1
1
  # Copyright (c) 2016 Adam Karpierz
2
- # Licensed under the zlib/libpng License
3
- # https://opensource.org/license/zlib
2
+ # SPDX-License-Identifier: Zlib
4
3
 
5
4
  # Copyright © 2001 Stephen Williams (steve@icarus.com)
6
5
  # Copyright © 2001-2002 David Brownell (dbrownell@users.sourceforge.net)
@@ -35,6 +34,8 @@ from ezusb import FX_KNOWN_DEVICES, FX_TYPE_MAX, FX_TYPE_NAMES, IMG_TYPE_NAMES,
35
34
  from ezusb import ezusb_load_ram
36
35
  from ezusb import verbose
37
36
 
37
+ usb_error_name = lambda status: usb.error_name(status).decode("utf-8")
38
+
38
39
  if not is_windows or defined("__CYGWIN__"):
39
40
  #include <syslog.h>
40
41
  dosyslog = False # bool
@@ -157,9 +158,13 @@ def main(argv=sys.argv[1:]):
157
158
  return print_usage(-1)
158
159
 
159
160
  # open the device using libusb
160
- status = usb.init(None)
161
+ status = (usb.init_context(None, None, 0)
162
+ if hasattr(usb, "init_context") else
163
+ usb.init(None))
161
164
  if status < 0:
162
- logerror("usb.init() failed: {}\n", usb.error_name(status))
165
+ logerror("libusb.init_context() failed: {}\n"
166
+ if hasattr(usb, "init_context") else
167
+ "libusb.init() failed: {}\n", usb_error_name(status))
163
168
  return -1
164
169
 
165
170
  try:
@@ -169,7 +174,7 @@ def main(argv=sys.argv[1:]):
169
174
  if target_type is None or device_id is None or device_path is not None:
170
175
 
171
176
  if usb.get_device_list(None, ct.byref(devs)) < 0:
172
- logerror("libusb.get_device_list() failed: {}\n", usb.error_name(status))
177
+ logerror("libusb.get_device_list() failed: {}\n", usb_error_name(status))
173
178
  return -1
174
179
 
175
180
  i = 0
@@ -224,14 +229,14 @@ def main(argv=sys.argv[1:]):
224
229
  status = usb.open(dev, ct.byref(device))
225
230
  usb.free_device_list(devs, 1)
226
231
  if status < 0:
227
- logerror("usb.open() failed: {}\n", usb.error_name(status))
232
+ logerror("libusb.open() failed: {}\n", usb_error_name(status))
228
233
  return -1
229
234
 
230
235
  elif device_id is not None:
231
236
 
232
237
  device = usb.open_device_with_vid_pid(None, ct.c_uint16(vid), ct.c_uint16(pid))
233
238
  if not device:
234
- logerror("usb.open() failed\n")
239
+ logerror("libusb.open() failed\n")
235
240
  return -1
236
241
 
237
242
  # We need to claim the first interface
@@ -239,7 +244,7 @@ def main(argv=sys.argv[1:]):
239
244
  status = usb.claim_interface(device, 0)
240
245
  if status != usb.LIBUSB_SUCCESS:
241
246
  usb.close(device)
242
- logerror("libusb.claim_interface failed: {}\n", usb.error_name(status))
247
+ logerror("libusb.claim_interface failed: {}\n", usb_error_name(status))
243
248
  return -1
244
249
 
245
250
  if verbose:
@@ -1,6 +1,5 @@
1
1
  # Copyright (c) 2016 Adam Karpierz
2
- # Licensed under the zlib/libpng License
3
- # https://opensource.org/license/zlib
2
+ # SPDX-License-Identifier: Zlib
4
3
 
5
4
  # libusb example program for hotplug API
6
5
  # Copyright © 2012-2013 Nathan Hjelm <hjelmn@mac.com>
@@ -24,6 +23,8 @@ import ctypes as ct
24
23
 
25
24
  import libusb as usb
26
25
 
26
+ usb_strerror = lambda r: usb.strerror(r).decode("utf-8")
27
+
27
28
  handle = ct.POINTER(usb.device_handle)()
28
29
  done = 0
29
30
 
@@ -35,10 +36,12 @@ def hotplug_callback(ctx, dev, event, user_data):
35
36
 
36
37
  desc = usb.device_descriptor()
37
38
  rc = usb.get_device_descriptor(dev, ct.byref(desc))
38
- if rc != usb.LIBUSB_SUCCESS:
39
- print("Error getting device descriptor", file=sys.stderr)
40
-
41
- print("Device attached: {:04x}:{:04x}".format(desc.idVendor, desc.idProduct))
39
+ if rc == usb.LIBUSB_SUCCESS:
40
+ print("Device attached: {:04x}:{:04x}".format(desc.idVendor, desc.idProduct))
41
+ else:
42
+ print("Device attached")
43
+ print("Error getting device descriptor: {}".format(usb_strerror(rc)),
44
+ file=sys.stderr)
42
45
 
43
46
  if handle:
44
47
  usb.close(handle)
@@ -46,7 +49,8 @@ def hotplug_callback(ctx, dev, event, user_data):
46
49
 
47
50
  rc = usb.open(dev, ct.byref(handle))
48
51
  if rc != usb.LIBUSB_SUCCESS:
49
- print("Error opening device", file=sys.stderr)
52
+ print("No access to device: {}".format(usb_strerror(rc)),
53
+ file=sys.stderr)
50
54
 
51
55
  done += 1
52
56
 
@@ -58,7 +62,14 @@ def hotplug_callback_detach(ctx, dev, event, user_data):
58
62
 
59
63
  global handle, done
60
64
 
61
- print("Device detached")
65
+ desc = usb.device_descriptor()
66
+ rc = usb.get_device_descriptor(dev, ct.byref(desc))
67
+ if rc == usb.LIBUSB_SUCCESS:
68
+ print("Device detached: {:04x}:{:04x}".format(desc.idVendor, desc.idProduct))
69
+ else:
70
+ print("Device detached")
71
+ print("Error getting device descriptor: {}".format(usb_strerror(rc)),
72
+ file=sys.stderr)
62
73
 
63
74
  if handle:
64
75
  usb.close(handle)
@@ -75,13 +86,15 @@ def main(argv=sys.argv[1:]):
75
86
 
76
87
  hp = [usb.hotplug_callback_handle() for i in range(2)]
77
88
 
78
- vendor_id = int(argv[0]) if len(argv) > 0 else 0x045a
79
- product_id = int(argv[1]) if len(argv) > 1 else 0x5005
89
+ vendor_id = int(argv[0]) if len(argv) > 0 else usb.LIBUSB_HOTPLUG_MATCH_ANY
90
+ product_id = int(argv[1]) if len(argv) > 1 else usb.LIBUSB_HOTPLUG_MATCH_ANY
80
91
  class_id = int(argv[2]) if len(argv) > 2 else usb.LIBUSB_HOTPLUG_MATCH_ANY
81
92
 
82
- rc = usb.init(None)
83
- if rc < 0:
84
- print("failed to initialise libusb: {}".format(usb.error_name(rc)))
93
+ rc = (usb.init_context(None, None, 0)
94
+ if hasattr(usb, "init_context") else
95
+ usb.init(None))
96
+ if rc != usb.LIBUSB_SUCCESS:
97
+ print("failed to initialise libusb: {}".format(usb_strerror(rc)))
85
98
  return 1
86
99
 
87
100
  try:
@@ -107,8 +120,8 @@ def main(argv=sys.argv[1:]):
107
120
 
108
121
  while done < 2:
109
122
  rc = usb.handle_events(None)
110
- if rc < 0:
111
- print("libusb.handle_events() failed: {}".format(usb.error_name(rc)))
123
+ if rc != usb.LIBUSB_SUCCESS:
124
+ print("libusb.handle_events() failed: {}".format(usb_strerror(rc)))
112
125
  finally:
113
126
  if handle:
114
127
  usb.close(handle)
@@ -1,6 +1,5 @@
1
1
  # Copyright (c) 2016 Adam Karpierz
2
- # Licensed under the zlib/libpng License
3
- # https://opensource.org/license/zlib
2
+ # SPDX-License-Identifier: Zlib
4
3
 
5
4
  # libusb example program to list devices on the bus
6
5
  # Copyright © 2007 Daniel Drake <dsd@gentoo.org>
@@ -54,7 +53,9 @@ def print_devs(devs):
54
53
 
55
54
  def main(argv=sys.argv[1:]):
56
55
 
57
- r = usb.init(None)
56
+ r = (usb.init_context(None, None, 0)
57
+ if hasattr(usb, "init_context") else
58
+ usb.init(None))
58
59
  if r < 0:
59
60
  return r
60
61