def recv_tuple(self): tmp_buffer = [' '] res_tuple = [] while tmp_buffer[-1] != '\n': char = recv_n_bytes(self.sock, 1) if char == ':': if tmp_buffer[1] == '\x00': toks = ''.join(tmp_buffer[2:]).split('@') else: toks = ''.join(tmp_buffer[1:]).split('@') elmt_type = toks[0].strip() if elmt_type == 'i' or elmt_type == 'j': res_tuple.append(int(toks[1])) elif elmt_type == 'f': res_tuple.append(float(toks[1])) else: # String res_tuple.append(toks[1]) tmp_buffer = [' '] else: tmp_buffer.append(char) return tuple(res_tuple)
def recv_n_bytes(self, n_bytes): """ Receive exactly n bytes Args: n_bytes: Number of bytes to receive """ return recv_n_bytes(self.sock, n_bytes)