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

Commit 849f16c

Browse files
authored
Merge pull request #471 from robszewczyk/bug/python3-support
Python3 compatibility for DeviceManager
2 parents 7b235b2 + 1657a8c commit 849f16c

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)