How to use set_header method in tappy

Best Python code snippet using tappy_python

web_server.py

Source: web_server.py Github

copy

Full Screen

...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,...

Full Screen

Full Screen

ehos_rest.py

Source: ehos_rest.py Github

copy

Full Screen

...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()...

Full Screen

Full Screen

server_musci.py

Source: server_musci.py Github

copy

Full Screen

...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')...

Full Screen

Full Screen

app.py

Source: app.py Github

copy

Full Screen

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'...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

What exactly do Scrum Masters perform throughout the course of a typical day

Many theoretical descriptions explain the role of the Scrum Master as a vital member of the Scrum team. However, these descriptions do not provide an honest answer to the fundamental question: “What are the day-to-day activities of a Scrum Master?”

Starting &#038; growing a QA Testing career

The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.

Feeding your QA Career – Developing Instinctive &#038; Practical Skills

The QA testing profession requires both educational and long-term or experience-based learning. One can learn the basics from certification courses and exams, boot camp courses, and college-level courses where available. However, developing instinctive and practical skills works best when built with work experience.

Testing in Production: A Detailed Guide

When most firms employed a waterfall development model, it was widely joked about in the industry that Google kept its products in beta forever. Google has been a pioneer in making the case for in-production testing. Traditionally, before a build could go live, a tester was responsible for testing all scenarios, both defined and extempore, in a testing environment. However, this concept is evolving on multiple fronts today. For example, the tester is no longer testing alone. Developers, designers, build engineers, other stakeholders, and end users, both inside and outside the product team, are testing the product and providing feedback.

What will come after “agile”?

I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tappy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful