def request_data(self, request, *args): """Request data from Turbo-Satori. Parameters: ----------- request : str The request to be sent to Turbo-Satori. Returns: -------- data : str The byte string of the received data. rt : int The time it took to get the data. """ start = get_time() self._tcp.clear() request = unicode2byte(request) self._send(request, *args) data = self._wait() arg_length = sum([len(x) for x in args]) arg = b"".join(args) if data is None: raise TurbosatoriNetworkInterface.TimeoutError( "Waiting for requested data timed out!") elif byte2unicode(data).startswith("Wrong request!"): raise TurbosatoriNetworkInterface.RequestError( "Wrong request '{0}'!".format(data[19:-1])) elif data[0:len(request) + 1 + arg_length] != request + b"\x00" + arg: raise TurbosatoriNetworkInterface.DataError( "Received data does not match request!") else: return data[len(request) + 1:], int((get_time() - start) * 1000)
def request_data(self, request, *args): """Request data from Turbo Brain Voyager. Parameters ---------- request : str The request to be sent to Turbo Brain Voyager. Returns ------- data : str The byte string of the received data. rt : int The time it took to get the data. """ start = get_time() self._tcp.clear() request = unicode2byte(request) self._send(request, *args) data = self._wait() if data is None: return None, None elif data[0:len(request)] != request: return data, None else: return data[len(request) + 1:], int((get_time() - start) * 1000)
def _send(self, message, *args): length = len(message) arg_length = sum([len(x) for x in args]) data = struct.pack('!q', length + 5 + arg_length) + \ b"\x00\x00\x00" + unicode2byte(chr(length + 1)) + message + b"\x00" if len(args) > 0: for arg in args: data += arg self._tcp.send(data)
def _send(self, message, *args): length = len(message) arg_length = 0 if len(args) > 0: for arg in args: arg_length += len(arg) data = struct.pack('!q', length + 5 + arg_length) + \ b"\x00\x00\x00" + unicode2byte(chr(length + 1)) + message + b"\x00" if len(args) > 0: for arg in args: data += arg self._tcp.send(data)