How to use _do_redirect method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...20import socket21import sys22import threading23import tensorflow as tf24def _do_redirect(handler, location):25 handler.send_response(301)26 handler.send_header("Location", location)27 handler.end_headers()28def _do_documentation(handler):29 handler.send_response(200)30 handler.end_headers()31 handler.wfile.write(b"Here is some documentation.")32def start_smart_module_server(download_url):33 """Serve documentation and module requests at the same URL."""34 # pylint:disable=g-import-not-at-top35 if sys.version_info[0] == 2:36 import BaseHTTPServer37 import SimpleHTTPServer38 import urlparse39 class HTTPServerV6(BaseHTTPServer.HTTPServer):40 address_family = socket.AF_INET641 class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):42 def do_GET(self):43 parsed_url = urlparse.urlparse(self.path)44 qs = urlparse.parse_qs(parsed_url.query)45 if qs["tf-hub-format"][0] == "compressed":46 _do_redirect(self, download_url)47 else:48 _do_documentation(self)49 server = HTTPServerV6(("", 0), RequestHandler)50 server_port = server.server_port51 else:52 import http.server53 import socketserver54 import urllib55 class RequestHandler(http.server.SimpleHTTPRequestHandler):56 def do_GET(self):57 parsed_url = urllib.parse.urlparse(self.path)58 qs = urllib.parse.parse_qs(parsed_url.query)59 if qs["tf-hub-format"][0] == "compressed":60 _do_redirect(self, download_url)61 else:62 _do_documentation(self)63 server = socketserver.TCPServer(("", 0), RequestHandler)64 _, server_port = server.server_address65 # pylint:disable=g-import-not-at-top66 thread = threading.Thread(target=server.serve_forever)67 thread.daemon = True68 thread.start()69 return server_port70def start_http_server(redirect=None):71 """Returns the port of the newly started HTTP server."""72 # Start HTTP server to serve TAR files.73 # pylint:disable=g-import-not-at-top74 if sys.version_info[0] == 2:75 import BaseHTTPServer76 import SimpleHTTPServer77 class HTTPServerV6(BaseHTTPServer.HTTPServer):78 address_family = socket.AF_INET679 class RedirectHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):80 def do_GET(self):81 _do_redirect(self, redirect)82 server = HTTPServerV6(("", 0), RedirectHandler if redirect else83 SimpleHTTPServer.SimpleHTTPRequestHandler)84 server_port = server.server_port85 else:86 import http.server87 import socketserver88 class RedirectHandler(http.server.SimpleHTTPRequestHandler):89 def do_GET(self):90 _do_redirect(self, redirect)91 server = socketserver.TCPServer(("", 0), RedirectHandler if redirect else92 http.server.SimpleHTTPRequestHandler)93 _, server_port = server.server_address94 # pylint:disable=g-import-not-at-top95 thread = threading.Thread(target=server.serve_forever)96 thread.daemon = True97 thread.start()98 return server_port99def test_srcdir():100 """Returns the path where to look for test data files."""101 if "test_srcdir" in return["test_srcdir"].value103 elif "TEST_SRCDIR" in os.environ:104 return os.environ["TEST_SRCDIR"]...

Full Screen

Full Screen

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:


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

Run autotest 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?