Best Python code snippet using localstack_python
portscanner-bot.py
Source: portscanner-bot.py
...64 message = ""65 for ip in self.ip_range:66 start = datetime.now()67 new_chunk = self.start_scanning_template.format(ip)68 if self.check_message_size(new_chunk, message):69 message += new_chunk70 else:71 bot.send_message(chat_id=update.message.chat_id, text=message)72 message = new_chunk73 time.sleep(1)74 for port in self.port_range:75 result = self.scanner.scan_port(ip, port)76 if result:77 new_chunk = self.scanning_template.format(port, self.scanner.get_service_name(port))78 if not self.check_message_size(message, new_chunk):79 bot.send_message(chat_id=update.message.chat_id, text=message)80 message = new_chunk81 time.sleep(1)82 else:83 message += new_chunk84 end = datetime.now()85 totaltime = end - start86 new_chunk = self.scanning_completed_template.format(totaltime)87 if self.check_message_size(new_chunk, message):88 message += new_chunk89 else:90 bot.send_message(chat_id=update.message.chat_id, text=message)91 message = new_chunk92 time.sleep(1)93 if len(message) > 0:94 bot.send_message(chat_id=update.message.chat_id, text=message)95 time.sleep(1)96 except Exception as e:97 print(e)98 bot.send_message(chat_id=update.message.chat_id, text=self.replies['exception_value'])99 def check_message_size(self, message, chunk):100 if len(message) + len(chunk) <= self.MAX_MESSAGE_SIZE:101 return True102 else:103 return False104 def set_timeout(self, bot, update, args):105 input = ' '.join(args)106 try:107 self.scanner.set_timeout(float(input))108 except:109 bot.send_message(chat_id=update.message.chat_id, text=self.replies['exception_timeout'])110 def log(self, bot, update, comment=""):111 try:112 name = update.message.from_user.first_name113 text = update.message.text...
jafka-performance.py
Source: jafka-performance.py
...18import time19DEFAULT_MAX_MESSAGE_SIZE = 1024*102420def packagesize(messagesize,batchsize,topic):21 return (10 + messagesize)*batchsize +16+len(topic.encode('utf-8'))22def check_message_size(messagesize,batchsize,topic):23 size = packagesize(messagesize,batchsize,topic)24 if size > DEFAULT_MAX_MESSAGE_SIZE:25 print('The message package(%d) is too large;default message package is: %d' %\26 (size,DEFAULT_MAX_MESSAGE_SIZE))27 print(' package size = (10 + messagesize)*batchsize +16+topic')28 dsize = DEFAULT_MAX_MESSAGE_SIZE - 16 - len(topic.encode('utf8'))29 print(' messagesize(%d): batchsize <= %.d' % (messagesize,dsize/messagesize))30 print(' batchsize(%d): messaegsize <= %.d' % (batchsize,dsize/batchsize))31 sys.exit(1)32 return size33if __name__ == '__main__':34 argv=sys.argv35 argvs=len(argv)36 if len(sys.argv) < 5:37 print('Usage: %s <topic> <host> <port> <count> [batchsize [messagesize]]'%(argv[0]))38 print(' : %s demo localhost 9022 10000'%(sys.argv[0]))39 print(' : %s demo localhost 9022 10000 100 100'%(sys.argv[0]))40 sys.exit(1)41 (topic,host,port,count) = (argv[1],argv[2],int(argv[3]),int(argv[4]))42 batchsize = int(argv[5]) if argvs>5 else 143 messagesize = int(argv[6]) if argvs>6 else 10044 package_size = check_message_size(messagesize,batchsize,topic)45 print('send %d messages to topic[%s] at %s:%d\n batch size=%d\n message size: %d' % (count,topic,host,port,batchsize,messagesize))46 producer = jafka.Producer(host,port)47 start = time.time()48 i = 049 send_bytes = 050 messages = [bytearray(messagesize) for i in range(batchsize)]51 out=sys.stdout52 clear='\b'*653 while i < count:54 producer.send('demo',messages)55 i += batchsize56 if i > batchsize:57 out.write(clear)58 out.write('%05.2f%%'%(100*i/(1.0*count)))...
test_sqs.py
Source: test_sqs.py
...37 queue = provider.SqsQueue("TestQueue", "us-east-1", "123456789", policy)38 sqs_message = provider.SqsMessage(Message(), {})39 result = provider.SqsProvider()._dead_letter_check(queue, sqs_message, None)40 assert result is False41def test_except_check_message_size():42 message_body = "".join(("a" for _ in range(provider.DEFAULT_MAXIMUM_MESSAGE_SIZE + 1)))43 with pytest.raises(provider.InvalidParameterValue):44 provider.check_message_size(message_body, provider.DEFAULT_MAXIMUM_MESSAGE_SIZE)45def test_check_message_size():46 message_body = "a"...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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!!