Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 1657a8c

Browse files
committed
Python3 compatibility for DeviceManager
A few missing bits that made it past the previous changes: * _BytesArrayToVoidPtr operates on `bytes` class rather than on `str` class. In Python 2, `bytes` is merely an alias for `str` so no changes required, in Python3, `bytes` is the binary string returned by various utilities such as `base64.b64decode()` * Wheel packaging changed to reflect that the package is expected to work on Python3.
1 parent 2fbedef commit 1657a8c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/device-manager/python/build-openweave-wheel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ def finalize_options(self):
162162
'License :: OSI Approved :: Apache Software License',
163163
'Programming Language :: Python :: 2',
164164
'Programming Language :: Python :: 2.7',
165+
'Programming Language :: Python :: 3',
165166
],
166-
python_requires='>=2.7, <3',
167+
python_requires='>=2.7',
167168
packages=[
168169
'openweave' # Arrange to install a package named "openweave"
169170
],

src/device-manager/python/openweave/WeaveDeviceMgr.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _VoidPtrToByteArray(ptr, len):
100100

101101
def _ByteArrayToVoidPtr(array):
102102
if array != None:
103-
if not (isinstance(array, str) or isinstance(array, bytearray)):
103+
if not (isinstance(array, bytes) or isinstance(array, bytearray)):
104104
raise TypeError("Array must be an str or a bytearray")
105105
return cast( (c_byte * len(array)) .from_buffer_copy(array), c_void_p)
106106
else:
@@ -853,6 +853,9 @@ def HandlePairTokenComplete(devMgr, reqState, tokenPairingBundlePtr, tokenPairin
853853

854854
cbHandlePairTokenComplete = _PairTokenCompleteFunct(HandlePairTokenComplete)
855855

856+
if pairingToken is not None and isinstance(pairingToken, str):
857+
pairingToken = _StringToCString(pairingToken)
858+
856859
return self._CallDevMgrAsync(
857860
lambda: _dmLib.nl_Weave_DeviceManager_PairToken(self.devMgr, _ByteArrayToVoidPtr(pairingToken), len(pairingToken), cbHandlePairTokenComplete, self.cbHandleError)
858861
)
@@ -1017,6 +1020,12 @@ def RegisterServicePairAccount(self, serviceId, accountId, serviceConfig, pairin
10171020
if accountId is not None and '\x00' in accountId:
10181021
raise ValueError("Unexpected NUL character in accountId")
10191022

1023+
if pairingToken is not None and isinstance(pairingToken, str):
1024+
pairingToken = _StringToCString(pairingToken)
1025+
1026+
if pairingInitData is not None and isinstance(pairingInitData, str):
1027+
pairingInitData = _StringToCString(pairingInitData)
1028+
10201029
self._CallDevMgrAsync(
10211030
lambda: _dmLib.nl_Weave_DeviceManager_RegisterServicePairAccount(self.devMgr, serviceId, _StringToCString(accountId),
10221031
_ByteArrayToVoidPtr(serviceConfig), len(serviceConfig),

0 commit comments

Comments
 (0)