How to use check_content method in avocado

Best Python code snippet using avocado_python

check.py

Source:check.py Github

copy

Full Screen

1# -*-coding:utf-8-*-23class Udp_check():4 def __init__(self, IP_content):5 self.IP_content = IP_content6 self.IP_header_len = 20 # IP头部20字节7 self.check_content = [] # UDP校验和部分8 # UDP校验和部分 = UDP伪首部 + UDP内容(UDP首部 + UDP数据部分)910 def add_udp_pseudo_header_content(self):11 # UDP伪首部 = 源IP地址 + 目的IP地址 + 0x00 +协议字段 + UDP长度1213 # IP源地址为IP报文的13、14、15、16字节,即伪首部的源IP地址字段14 self.check_content.append(self.IP_content[12])15 self.check_content.append(self.IP_content[13])16 self.check_content.append(self.IP_content[14])17 self.check_content.append(self.IP_content[15])1819 # IP目的地址为IP报文的17、18、19、20字节,即伪首部的目的IP地址字段20 self.check_content.append(self.IP_content[16])21 self.check_content.append(self.IP_content[17])22 self.check_content.append(self.IP_content[18])23 self.check_content.append(self.IP_content[19])2425 # UDP伪首部的第三个字段,为0x0026 self.check_content.append(0x00)2728 # 协议类型是IP报文的第10字节,即伪首部的协议类型字段29 self.check_content.append(self.IP_content[9])3031 # UDP数据长度是UDP报文中的第5、6字节,伪首部的长度字段3233 self.check_content.append(self.IP_content[self.IP_header_len + 4])34 self.check_content.append(self.IP_content[self.IP_header_len + 5])3536 def add_udp_content(self):37 # udp内容的长度38 udp_content_len = len(self.IP_content) - self.IP_header_len39 # 往校验部分添加udp内容40 for i in range(udp_content_len):41 self.check_content.append(self.IP_content[self.IP_header_len + i])4243 def set_and_fill_zero(self):44 self.check_content[18] = 0 # 把原来的校验和设置为045 self.check_content[19] = 04647 if len(self.check_content) % 2 == 1: # 整个报文长度为奇数需要补充048 self.check_content.append(0x00)4950 def check_process(self):51 data_sum = []5253 # 先需要将前后二个数合并成16位长度的16进制的数54 for num in range(0, len(self.check_content), 2):55 # 如果转换为16进制后只有1位需要高位补0操作,用zfill方法56 part1 = str(hex(self.check_content[num]))[2:].zfill(2)57 part2 = str(hex(self.check_content[num + 1]))[2:].zfill(2)58 part_all = part1 + part259 data_sum.append(int(part_all, 16))60 ## print(data_sum)6162 sum_total = sum(data_sum) # 计算所有数的和63 sum_total_hex = str(hex(sum_total))[2:] # 16进制化64 sum_total_hex_len = len(sum_total_hex) # 取得字节长度6566 if sum_total_hex_len > 4: # 求和的结果大于2个[字节16位]的话,分割成2个2字节16位数67 part1 = int(sum_total_hex[: sum_total_hex_len - 4], 16) # 分割第一、二字节的十六进制数字,转换为10进制68 part2 = int(sum_total_hex[sum_total_hex_len - 4:], 16) # 分割第三、四字节的十六进制数字,转换为10进制69 part_all = part1 + part270 else:71 part_all = sum_total7273 last_check_sum = str(hex(65535 - part_all))[2:] # 二个字节的十六进制数之和取反74 return sum_total_hex, last_check_sum7576 def run(self):77 self.add_udp_pseudo_header_content()78 self.add_udp_content()79 check1 = str(hex(self.check_content[18]))[2:]80 check2 = str(hex(self.check_content[19]))[2:]8182 print("检验和:0x{0}{1}".format(check1, check2))8384 self.set_and_fill_zero()85 print('需要计算的UDP校验和内容为:{}'.format((self.check_content)))86 ## UDP校验和部分准备完成8788 sum_total_hex, last_check_sum = self.check_process()89 print("sum_total_hex: 0x{}".format(sum_total_hex))90 print("检验和:0x{0}".format(last_check_sum))9192 temp = hex((int(sum_total_hex, 16) >> 16) + (int(sum_total_hex, 16) & 0xffff))93 print("(0x{0} >> 16) + (0x{0} & 0xffff) = {1} ".format(sum_total_hex, temp))9495 temp2 = hex(int(temp, 16) + int('0x' + check1 + check2, 16))96 print("{0} + 0x{1}{2} = {3}".format(temp, check1, check2, temp2))979899if __name__ == '__main__':100 IP_content_hex = ['66', '60', '55', '55', '8f', '0c', '00', '00', '40', '11', 'd5', '85', '0a', '08', '88', '17',101 '0a', '08', '88', 'ff', 'd6', '83', 'd6', '83', '01', '0f', '5f', '62', '00', '73', '68', '79',102 '79', '79', '66', '2d', '67', '75', '74', '69', '6e', '67', '74', '00', '00', '00', '00', '00',103 '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '20', '5f', '27', '02',104 '00', '00', '00', '00', '30', 'b4', '9f', '06', '00', '00', '00', '00', '33', '27', '00', '00',105 '00', '00', '00', '00', '10', '5f', '27', '02', '00', '00', '00', '00', 'c0', '04', '6e', '05',106 '00', '00', '00', '00', '7c', '6a', '7a', '70', '00', '00', '00', '00', '98', 'a3', 'da', '6f',107 '00', '00', '00', '00', '59', 'b8', '9f', '06', '00', '00', '00', '00', '00', '00', '00', '00',108 '00', '00', '00', '00', '70', '97', 'da', '04', '00', '00', '00', '00', 'a4', 'b4', '9f', '06',109 '00', '00', '00', '00', 'c0', 'b4', '9f', '06', '00', '00', '00', '00', 'a8', 'd9', '7a', '7b',110 '61', '63', '36', '35', '64', '66', '64', '62', '2d', '36', '32', '37', '34', '2d', '34', '65',111 '65', '34', '2d', '62', '63', '64', '64', '2d', '34', '35', '62', '36', '61', '62', '63', '63',112 '37', '31', '36', '39', '7d', '00', '00', '00', '00', '00', '00', '00', '01', '00', '00', '00',113 '00', '00', '00', '00', 'a0', 'b4', '9f', '06', '00', '00', '00', '00', '00', '00', '00', '00',114 '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00',115 '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00',116 '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00',117 '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '35',118 'a5', '8a', 'f3']119 print("IP_content:{}".format(len(IP_content_hex)))120121 IP_content_dec = [int(i, 16) for i in IP_content_hex] # 十进制化122 udp_check = Udp_check(IP_content_dec)123 udp_check.run()124 ...

