Example #1
0
 def add_stream(self, func, *args, **kwargs):
     """ Add a stream to the server """
     if self._stream_connection is None:
         raise StreamError('Not connected to stream server')
     if func == setattr:
         raise StreamError('Cannot stream a property setter')
     return_type = self._get_return_type(func, *args, **kwargs)
     call = self.get_call(func, *args, **kwargs)
     return krpc.stream.Stream.from_call(self, return_type, call)
Example #2
0
 def _get_return_type(func, *args, **kwargs):  # pylint: disable=unused-argument
     """ Get the return type for a remote procedure call """
     if func == getattr:
         # A property or class property getter
         attr = func(args[0].__class__, args[1])
         return attr.fget._return_type
     elif func == setattr:
         # A property setter
         raise StreamError('Cannot get return type for a property setter')
     elif hasattr(func, '__self__'):
         # A method
         return func._return_type
     else:
         # A class method
         return func._return_type
Example #3
0
 def get_call(func, *args, **kwargs):
     """ Convert a remote procedure call to a KRPC.ProcedureCall message """
     if func == getattr:
         # A property or class property getter
         attr = func(args[0].__class__, args[1])
         return attr.fget._build_call(args[0])
     elif func == setattr:
         # A property setter
         raise StreamError('Cannot create a call for a property setter')
     elif hasattr(func, '__self__'):
         # A method
         return func._build_call(func.__self__, *args, **kwargs)
     else:
         # A class method
         return func._build_call(*args, **kwargs)
 def remove(self):
     self._conn._stream_manager.remove_stream(self._stream_id)
     with self._update_lock:
         self._value = StreamError("Stream does not exist")
 def value(self):
     if not self._updated:
         raise StreamError("Stream has no value")
     return self._value