def do_GET(self): """This method is called whenever the client invokes the GET method in the HTTP protocol request""" termcolor.cprint(self.requestline, 'green') termcolor.cprint(self.path, 'blue') o = urlparse(self.path) path_name = o.path arguments = parse_qs(o.query) print("Resource requested: ", path_name) print("Parameters: ", arguments) context = {} if path_name == '/': context["n_sequences"] = len(list_sequences) context["list_genes"] = list_genes contents = su.read_template_html_file('./index.html').render( context=context) elif path_name == "/test": contents = su.read_template_html_file("./test.html").render() elif path_name == "/ping": contents = su.read_template_html_file("./ping.html").render() elif path_name == "/get": number_sequence = arguments["sequence"][0] contents = su.get(list_sequences, number_sequence) elif path_name == "/gene": gene = arguments["gene"][0] contents = su.gene(gene) elif path_name == "/operation": sequence = arguments["sequence"][0] calculation = arguments["calculation"][0] if calculation == "Info": contents = su.info(sequence) elif calculation == "Comp": contents = su.comp(sequence) elif calculation == "Rev": contents = su.rev(sequence) else: contents = su.read_template_html_file('./Error.html').render() else: contents = su.read_template_html_file("./Error.html").render() self.send_response(200) # -- Status line: OK! # Define the content-type header: self.send_header('Content-Type', 'text/html') self.send_header('Content-Length', len(contents.encode())) # The header is finished self.end_headers() # Send the response message self.wfile.write(contents.encode()) return
def do_GET(self): termcolor.cprint(self.requestline, 'green') termcolor.cprint(self.path, 'blue') o = urlparse(self.path) path_name = o.path arguments = parse_qs(o.query) print("Resource requested: ", path_name) print("Parameters: ", arguments) # IN this simple server version: # We are NOT processing the client's request # It is a happy server: It always returns a message saying # that everything is ok context = {} # Message to send back to the client if path_name == '/': context["n_sequences"] = len(list_sequences) context["list_genes"] = list_genes contents = su.read_template_html_file('./html/index.html').render( context=context) elif path_name == "/ping": contents = su.read_template_html_file("./html/ping.html").render() elif path_name == "/get": number_sequence = arguments["sequence"][0] contents = su.get(list_sequences, number_sequence) elif path_name == "/gene": gene = arguments["gene"][0] contents = su.gene(gene) elif path_name == "/operation": sequence = arguments['sequence'][0] calculation = arguments['calculation'][0] if calculation == 'Info': contents = su.info(sequence) elif calculation == 'Comp': contents = su.comp(sequence) elif calculation == 'Rev': contents = su.rev(sequence) else: contents = su.read_template_html_file( "./html/ERROR.html").render() else: contents = su.read_template_html_file("./html/ERROR.html").render() self.send_response(200) self.send_header('Content-Type', 'text/html') self.send_header('Content-Length', len(contents.encode())) self.end_headers() self.wfile.write(contents.encode()) return
formatted_msg = Server_utils.format_command(msg) formatted_msg = formatted_msg.split(" ") if len(formatted_msg) == 1: command = formatted_msg[0] else: command = formatted_msg[0] + '"' argument = '"' + formatted_msg[1] if command == '"PING"': Server_utils.ping(cs) elif command == '"GET"': Server_utils.get(list_sequences, cs, argument) elif command == '"INFO"': Server_utils.info(argument, cs) elif command == '"COMP"': Server_utils.comp(argument, cs) elif command == '"REV"': Server_utils.rev(argument, cs) elif command == '"GENE"': Server_utils.gene(argument, cs) else: response = "Not available command" termcolor.cprint(response, "red") cs.send(response.encode())
formatted_msg = Server_utils.format_command(msg) formatted_msg = formatted_msg.split(" ") if len(formatted_msg) == 1: command = formatted_msg[0] else: command = formatted_msg[0] argument = formatted_msg[1] # print(argument) if command == "PING": Server_utils.ping() elif command == "GET": Server_utils.get(list_sequences, cs, argument) elif command == "INFO": Server_utils.info(cs, argument) elif command == "COMP": Server_utils.comp(Seq, argument) elif command == "REV": Server_utils.rev(Seq, argument) elif command == "GENE": Server_utils.gene(Seq, argument) else: response = "Not available command" termcolor.cprint(response, "red") cs.send(response.encode()) cs.close()
def do_GET(self): global contents colorama.init(strip="False") """This method is called whenever the client invokes the GET method in the HTTP protocol request""" # Print the request line termcolor.cprint(self.requestline, 'green') termcolor.cprint(self.path, 'blue') o = urlparse(self.path) path_name = o.path arguments = parse_qs(o.query) print("Resource requested: ", path_name) print("Parameters: ", arguments) # IN this simple server version: # We are NOT processing the client's request # It is a happy server: It always returns a message saying # that everything is ok # Message to send back to the client context = {} if path_name == "/": context["n_seq"] = len(LIST_SEQ) context["list_genes"] = LIST_GENE context["operation_list"] = OPERATION_LIST contents = su.read_template_html_file(HTML_ASSETS + "index.html").render(context=context) elif path_name == "/ping": contents = su.read_template_html_file(HTML_ASSETS + "ping.html").render() elif path_name == "/get": number_seq = arguments["sequence"][0] contents = su.get(LIST_SEQ, number_seq) elif path_name == "/gene": gene = arguments["gene"][0] contents = su.gene(gene) elif path_name == "/operation": sequence = arguments["sequence"][0] operation = arguments["calculation"][0] if operation == "info": contents = su.info(sequence) elif operation == "comp": contents = su.comp(sequence) elif operation == "rev": contents = su.rev(sequence) else: contents = su.read_template_html_file(HTML + "ERROR.html").render() # Generating the response message self.send_response(200) # -- Status line: OK! length = len(contents.encode()) # Define the content-type header: self.send_header('Content-Type', 'text/html') self.send_header('Content-Length', str(length)) # The header is finished self.end_headers() # Send the response message self.wfile.write(contents.encode()) return
ls.close() exit() msg_raw = cs.recv(2048) msg = msg_raw.decode() formatted_msg = su.format_command(msg) #print(formatted_msg) formatted_msg = formatted_msg.split(' ') if len(formatted_msg) == 1: command = formatted_msg[0] else: command = formatted_msg[0] argument = formatted_msg[1] if command == 'PING': su.ping(cs) elif command == 'GET': su.get(cs, list_sequences, argument) elif command == 'INFO': su.info(cs, argument) elif command == 'COMP': su.comp(cs, argument) elif command == 'REV': su.rev(cs, argument) elif command == 'GENE': su.gene(cs, argument) else: response = 'Not available command.' cs.send(str(response).encode()) cs.close()