Full Screen

Full Screen

Conversation.py

Source:Conversation.py Github

copy

Full Screen

...47 print(48 "ERROR: Imagem encontrada porém erro ao obter atributos tag=message_attachments"49 )50 async def __register_m7(self):51 if self.bot.check_content("?m7"):52 if Data.has_recent_image(self.bot.author_id):53 points = Data.get_points_by_id(self.bot.author_id)54 points += 155 Data.update_points(self.bot.author_id, points)56 await self.bot.say(57 self.bot.mention + MessageEnum.M7_EMBLEM.value + str(points)58 )59 else:60 await self.bot.say(MessageEnum.PLEASE_SEND_PICTURE.value)61 async def __register_m6(self):62 if self.bot.check_content("?m6"):63 if Data.has_recent_image(self.bot.author_id):64 points = Data.get_points_by_id(self.bot.author_id)65 points += 0.566 Data.update_points(self.bot.author_id, points)67 await self.bot.say(68 self.bot.mention + MessageEnum.M6_EMBLEM.value + str(points)69 )70 else:71 await self.bot.say(MessageEnum.PLEASE_SEND_PICTURE.value)72 async def __individual_points_message(self):73 if self.bot.check_content("?p"):74 points = Data.get_points_by_id(self.bot.author_id)75 result = f"{self.bot.mention} - {points} pontos\n"76 await self.bot.say(result)77 async def __overall_general_ranking_message(self):78 if self.bot.check_content("?rg"):79 ranking = Data.get_general_overall_ranking()80 print(ranking)81 result = MessageEnum.EVERY_SEASON_RANKING.value82 for row in ranking:83 result += f"{row[0]} - {str(row[1])} pontos\n"84 await self.bot.say(result)85 async def __general_ranking_message(self):86 if self.bot.check_content("?r"):87 ranking = Data.get_general_ranking()88 print(ranking)89 result = ""90 for row in ranking:91 result += f"{row[0]} - {str(row[1])} pontos\n"92 await self.bot.say(result)93 async def __sign_in_message(self):94 if self.bot.check_content("?c"):95 Data.add_new_participant(self.bot.author_id, self.bot.author)96 await self.bot.say(97 self.bot.mention + MessageEnum.REGISTERED_SUCCESSFULLY.value98 )99 async def __rules_message(self):100 if self.bot.check_content("?rules"):101 Data.add_new_participant(self.bot.author_id, self.bot.author)102 await self.bot.say(MessageEnum.RULES.value)103 async def __help_message(self):104 if self.bot.check_content("?help", "?h"):105 await self.bot.say(MessageEnum.COMMANDS_LIST.value)106 async def __eater_eggs_messages(self):107 if self.bot.check_content("???"):108 await self.bot.say(f"Oia o bot aqui rapai, fica esperto {self.mention}")109 if self.bot.check_content("!!!"):110 await self.bot.react("😑")111 for variant in EasterEggsLists.VesselList():112 if self.bot.check_content_start(variant):113 await self.bot.react("😑")114 await self.bot.say("Carai Barba, você só ouve isso!")115 for variant in EasterEggsLists.BestOfList():116 if self.bot.check_content_start(variant):117 await self.bot.react("😁")...

Full Screen

Full Screen

discovery_rule.py

Source:discovery_rule.py Github

copy

Full Screen

...40 self.check_content = check_content41 self.check_mode = check_mode42 self.check_type = check_type43 @property44 def check_content(self):45 """Gets the check_content of this DiscoveryRule.46 匹配值。47 :return: The check_content of this DiscoveryRule.48 :rtype: list[str]49 """50 return self._check_content51 @check_content.setter52 def check_content(self, check_content):53 """Sets the check_content of this DiscoveryRule.54 匹配值。55 :param check_content: The check_content of this DiscoveryRule.56 :type check_content: list[str]57 """58 self._check_content = check_content59 @property60 def check_mode(self):61 """Gets the check_mode of this DiscoveryRule.62 匹配条件。 contain、equals63 :return: The check_mode of this DiscoveryRule.64 :rtype: str65 """66 return self._check_mode...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful