Best Python code snippet using pyatom_python
ruleset.py
Source:ruleset.py
1# coding: utf-82import re3import six4from huaweicloudsdkcore.utils.http_utils import sanitize_for_serialization5class Ruleset:6 """7 Attributes:8 openapi_types (dict): The key is attribute name9 and the value is attribute type.10 attribute_map (dict): The key is attribute name11 and the value is json key in definition.12 """13 sensitive_list = []14 openapi_types = {15 'project_id': 'str',16 'template_name': 'str',17 'language': 'str',18 'is_default': 'str',19 'rule_ids': 'str',20 'uncheck_ids': 'str',21 'template_id': 'str',22 'custom_attributes': 'list[CustomAttributes]'23 }24 attribute_map = {25 'project_id': 'project_id',26 'template_name': 'template_name',27 'language': 'language',28 'is_default': 'is_default',29 'rule_ids': 'rule_ids',30 'uncheck_ids': 'uncheck_ids',31 'template_id': 'template_id',32 'custom_attributes': 'custom_attributes'33 }34 def __init__(self, project_id=None, template_name=None, language=None, is_default=None, rule_ids=None, uncheck_ids=None, template_id=None, custom_attributes=None):35 """Ruleset36 The model defined in huaweicloud sdk37 :param project_id: 项ç®ID38 :type project_id: str39 :param template_name: æ°è§åéå称40 :type template_name: str41 :param language: è§åéè¯è¨42 :type language: str43 :param is_default: å¦ææåºäºçè§åéåæ¯1ï¼æ²¡æåºäºçè§åéåæ¯044 :type is_default: str45 :param rule_ids: æ°å¯ç¨è§åids46 :type rule_ids: str47 :param uncheck_ids: æ°å
³éè§åid48 :type uncheck_ids: str49 :param template_id: è§åéID50 :type template_id: str51 :param custom_attributes: èªå®ä¹è§ååæ°é¡¹ï¼æ¯æä¿®æ¹è§åéå¼52 :type custom_attributes: list[:class:`huaweicloudsdkcodecheck.v2.CustomAttributes`]53 """54 55 56 self._project_id = None57 self._template_name = None58 self._language = None59 self._is_default = None60 self._rule_ids = None61 self._uncheck_ids = None62 self._template_id = None63 self._custom_attributes = None64 self.discriminator = None65 self.project_id = project_id66 self.template_name = template_name67 self.language = language68 self.is_default = is_default69 self.rule_ids = rule_ids70 if uncheck_ids is not None:71 self.uncheck_ids = uncheck_ids72 if template_id is not None:73 self.template_id = template_id74 if custom_attributes is not None:75 self.custom_attributes = custom_attributes76 @property77 def project_id(self):78 """Gets the project_id of this Ruleset.79 项ç®ID80 :return: The project_id of this Ruleset.81 :rtype: str82 """83 return self._project_id84 @project_id.setter85 def project_id(self, project_id):86 """Sets the project_id of this Ruleset.87 项ç®ID88 :param project_id: The project_id of this Ruleset.89 :type project_id: str90 """91 self._project_id = project_id92 @property93 def template_name(self):94 """Gets the template_name of this Ruleset.95 æ°è§åéå称96 :return: The template_name of this Ruleset.97 :rtype: str98 """99 return self._template_name100 @template_name.setter101 def template_name(self, template_name):102 """Sets the template_name of this Ruleset.103 æ°è§åéå称104 :param template_name: The template_name of this Ruleset.105 :type template_name: str106 """107 self._template_name = template_name108 @property109 def language(self):110 """Gets the language of this Ruleset.111 è§åéè¯è¨112 :return: The language of this Ruleset.113 :rtype: str114 """115 return self._language116 @language.setter117 def language(self, language):118 """Sets the language of this Ruleset.119 è§åéè¯è¨120 :param language: The language of this Ruleset.121 :type language: str122 """123 self._language = language124 @property125 def is_default(self):126 """Gets the is_default of this Ruleset.127 å¦ææåºäºçè§åéåæ¯1ï¼æ²¡æåºäºçè§åéåæ¯0128 :return: The is_default of this Ruleset.129 :rtype: str130 """131 return self._is_default132 @is_default.setter133 def is_default(self, is_default):134 """Sets the is_default of this Ruleset.135 å¦ææåºäºçè§åéåæ¯1ï¼æ²¡æåºäºçè§åéåæ¯0136 :param is_default: The is_default of this Ruleset.137 :type is_default: str138 """139 self._is_default = is_default140 @property141 def rule_ids(self):142 """Gets the rule_ids of this Ruleset.143 æ°å¯ç¨è§åids144 :return: The rule_ids of this Ruleset.145 :rtype: str146 """147 return self._rule_ids148 @rule_ids.setter149 def rule_ids(self, rule_ids):150 """Sets the rule_ids of this Ruleset.151 æ°å¯ç¨è§åids152 :param rule_ids: The rule_ids of this Ruleset.153 :type rule_ids: str154 """155 self._rule_ids = rule_ids156 @property157 def uncheck_ids(self):158 """Gets the uncheck_ids of this Ruleset.159 æ°å
³éè§åid160 :return: The uncheck_ids of this Ruleset.161 :rtype: str162 """163 return self._uncheck_ids164 @uncheck_ids.setter165 def uncheck_ids(self, uncheck_ids):166 """Sets the uncheck_ids of this Ruleset.167 æ°å
³éè§åid168 :param uncheck_ids: The uncheck_ids of this Ruleset.169 :type uncheck_ids: str170 """171 self._uncheck_ids = uncheck_ids172 @property173 def template_id(self):174 """Gets the template_id of this Ruleset.175 è§åéID176 :return: The template_id of this Ruleset.177 :rtype: str178 """179 return self._template_id180 @template_id.setter181 def template_id(self, template_id):182 """Sets the template_id of this Ruleset.183 è§åéID184 :param template_id: The template_id of this Ruleset.185 :type template_id: str186 """187 self._template_id = template_id188 @property189 def custom_attributes(self):190 """Gets the custom_attributes of this Ruleset.191 èªå®ä¹è§ååæ°é¡¹ï¼æ¯æä¿®æ¹è§åéå¼192 :return: The custom_attributes of this Ruleset.193 :rtype: list[:class:`huaweicloudsdkcodecheck.v2.CustomAttributes`]194 """195 return self._custom_attributes196 @custom_attributes.setter197 def custom_attributes(self, custom_attributes):198 """Sets the custom_attributes of this Ruleset.199 èªå®ä¹è§ååæ°é¡¹ï¼æ¯æä¿®æ¹è§åéå¼200 :param custom_attributes: The custom_attributes of this Ruleset.201 :type custom_attributes: list[:class:`huaweicloudsdkcodecheck.v2.CustomAttributes`]202 """203 self._custom_attributes = custom_attributes204 def to_dict(self):205 """Returns the model properties as a dict"""206 result = {}207 for attr, _ in six.iteritems(self.openapi_types):208 value = getattr(self, attr)209 if isinstance(value, list):210 result[attr] = list(map(211 lambda x: x.to_dict() if hasattr(x, "to_dict") else x,212 value213 ))214 elif hasattr(value, "to_dict"):215 result[attr] = value.to_dict()216 elif isinstance(value, dict):217 result[attr] = dict(map(218 lambda item: (item[0], item[1].to_dict())219 if hasattr(item[1], "to_dict") else item,220 value.items()221 ))222 else:223 if attr in self.sensitive_list:224 result[attr] = "****"225 else:226 result[attr] = value227 return result228 def to_str(self):229 """Returns the string representation of the model"""230 import simplejson as json231 if six.PY2:232 import sys233 reload(sys)234 sys.setdefaultencoding("utf-8")235 return json.dumps(sanitize_for_serialization(self), ensure_ascii=False)236 def __repr__(self):237 """For `print`"""238 return self.to_str()239 def __eq__(self, other):240 """Returns true if both objects are equal"""241 if not isinstance(other, Ruleset):242 return False243 return self.__dict__ == other.__dict__244 def __ne__(self, other):245 """Returns true if both objects are not equal"""...
routing_table.py
Source:routing_table.py
1# coding: utf-82import handlers.active_handler as ActiveHandlers3import handlers.common_handler as CommonHandlers4import handlers.game_handler as game_handler5import handlers.live_handler as live_handler6import handlers.login_handler as LoginHandlers7import handlers.user_info_handler as UserInfoHandelers8check_token_dict = {'need_token': True}9uncheck_token_dict = {'need_token': False}10ROUTING_TABLE = [11 (r"/login/sendsms$", LoginHandlers.SendRegisterVerifyCodeHandler, uncheck_token_dict),12 (r"/login/sendpwsms$", LoginHandlers.SendResetPwVerifyCodeHandler, uncheck_token_dict),13 (r"/login/checkcode", LoginHandlers.ValidateSMSCode, uncheck_token_dict),14 (r"/login/register", LoginHandlers.RegisterUser, uncheck_token_dict),15 (r"/login/update", UserInfoHandelers.ModifyUser, check_token_dict),16 (r"/login/gethobby", CommonHandlers.GetHobby, check_token_dict),17 (r"/login/gethobbies", CommonHandlers.GetAllHobbiesHandle, check_token_dict),18 (r"/login/savehobby", UserInfoHandelers.SelectHobby, check_token_dict),19 (r"/login/login", LoginHandlers.UserLoginHandler, uncheck_token_dict),20 (r"/login/logout", LoginHandlers.UserOfflineHandler, check_token_dict),21 (r"/login/wx", LoginHandlers.WeChatUserLoginHandler, uncheck_token_dict),22 (r"/login/resetpw", UserInfoHandelers.ResetPasswordHandler, uncheck_token_dict),23 (r"/login/ver", CommonHandlers.GetAppVersionInfoHandler, uncheck_token_dict),24 (r"/ground/topic/get", ActiveHandlers.GetTopicsHandler, uncheck_token_dict),25 (r"/ground/active/add", ActiveHandlers.CreateActiveHandler, check_token_dict),26 (r"/ground/active/get", ActiveHandlers.GetActivesHandler, uncheck_token_dict),27 (r"/ground/active/delete", ActiveHandlers.DeleteActiveHandler, check_token_dict),28 (r"/ground/active/like", ActiveHandlers.LikeActiveHandler, check_token_dict),29 (r"/ground/active/refresh", ActiveHandlers.GetActiveMutableData, check_token_dict),30 (r"/ground/active/nearby", ActiveHandlers.GetActivesNearbyEpHandler, uncheck_token_dict),31 (r"/ground/active/comment/add", ActiveHandlers.AddCommentHandler, check_token_dict),32 (r"/ground/active/comment/delete", ActiveHandlers.DeleteCommentHandler, check_token_dict),33 (r"/ground/active/comment/get", ActiveHandlers.GetActiveCommentsHandler, check_token_dict),34 (r"/token/pic/upload", CommonHandlers.Get7CowUploadCertificate, check_token_dict),35 (r"/token/pic/download", CommonHandlers.Get7CowDownloadCertificate, check_token_dict),36 (r"/contactus/report", CommonHandlers.ReportHandler, check_token_dict),37 (r"/contactus/feedback", CommonHandlers.SuggestionHandler, check_token_dict),38 (r"/user/getsome", UserInfoHandelers.GetUserInfoHandler, uncheck_token_dict),39 (r"/user/detail", UserInfoHandelers.GetUserDetailHandler, uncheck_token_dict),40 (r"/user/details", UserInfoHandelers.GetUsersDetailHandler, uncheck_token_dict),41 (r"/user/visitors", UserInfoHandelers.GetUserVisitorsHandler, check_token_dict),42 (r"/user/sites", UserInfoHandelers.GetUserLocationHandler, check_token_dict),43 (r"/user/gold", UserInfoHandelers.GetUserGoldHandler, check_token_dict),44 (r"/discovery/users", UserInfoHandelers.GetRecommendUsersHandler, uncheck_token_dict),45 (r'/heartbeat/report', CommonHandlers.ReportHeartbeatHandler, check_token_dict),46]47import handlers.operation_handler as OpHandlers48import handlers.wshandler as ExpHandler49LIVE_TABLE = [50 (r'/live/create', live_handler.CreateLiveHandler, check_token_dict),51 (r'/live/resetpush', live_handler.ResetLivePushAddrHandler, check_token_dict),52 (r'/live/list', live_handler.GetLiveListHandler, uncheck_token_dict),53 # (r'/live/rank', live_handler.LiveFunctionalHandler, check_token_dict),54 (r'/live/detail', live_handler.GetLiveDetailHandler, check_token_dict),55 (r'/live/play', game_handler.GameCtrlHandler, check_token_dict),56 (r'/live/games', game_handler.GetGameListHandler, check_token_dict),57 (r'/live/rank', live_handler.RankHandler, check_token_dict),58 (r'/sock/live', ExpHandler.HostHandler),59 (r'/sock/watch', ExpHandler.WatcherHandler)60]61OP_TABLE = [62 (r"/op/hobby/add", OpHandlers.AddHobbyPageHandler),63 (r"/op/hobby/query", OpHandlers.ShowHobbiesHandler),64 (r"/op/topic/add", OpHandlers.AddTopicHandler),65 (r"/op/topic/update", OpHandlers.UpdateTopicHandler),66 (r"/op/topic/query", OpHandlers.QueryTopicHandler),67 (r"/op/switch/redis", OpHandlers.SwitchRedisHandler),68 (r"/op/appver/set", OpHandlers.ChangeVersionHandler),69 (r"/op/appver/get", OpHandlers.GetVersionHandler),70 (r"/op/user/control", OpHandlers.UserOperationHandler)71]72import pay.pay_handlers as pay_handlers73PAY_TABLE = [74 (r'/pay/cb/wx', pay_handlers.WeinXinCallbackHandler),75 (r'/pay/cb/zfb', pay_handlers.AliPayCallbackHandler),76 (r'/pay/q', pay_handlers.OrderQueryHandler, check_token_dict),77 (r'/pay/do', pay_handlers.PayHandler, check_token_dict),78 (r'/pay/his', pay_handlers.OrdersHandler, check_token_dict),79 (r'/pay/cargo', CommonHandlers.GetCargoConfHandler, check_token_dict)...
scan_domain.py
Source:scan_domain.py
1import os2import sys3import subprocess4import time5import re6import threading7gUncheckDomainFile = 'UncheckDomain.txt'8gNotOccupiedFile = 'NotOccupied.txt'9gAlreadyOccupiedFile = 'AlreadyOccupied.txt'10class ScanDomain:11 def __init__(self):12 self.set_not_occupied_file = 'NotOccupied.txt'13 self.set_already_occupied_file = 'AlreadyOccupied.txt'14 self.set_thread_cnt = 2015 self.not_occupied_fd = None16 self.already_occupied_fd = None17 self.set_uncheck_domain_file = 'UncheckDomain.txt'18 self.lock = threading.Lock()19 self.uncheck_domain_list = list()20 self.quit = False21 self.running_thread_cnt = 022 self.do_init()23 time.sleep(3)24 pass25 def do_init(self):26 self.already_occupied_fd = open(self.set_already_occupied_file, 'a+')27 self.not_occupied_fd = open(self.set_not_occupied_file, 'a+')28 self.get_domain()29 pass30 def add_not_occupied_domain(self, domain):31 self.lock.acquire()32 self.not_occupied_fd.write(domain + '\n')33 self.not_occupied_fd.flush()34 self.lock.release()35 pass36 def add_already_occupied_domain(self, domain):37 self.lock.acquire()38 self.already_occupied_fd.write(domain + '\n')39 self.already_occupied_fd.flush()40 self.lock.release()41 pass42 def add_uncheck_domain(self, domain):43 self.lock.acquire()44 self.uncheck_domain_list.append(domain)45 self.lock.release()46 pass47 def get_domain(self):48 if os.path.exists(self.set_uncheck_domain_file):49 words_file = gUncheckDomainFile50 with open(words_file, 'r') as fd:51 while True:52 line = fd.readline()53 if not line:54 break55 self.uncheck_domain_list.append(line[:-1])56 else:57 words_file = '/usr/share/dict/words'58 with open(words_file, 'r') as fd:59 while True:60 line = fd.readline()61 if not line:62 break63 self.uncheck_domain_list.append(line[:-1] + '.cc')64 print 'Load from [%s] Done, cnt [%d]' % (words_file, len(self.uncheck_domain_list))65 pass66 def get_domain_to_check(self):67 self.lock.acquire()68 if not len(self.uncheck_domain_list):69 ret_domain = None70 else:71 ret_domain = self.uncheck_domain_list.pop()72 self.lock.release()73 return ret_domain74 pass75 def save_uncheck_doman_list(self):76 with open(self.set_uncheck_domain_file, 'w+') as fd:77 for domain in self.uncheck_domain_list:78 fd.write(domain + '\n')79 pass80 def check_domain(self, domain_url):81 command = ['nslookup', domain_url]82 pipe = subprocess.Popen(command, stdout=subprocess.PIPE)83 out = ''84 while True:85 if pipe.poll() is not None:86 break87 time.sleep(0.1)88 out = pipe.stdout.read()89 ret = True90 pattern = 'server can\'t find'91 m = re.search(pattern, out)92 if m:93 print 'Not occupied [%s]' % domain_url94 ret = True95 pattern = 'answer'96 m = re.search(pattern, out)97 if m:98 print 'Already occupied [%s]' % domain_url99 ret = False100 return ret101 pass102 def check_domain_thread(self):103 self.running_thread_cnt += 1104 while True:105 domain = self.get_domain_to_check()106 if not domain:107 break108 ret = self.check_domain(domain)109 if ret:110 self.add_not_occupied_domain(domain)111 else:112 self.add_already_occupied_domain(domain)113 if self.quit:114 self.add_uncheck_domain(domain)115 break116 self.running_thread_cnt -= 1117 def start_scan(self):118 for idx in range(self.set_thread_cnt):119 pro = threading.Thread(target=self.check_domain_thread)120 pro.start()121 while True:122 try:123 time.sleep(5)124 if not len(self.uncheck_domain_list):125 print 'All Done'126 self.save_uncheck_doman_list()127 return128 except KeyboardInterrupt:129 self.quit = True130 while 0 != self.running_thread_cnt:131 print 'Please waiting for thread quit [%d]' % self.running_thread_cnt132 time.sleep(1)133 self.save_uncheck_doman_list()134 print 'Quit Now'135 return136 pass137 def quit(self):138 pass139def do_test():140 scan_handle = ScanDomain()141 scan_handle.start_scan()142 pass143if __name__ == '__main__':...
compare.py
Source:compare.py
1#!/usr/bin/env python2# -*- encoding: utf-8 -*-3'''4@File : compare.py5@Author : Billy Zhou6@Time : 2021/08/227@Desc : None8'''9import sys10from pathlib import Path11cwdPath = Path(__file__).parents[2]12sys.path.append(str(cwdPath))13from src.manager.Logger import logger14log = logger.get_logger(__name__)15import copy16from collections.abc import Mapping17from src.basic.input_check import input_checking_YN18def dict_compare(19 dict_uncheck: dict, dict_refer: dict,20 dict_checked: dict = {}, suffix: str = '[]', lv: int = 0, diff_autoadd=True):21 """Compare two dict and merge the missing part."""22 if not dict_checked:23 log.debug('dict_checked init')24 dict_checked = copy.deepcopy(dict_uncheck)25 sub_lv = lv + 126 suffix = '[]' if lv == 0 else suffix27 if not dict_uncheck:28 # missing part29 if diff_autoadd:30 dict_checked = dict_refer31 else:32 selection = input_checking_YN('dict_uncheck is blank. Fill it with dict_refer?')33 if selection == 'Y':34 print('Filled.')35 dict_checked = dict_refer36 else:37 print('Canceled.')38 else:39 log.debug('dict_checked: {0}'.format(dict_checked))40 # diff with dict_refer base on dict_refer.items()41 for key, value_refer in dict_refer.items():42 suffix_ = "[" + str(key) + "]"43 log.debug("sub_lv: %s", sub_lv)44 log.debug("suffix: %s", suffix)45 log.debug("suffix_: %s", suffix_)46 if not dict_uncheck.get(key):47 # dict_uncheck missing part in dict_refer48 if diff_autoadd:49 dict_checked[key] = dict_refer[key]50 else:51 sub_suffix = suffix + suffix_ if suffix != '[]' else suffix_52 tip_words = 'dict_uncheck{0} is missing. Add it with dict_refer{0}?'.format(sub_suffix)53 selection = input_checking_YN(tip_words)54 if selection == 'Y':55 print('Added.')56 dict_checked[key] = dict_refer[key]57 else:58 print('Canceled.')59 else:60 sub_suffix = suffix + suffix_ if suffix != '[]' else suffix_61 if isinstance(value_refer, Mapping):62 # check deeper for dict type of value_refer63 # value_refer equal to dict_refer[key]64 log.debug("sub_suffix: %s", sub_suffix)65 dict_compare(66 dict_uncheck[key], value_refer, dict_checked[key],67 sub_suffix, sub_lv, diff_autoadd)68 else:69 # check diff part of values between dict_uncheck and dict_refer70 if str(dict_uncheck[key]) != str(dict_refer[key]):71 print('Values diff between dict_uncheck{0} and dict_refer{0}.'.format(sub_suffix))72 print('Value of dict_uncheck{0}: {1}'.format(sub_suffix, dict_uncheck[key]))73 print('Value of dict_refer{0}: {1}'.format(sub_suffix, value_refer))74 tip_words = 'Replace the value of dict_uncheck{0} with dict_refer{0}?'.format(sub_suffix)75 selection = input_checking_YN(tip_words)76 if selection == 'Y':77 print('Replaced.')78 dict_checked[key] = dict_refer[key]79 else:80 print('Canceled.')81 return dict_checked82if __name__ == '__main__':83 d1 = {84 1: {85 2: {86 7: [9]87 },88 6: [7, 8]89 },90 4: [7, 8]91 }92 d2 = {93 1: {94 2: {95 9: [10]96 },97 3: [7, 8]98 },99 2: {100 1: {},101 },102 3: [7, 8],103 4: [5, 6],104 }105 print(dict_compare(d1, d2, diff_autoadd=False))106 print("d1: {0}".format(d1))...
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!!