Best Python code snippet using tox_python
web_server.py
Source: web_server.py
...39 req = urllib.request.Request(url)40 res = urllib.request.urlopen(req)41 userid = res.headers["Qcloud-Server-Userid"]42 token = res.headers["Qcloud-Token"]43 self.set_header("Qchemserv-Status", "OK")44 self.set_header("Qchemserv-Request", "register")45 self.set_header("Qchemserv-Cookie", token)46 logging.info("User added: " + userid)47 except Exception as e:48 msg = str(e);49 logging.error(msg)50 self.set_header("Qcloud-Server-Message", msg)51class SubmitJob(BaseHandler):52 def post(self):53 try:54 token = self.get_argument("cookie")55 userid = self.validate_token(token)56 if (userid is None):57 raise tornado.web.HTTPError(401, log_message="Invalid token passed to submit")58 input = self.request.body.decode()59 job = self.job_manager.submit_job(input)60 self.set_header("Qcloud-Server-Status", "OK")61 self.set_header("Qcloud-Server-Jobid", job.jobid)62 self.set_header("Qcloud-Server-Slurmid", job.slurmid)63 self.set_header("Qchemserv-Status", "OK")64 self.set_header("Qchemserv-Request", "submit")65 self.set_header("Qchemserv-Jobid", job.jobid)66 logging.info("Job %s submitted; UID=%s, JID=%s" % (job.slurmid, userid, job.jobid))67 except tornado.web.MissingArgumentError as e:68 msg = "Missing argument: " + str(e)69 self.set_header("Qcloud-Server-Message", msg)70 except Exception as e:71 msg = str(e);72 logging.error(msg)73 self.set_header("Qcloud-Server-Message", msg)74class ListFiles(BaseHandler):75 def prepare(self):76 try:77 job = self.get_job()78 #if (job.status != "DONE"):79 # raise Exception("Job not completed")80 filelist = job.files81 body = ''82 for f in filelist:83 body += ("%s\n" % f)84 self.write(body)85 self.set_header("Qcloud-Server-Status", "OK")86 self.set_header("Qcloud-Server-Jobid", job.jobid)87 self.set_header("Qchemserv-Status", "OK")88 self.set_header("Qchemserv-Request", "list")89 self.set_header("Qchemserv-Jobid", job.jobid)90 logging.info("Job list; JID=%s" % (job.jobid))91 except tornado.web.MissingArgumentError as e:92 msg = "Missing argument: " + str(e)93 self.set_header("Qcloud-Server-Message", msg)94 except Exception as e:95 msg = str(e);96 logging.error(msg)97 self.set_header("Qcloud-Server-Message", msg)98 def get(self):99 pass100 101 def post(self):102 pass103 104class Download(BaseHandler):105 def prepare(self):106 try:107 job = self.get_job()108 fname = self.get_argument("file")109 fpath = self.job_manager.get_job_filepath(job.jobid, fname)110 if (fpath is None):111 raise Exception("File not found " + fname)112 with open(fpath, 'r') as file:113 data = file.read()114 self.write(data)115 self.set_header("Qcloud-Server-Status", "OK")116 self.set_header("Qcloud-Server-Jobid", job.jobid)117 self.set_header("Qchemserv-Status", "OK")118 self.set_header("Qchemserv-Request", "download")119 self.set_header("Qchemserv-Jobid", job.jobid)120 logging.info("File download; JID=%s file=%s " % (job.jobid, fname))121 except tornado.web.MissingArgumentError as e:122 msg = "Missing argument: " + str(e)123 self.set_header("Qcloud-Server-Message", msg)124 except Exception as e:125 msg = str(e);126 logging.error(msg)127 self.set_header("Qcloud-Server-Message", msg)128 def get(self):129 pass130 def post(self):131 pass132class JobStatus(BaseHandler):133 def prepare(self):134 try:135 job = self.get_job()136 self.set_header("Qcloud-Server-Status", "OK")137 self.set_header("Qcloud-Server-Jobid", job.jobid)138 self.set_header("Qcloud-Server-Jobstatus", job.status)139 self.set_header("Qchemserv-Status", "OK")140 self.set_header("Qchemserv-Request", "status")141 self.set_header("Qchemserv-Jobid", job.jobid)142 self.set_header("Qchemserv-Jobstatus", job.status)143 logging.info("Job status; JID=%s status=%s" % (job.jobid, job.status))144 except tornado.web.MissingArgumentError as e:145 msg = "Missing argument: " + str(e)146 self.set_header("Qcloud-Server-Message", msg)147 except Exception as e:148 msg = str(e);149 logging.error(msg)150 self.set_header("Qcloud-Server-Message", msg)151 def get(self):152 pass153 def post(self):154 pass155class JobInfo(BaseHandler):156 def prepare(self):157 try:158 job = self.get_job()159 info = self.job_manager.get_job_info(job)160 self.write(info)161 self.set_header("Qcloud-Server-Status", "OK")162 self.set_header("Qcloud-Server-Jobid", job.jobid)163 self.set_header("Qcloud-Server-Jobstatus", job.status)164 self.set_header("Qchemserv-Status", "OK")165 self.set_header("Qchemserv-Request", "info")166 self.set_header("Qchemserv-Jobid", job.jobid)167 self.set_header("Qchemserv-Jobstatus", job.status)168 except tornado.web.MissingArgumentError as e:169 msg = "Missing argument: " + str(e)170 self.set_header("Qcloud-Server-Message", msg)171 except Exception as e:172 msg = str(e);173 logging.error(msg)174 self.set_header("Qcloud-Server-Message", msg)175 def get(self):176 pass177 def post(self):178 pass179class DeleteJob(BaseHandler):180 def prepare(self):181 try:182 job = self.get_job()183 184 self.job_manager.delete_job(job.jobid)185 self.set_header("Qcloud-Server-Status", "OK")186 self.set_header("Qcloud-Server-Jobid", job.jobid)187 self.set_header("Qchemserv-Status", "OK")188 self.set_header("Qchemserv-Request", "delete")189 self.set_header("Qchemserv-Jobid", job.jobid)190 logging.info("Job deleted; JID=%s" % (job.jobid))191 except tornado.web.MissingArgumentError as e:192 msg = "Missing argument: " + str(e)193 self.set_header("Qcloud-Server-Message", msg)194 except Exception as e:195 msg = str(e);196 logging.error(msg)197 self.set_header("Qcloud-Server-Message", msg)198 def get(self):199 pass200 201 def post(self):202 pass203 204class ComputeServer(tornado.web.Application):205 def __init__(self, config):206 job_manager = JobManager(config)207 # Authentication server details208 host = config.get("authentication", "host")209 port = config.get("authentication", "port")210 auth_url = "http://" + host + ":" + port211 args = dict( authentication_url = auth_url,...
ehos_rest.py
Source: ehos_rest.py
...13 self.render('index.html', title='My title', message='Hello world')14class Clouds (tornado.BaseHandler):15 def set_default_headers(self):16 #print( "setting headers!!!")17 #self.set_header("Access-Control-Allow-Origin", "*")18 #self.set_header("Access-Control-Allow-Headers", "x-requested-with")19 #self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')20 self.set_header("Content-Type", 'application/json; charset="utf-8"')21 def get(self, id:str=None):22 arguments = self._arguments()23 arguments = self._valid_arguments(arguments, ['name'])24 if id is not None:25 arguments[ 'id' ] = id26 #pp.pprint( arguments )27 data = db.clouds(**arguments)28 #print( 'In clouds @@@@ ')29 self.set_json_header()30 self.send_response( data )31class Nodes (tornado.BaseHandler):32 def set_default_headers(self):33 #print( "setting headers!!!")34 self.set_header("Access-Control-Allow-Origin", "*")35 self.set_header("Access-Control-Allow-Headers", "x-requested-with")36 self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')37 def get(self, id:int=None):38 arguments = self._arguments()39 arguments = self._valid_arguments(arguments, ['cloud_id', 'node_state_id', 'vm_state_id'])40 if id is not None:41 arguments[ 'id' ] = id42 #pp.pprint( arguments )43 data = db.nodes(**arguments)44 #print( 'In clouds @@@@ ')45 self.set_json_header()46 self.send_response( data )47class NodeStatus(tornado.BaseHandler):48 def set_default_headers(self):49 #print( "setting headers!!!")50 self.set_header("Access-Control-Allow-Origin", "*")51 self.set_header("Access-Control-Allow-Headers", "x-requested-with")52 self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')53 def get(self):54 data = db.vm_states()55 self.set_json_header()56 self.send_response( data )57class NodeStates(tornado.BaseHandler):58 def set_default_headers(self):59 #print( "setting headers!!!")60 self.set_header("Access-Control-Allow-Origin", "*")61 self.set_header("Access-Control-Allow-Headers", "x-requested-with")62 self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')63 def get(self):64 data = db.node_states()65 self.set_json_header()66 self.send_response( data )67class Settings(tornado.BaseHandler):68 def set_default_headers(self):69 #print( "setting headers!!!")70 self.set_header("Access-Control-Allow-Origin", "*")71 #self.set_header("Access-Control-Allow-Headers", "x-requested-with")72 self.set_header('Access-Control-Allow-Methods', 'GET, PATCH, OPTIONS')73 self.set_header('Access-Control-Allow-Headers', '*')74 self.set_header('Access-Control-Allow-Headers',75 'Content-Type, Access-Control-Allow-Origin, Access-Control-Allow-Headers, X-Requested-By, Access-Control-Allow-Methods')76 def get(self, id:int=None):77 print( 'get...')78 arguments = self._arguments()79 #arguments = self._valid_arguments(arguments, ['cloud_id', 'node_state_id', 'vm_state_id'])80 #if id is not None:81 # arguments[ 'id' ] = id82 #pp.pprint( arguments )83 data = db.settings_flat(**arguments)84 data = list( filter( lambda x:'clouds' not in x['name'], data ))85 data = sorted( data, key=lambda k: k['name'] )86 pp.pprint( data )87 #print( 'In clouds @@@@ ')88 self.set_json_header()...
server_musci.py
Source: server_musci.py
...6 r_f.close()7 return bit8class i_index(tornado.web.RequestHandler):9 # def set_default_headers(self):10 # self.set_header("Access-Control-Allow-Origin", "*")11 # self.set_header("Access-Control-Allow-Headers", "Content-Type")12 # self.set_header("Access-Control-Allow-Methods", "POST,GET,OPTIONS")13 # self.set_header ('Content-Type', 'audio/mpeg')14 def get(self):15 filename = "/Users/flqy/Desktop/PythonProject/mamamoo/Be.mp3"16 # self.set_header ('Accept-Ranges', 'bytes')17 self.set_header ('Content-Type', 'audio/mpeg')18 # Connection: keep-alive19 self.set_header ('Content-Disposition', 'inline; filename=\"Be.mp3\"')20 self.set_header ('Connection', 'keep-alive')21 print("请æ±æ¬å°çèµæº")22 with open(filename, 'rb') as f:23 while True:24 data = f.read(1024)25 if not data:26 break27 self.write(data)28 f.close()29 self.finish()30 pass31class ii_index(tornado.web.RequestHandler):32 # def set_default_headers(self):33 # self.set_header("Access-Control-Allow-Origin", "*")34 # self.set_header("Access-Control-Allow-Headers", "Content-Type")35 # self.set_header("Access-Control-Allow-Methods", "POST,GET,OPTIONS")36 def get(self):37 bit = readfile("/Users/flqy/Desktop/PythonProject/mamamoo/gogobebe.mp3")38 39 self.set_header ('Content-Disposition', 'inline; filename=gogobebe.mp3')40 self.set_header ('Content-Type', 'audio/mpeg')41 self.set_header ('Connection', 'keep-alive')42 self.write(bit)43 self.finish()44 pass45class iii_index(tornado.web.RequestHandler):46 # def set_default_headers(self):47 # self.set_header("Access-Control-Allow-Origin", "*")48 # self.set_header("Access-Control-Allow-Headers", "Content-Type")49 # self.set_header("Access-Control-Allow-Methods", "POST,GET,OPTIONS")50 51 def get(self):52 bit = readfile("/Users/flqy/Desktop/PythonProject/mamamoo/maria.mp3")53 # self.set_header('Content-Type', 'audio/mpeg; charset=utf-8')54 self.set_header('Content-Type', 'text/plain; charset=utf-8')55 56 self.set_header ('Content-Disposition', 'inline; filename=maria.mp3')57 # self.set_header ('Connection', 'keep-alive')58 59 self.write(bit)60 self.finish()61 pass62class iv_index(tornado.web.RequestHandler):63 64 def get(self):65 print("请æ±æåä¸é¦æ")66 bit = readfile("/Users/flqy/Desktop/PythonProject/mamamoo/starry night.mp3")67 self.set_header ('Connection', 'keep-alive')68 self.set_header ('Content-Type', 'text/plain; charset=utf-8')...
app.py
Source: app.py
1import random2from bottle import route, run, template, HTTPError, response3@route('/302-donotcache/<euid>')4def donotcache(euid):5 response.set_header('Cache-Control', 'private, max-age=0, no-cache')6 response.set_header('Expires', 'max-age=0')7 response.set_header('ETag', 'str(random.random())')8 location = 'http://lorempixel.com/100/100/'9 response.set_header('Location', location)10 response.status = 30211 return 'Found'12@route('/302-nocacheheaders/<euid>')13def nocacheheaders(euid):14 location = 'http://lorempixel.com/100/100/'15 response.set_header('Location', location)16 response.status = 30217 return 'Found'18@route('/302-cacheeverything/<euid>')19def cacheeverything(euid):20 response.set_header('Cache-Control', 'max-age=86100')21 response.set_header('Expires', 'max-age=86100')22 response.set_header('ETag', 'everything')23 location = 'http://lorempixel.com/100/100/'24 response.set_header('Location', location)25 response.status = 30226 return 'Found'27@route('/301/<euid>')28def permanent(euid):29 location = 'http://lorempixel.com/100/100/'30 response.set_header('Location', location)31 response.status = 30132 return 'Moved Permanently'...
Check out the latest blogs from LambdaTest on this topic:
Hey Testers! We know it’s been tough out there at this time when the pandemic is far from gone and remote working has become the new normal. Regardless of all the hurdles, we are continually working to bring more features on-board for a seamless cross-browser testing experience.
Manual cross browser testing is neither efficient nor scalable as it will take ages to test on all permutations & combinations of browsers, operating systems, and their versions. Like every developer, I have also gone through that ‘I can do it all phase’. But if you are stuck validating your code changes over hundreds of browsers and OS combinations then your release window is going to look even shorter than it already is. This is why automated browser testing can be pivotal for modern-day release cycles as it speeds up the entire process of cross browser compatibility.
With new-age project development methodologies like Agile and DevOps slowly replacing the old-age waterfall model, the demand for testing is increasing in the industry. Testers are now working together with the developers and automation testing is vastly replacing manual testing in many ways. If you are new to the domain of automation testing, the organization that just hired you, will expect you to be fast, think out of the box, and able to detect bugs or deliver solutions which no one thought of. But with just basic knowledge of testing, how can you be that successful test automation engineer who is different from their predecessors? What are the skills to become a successful automation tester in 2019? Let’s find out.
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
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!!