2020# This file is uitilies for Weave BLE
2121#
2222
23+ from __future__ import absolute_import
24+ from __future__ import print_function
2325import binascii
2426import logging
2527from ctypes import *
28+ import six
2629
2730
2831# Duplicates of BLE definitions in WeaveDeviceManager-ScriptBinding.cpp
@@ -54,7 +57,7 @@ def _VoidPtrToUUIDString(ptr, len):
5457 ptr = ptr [:8 ] + '-' + ptr [8 :12 ] + '-' + ptr [12 :16 ] + '-' + ptr [16 :20 ] + '-' + ptr [20 :]
5558 ptr = str (ptr )
5659 except :
57- print "ERROR: failed to convert void * to UUID"
60+ print ( "ERROR: failed to convert void * to UUID" )
5861 ptr = None
5962
6063 return ptr
@@ -74,7 +77,7 @@ def _ByteArrayToVoidPtr(array):
7477 return c_void_p (0 )
7578
7679def ParseBleEventType (val ):
77- if isinstance (val , ( int , long ) ):
80+ if isinstance (val , six . integer_types ):
7881 return val
7982 if (val .lower () == "rx" ):
8083 return BleEventType_Rx
@@ -92,16 +95,16 @@ def __init__(self, svcId=None, charId=None, status=False):
9295 self .Status = status
9396
9497 def Print (self , prefix = "" ):
95- print "%sBleEvent Type: %s" % (prefix , ("TX" if self .EventType == BleEventType_Tx else "ERROR" ))
96- print "%sStatus: %s" % (prefix , str (self .Status ))
98+ print ( "%sBleEvent Type: %s" % (prefix , ("TX" if self .EventType == BleEventType_Tx else "ERROR" ) ))
99+ print ( "%sStatus: %s" % (prefix , str (self .Status ) ))
97100
98101 if self .SvcId :
99- print "%sSvcId:" % (prefix )
100- print binascii .hexlify (self .SvcId )
102+ print ( "%sSvcId:" % (prefix ) )
103+ print ( binascii .hexlify (self .SvcId ) )
101104
102105 if self .CharId :
103- print "%sCharId:" % (prefix )
104- print binascii .hexlify (self .CharId )
106+ print ( "%sCharId:" % (prefix ) )
107+ print ( binascii .hexlify (self .CharId ) )
105108
106109 def SetField (self , name , val ):
107110 name = name .lower ()
@@ -123,8 +126,8 @@ def __init__(self, error=0):
123126 self .Error = error
124127
125128 def Print (self , prefix = "" ):
126- print "%sBleEvent Type: %s" % (prefix , ("DC" if self .EventType == BleEventType_Disconnect else "ERROR" ))
127- print "%sError: %s" % (prefix , str (self .Error ))
129+ print ( "%sBleEvent Type: %s" % (prefix , ("DC" if self .EventType == BleEventType_Disconnect else "ERROR" ) ))
130+ print ( "%sError: %s" % (prefix , str (self .Error ) ))
128131
129132 def SetField (self , name , val ):
130133 name = name .lower ()
@@ -144,18 +147,18 @@ def __init__(self, svcId=None, charId=None, buffer=None):
144147 self .Buffer = buffer
145148
146149 def Print (self , prefix = "" ):
147- print "%sBleEvent Type: %s" % (prefix , ("RX" if self .EventType == BleEventType_Rx else "ERROR" ))
150+ print ( "%sBleEvent Type: %s" % (prefix , ("RX" if self .EventType == BleEventType_Rx else "ERROR" ) ))
148151 if self .Buffer :
149- print "%sBuffer:" % (prefix )
150- print binascii .hexlify (self .Buffer )
152+ print ( "%sBuffer:" % (prefix ) )
153+ print ( binascii .hexlify (self .Buffer ) )
151154
152155 if self .SvcId :
153- print "%sSvcId:" % (prefix )
154- print binascii .hexlify (self .SvcId )
156+ print ( "%sSvcId:" % (prefix ) )
157+ print ( binascii .hexlify (self .SvcId ) )
155158
156159 if self .CharId :
157- print "%sCharId:" % (prefix )
158- print binascii .hexlify (self .CharId )
160+ print ( "%sCharId:" % (prefix ) )
161+ print ( binascii .hexlify (self .CharId ) )
159162
160163 def SetField (self , name , val ):
161164 name = name .lower ()
@@ -180,17 +183,17 @@ def __init__(self, svcId=None, charId=None, status=True, operation=BleSubscribe
180183 self .Operation = operation
181184
182185 def Print (self , prefix = "" ):
183- print "%sBleEvent Type: %s" % (prefix , ("SUBSCRIBE" if self .EventType == BleEventType_Subscribe else "ERROR" ))
184- print "%sStatus: %s" % (prefix , str (self .Status ))
185- print "%sOperation: %s" % (prefix , ("UNSUBSCRIBE" if self .Operation == BleSubscribeOperation_Unsubscribe else "SUBSCRIBE" ))
186+ print ( "%sBleEvent Type: %s" % (prefix , ("SUBSCRIBE" if self .EventType == BleEventType_Subscribe else "ERROR" ) ))
187+ print ( "%sStatus: %s" % (prefix , str (self .Status ) ))
188+ print ( "%sOperation: %s" % (prefix , ("UNSUBSCRIBE" if self .Operation == BleSubscribeOperation_Unsubscribe else "SUBSCRIBE" ) ))
186189
187190 if self .SvcId :
188- print "%sSvcId:" % (prefix )
189- print binascii .hexlify (self .SvcId )
191+ print ( "%sSvcId:" % (prefix ) )
192+ print ( binascii .hexlify (self .SvcId ) )
190193
191194 if self .CharId :
192- print "%sCharId:" % (prefix )
193- print binascii .hexlify (self .CharId )
195+ print ( "%sCharId:" % (prefix ) )
196+ print ( binascii .hexlify (self .CharId ) )
194197
195198 def SetField (self , name , val ):
196199 name = name .lower ()
0 commit comments