Best Python code snippet using avocado_python
check.py
Source:check.py
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
...
Conversation.py
Source:Conversation.py
...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("ð")...
discovery_rule.py
Source:discovery_rule.py
...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...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!