Best Python code snippet using localstack_python
async.py
Source: async.py
1#!/usr/bin/env python2#coding=utf-83import threading4import pycurl5from cStringIO import StringIO6class UrlOpen(threading.Thread):7 """å¼æ¥ä¸è½½ç½é¡µ"""8 def __init__(self):9 super(UrlOpen,self).__init__()10 self.opener = pycurl.CurlMulti()11 self.handle_list=[]12 def add(self,url,recall,writer=StringIO()):13 """14 åæ°:ç½å,åè°å½æ°,åæ¾ä¸´æ¶æ°æ®ç对象15 """16 c = pycurl.Curl()17 #å¯ä»¥ä¼ ç»åè°å½æ°18 c.url=url19 c.content = writer20 c.recall = recall21 c.setopt(c.URL,url)22 c.setopt(c.WRITEFUNCTION,c.content.write)23 self.handle_list.append(c)24 self.opener.add_handle(c)25 def _remove(self,c):26 c.close()27 self.opener.remove_handle(c)28 self.handle_list.remove(c)29 def run(self):30 num_handle=len(self.handle_list)31 while 1:32 ret = self.opener.select(10.0)33 if ret == -1: continue34 while 1:35 num_handle_pre=num_handle36 ret, num_handle =self.opener.perform()37 #æ´»å¨çè¿æ¥æ°æ¹åæ¶38 if num_handle!=num_handle_pre:39 result=self.opener.info_read()40 print result41 for i in result[1]:42 #æå43 i.http_code = i.getinfo(i.HTTP_CODE)44 self._remove(i)45 i.recall(i)46 for i in result[2]:47 #失败,åºè¯¥è®°å½ä¸ä¸48 self._remove(i)49 if ret != pycurl.E_CALL_MULTI_PERFORM:50 break51_opener=None52def urlopen(*arg,**key):53 global _opener54 if _opener is None:55 _opener=UrlOpen()56 _opener.add(*arg,**key)57 _opener.start()58 else:59 _opener.add(*arg,**key)60def show(x):61 print x.content.getvalue()62if __name__=="__main__":63 urlopen("http://blog.linuxeye.com/400.html",show)...
__init__.py
Source: __init__.py
1import urllib22import htmltool3_opener = None4def build_opener(spy, refresh=False):5 global _opener6 if not refresh and _opener:7 return _opener8 _opener = urllib2.build_opener(urllib2.HTTPHandler)9 """Set headers for every request.10 If a custom header for a certain request is required,11 define it using urllib2.Reqest12 """13 _opener.addheaders = [14 ("Accept", "*/*"),15 ("Accept-Encoding", "gzip,deflate"),16 ("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.6,en;q=0.4"),17 ("Connection", "keep-alive"),18 ("Content-Type", "application/x-www-form-urlencoded;\19charset=UTF-8"),20 # ("Host", spy.site['host']),21 # ("Origin", spy.site['domain_url']),22 # ("Referer", spy.site['domain_url']),23 ("User-Agent", """Mozilla/5.0 (Windows NT 6.1; WOW64) ,Apple\24WebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36"""),25 ("X-Requested-With", "XMLHttpRequest"),26 # ("X-Forwarded-For", "214.131.109.123"),27 ("Is-every-header-required", "I am awesome"),28 ]29 _opener.add_handler(htmltool.HTTPInternalError())30 _opener.add_handler(htmltool.proxy_handler)31 # default handlers32 spy.opener = _opener33 return _opener34class Spy(object):35 def __init__(self):36 pass37spy = Spy()38build_opener(spy)39# usock = _opener.open("http://anypost.yii2cms.com")40usock = _opener.open("https://www.google.com")41result = htmltool.handle_uscok(usock)42print(result)...
aoc_day_10.py
Source: aoc_day_10.py
1from numpy import median2# Todays solution is maybe a little clumsy because I wrote it while on the train #3file = 'input_puzzles/day_10.txt'4with open(file, 'r') as f:5 input = f.read().splitlines()6_opener = ['(', '[', '{', '<']7_closer = [')', ']', '}', '>']8_pairing_closer = {_closer[i]: _opener[i] for i in range(len(_opener))}9_pairing_opener = {_opener[i]: _closer[i] for i in range(len(_opener))}10_scores = {')': 3, ']': 57, '}': 1197, '>': 25137}11def check_corruption(line):12 res = []13 for char in line:14 if char in _opener:15 res.append(char)16 else:17 if _pairing_closer[char] != res[-1]:18 return char19 else:20 res.pop(-1)21 return22def find_incompletes(line):23 res = []24 for char in line:25 if char in _opener:26 res.append(char)27 else:28 if _pairing_closer[char] != res[-1]:29 return 30 else:31 res.pop(-1)32 return [_pairing_opener[i] for i in res][::-1]33def autocorrect_score(line):34 fin = 035 for char in line:36 fin = fin * 537 fin += _closer.index(char) + 138 return fin39res1 = sum(_scores[i] for i in [check_corruption(i) for i in input if check_corruption(i) != None])40incompletes = [find_incompletes(i) for i in input if find_incompletes(i) != None]41res2 = median([autocorrect_score(i) for i in incompletes])42print(f'Part 1: {res1}')...
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!!