66
77
88class WaitTimeoutError (Exception ):
9- pass
9+ """ Exception used when waiting times out"""
1010
1111
1212def _perf_clock ():
1313 """Provides high resolution timing in seconds"""
14+ import time
1415 if hasattr (time , 'perf_counter' ):
1516 return time .perf_counter () # pylint: disable=no-member
1617 if hasattr (time , 'clock' ):
@@ -27,6 +28,20 @@ def _addon_id():
2728 return getattr (_addon_id , 'cached' )
2829
2930
31+ def _to_unicode (text , encoding = 'utf-8' , errors = 'strict' ):
32+ """Force text to unicode"""
33+ if isinstance (text , bytes ):
34+ return text .decode (encoding , errors = errors )
35+ return text
36+
37+
38+ def _receiver ():
39+ """Return a SignalReceiver instance and cache it as a static variable"""
40+ if not hasattr (_receiver , 'cached' ):
41+ _receiver .cached = SignalReceiver ()
42+ return getattr (_receiver , 'cached' )
43+
44+
3045def _decode_data (data ):
3146 """Decode base64-encoded JSON data and return Python data structure"""
3247 import json
@@ -50,13 +65,6 @@ def _encode_data(data):
5065 return encoded_data .decode ('ascii' )
5166
5267
53- def _receiver ():
54- """Return a SignalReceiver instance and cache it as a static variable"""
55- if not hasattr (_receiver , 'cached' ):
56- _receiver .cached = SignalReceiver ()
57- return getattr (_receiver , 'cached' )
58-
59-
6068def _jsonrpc (** kwargs ):
6169 """Perform JSONRPC calls"""
6270 import json
@@ -67,20 +75,11 @@ def _jsonrpc(**kwargs):
6775 return json .loads (executeJSONRPC (json .dumps (kwargs )))
6876
6977
70- def _to_unicode (text , encoding = 'utf-8' , errors = 'strict' ):
71- """Force text to unicode"""
72- if isinstance (text , bytes ):
73- return text .decode (encoding , errors = errors )
74- return text
75-
76-
7778class SignalReceiver (Monitor , object ): # pylint: disable=bad-option-value,useless-object-inheritance
7879 """The AddonSignals receiver class"""
79-
8080 def __init__ (self ): # pylint: disable=super-init-not-called
81- """The SignalReceiver constructor"""
8281 self ._slots = {}
83- super (SignalReceiver , self ).__init__ ()
82+ super (SignalReceiver , self ).__init__ () # pylint: disable=super-with-arguments
8483
8584 def registerSlot (self , signaler_id , signal , callback ):
8685 """Register a slot in the AddonSignals receiver"""
@@ -111,16 +110,16 @@ def onNotification(self, sender, method, data):
111110
112111class CallHandler (object ): # pylint: disable=bad-option-value,useless-object-inheritance
113112 """The AddonSignals event handler class"""
114-
115- def __init__ (self , signal , data , source_id , timeout = 1000 , use_timeout_exception = False ):
116- ''' The CallHandler constructor '''
113+ def __init__ (self , signal , data , source_id , timeout = 1000 , use_timeout_exception = False ): # pylint: disable=too-many-arguments
114+ """The CallHandler constructor"""
117115 self .signal = signal
116+ self .data = data
118117 self .timeout = timeout
119118 self .source_id = source_id
120119 self ._return = None
121120 self .is_callback_received = False
122121 self .use_timeout_exception = use_timeout_exception
123- registerSlot (self .source_id , '_return. {0}' .format (self .signal ), self .callback )
122+ registerSlot (self .source_id , '_return_ {0}' .format (self .signal ), self .callback )
124123 sendSignal (signal , data , self .source_id )
125124
126125 def callback (self , data ):
@@ -130,17 +129,17 @@ def callback(self, data):
130129
131130 def waitForReturn (self ):
132131 """Wait for callback to trigger"""
133- monitor = xbmc . Monitor ()
132+ monitor = Monitor ()
134133 end_time = _perf_clock () + (self .timeout / 1000 )
135134 while not self .is_callback_received :
136135 if _perf_clock () > end_time :
137136 if self .use_timeout_exception :
138137 unRegisterSlot (self .source_id , self .signal )
139138 raise WaitTimeoutError
140139 break
141- elif monitor .abortRequested ():
140+ if monitor .abortRequested ():
142141 raise OSError
143- xbmc . sleep (10 )
142+ sleep (10 )
144143 unRegisterSlot (self .source_id , self .signal )
145144 return self ._return
146145
@@ -183,7 +182,7 @@ def returnCall(signal, data=None, source_id=None):
183182 :param data: data to send
184183 :param source_id: the name used for call/answer (e.g. add-on id)
185184 """
186- sendSignal ('_return. {0}' .format (signal ), data , source_id )
185+ sendSignal ('_return_ {0}' .format (signal ), data , source_id )
187186
188187
189188def makeCall (signal , data = None , source_id = None , timeout_ms = 1000 , use_timeout_exception = False ):
0 commit comments