def clean_escape_ruler(self): """ This function should called only once, so there is singleton pattern! To make the client configure file more easy to use So, in this function, we will convert something like ''0x7e7b==0x7e#0x7b7b==0x7b' to '126,123==123#123,123==123' :return: """ if self.singleton_flag: items = self.escape_ruler.split('#') new_escape_str = '' for item in items: key, value = item.split('==') new_key = str(dns(key)) new_value = str(dns(value)) new_key_x = new_key.replace('(', '').replace(')', '').rstrip(',') new_value_x = new_value.replace('(', '').replace(')', '').rstrip(',') new_escape_str += new_key_x + '==' + new_value_x + '#' self.escape_ruler = new_escape_str.rstrip('#') self.singleton_flag = False else: return 'You see this!! because this function is use Singleton Pattern! Only call for one time!'
def render(request, ruler): """ :param ruler: :type request: object """ system_cmd = SYSTEM_CMD temp = [] fill_field = ruler.split("|") # Auto loader the old CRC for value for occupying fill_field.append('sys_crc') #: loader the data format by ruler for item in fill_field: #: if the key in the request ,and go get it! if item in request: #: because , the value will be a tuple! pop_each_field(request[item], temp) elif item in system_cmd: pop_each_field(system_cmd[item], temp) elif item.startswith('0x'): cmd_tuple = dns(item) pop_each_field(cmd_tuple, temp) check_code = check(temp) #: change to a new CRC temp[-1] = check_code temp.insert(0, 126) temp.append(126) send_data = tuple(temp) if __name__ == '__main__': return send_data else: send_data_binary = tongue.Code(send_data).dst return send_data_binary