def main(): class MyRequestHandler(CGIHTTPServer.CGIHTTPRequestHandler): def _is_cgi(self): path = self.path x = '/cgi-bin/htmlhelp.cgi' i = len(x) if path[:i] == x and (not path[i:] or path[i] == '/'): self.cgi_info = '', path[1:i] return 1 return 0 CGIHTTPServer.test(MyRequestHandler)
#!/usr/bin/env python # _* config: utf-8 _*_ import CGIHTTPServer CGIHTTPServer.test()
#!/usr/bin/env python # coding:utf-8 '''CGI--通用网关接口''' import CGIHTTPServer CGIHTTPServer.test() '''默认8000,改端口 python cgihttpd.py 8080'''
break head, tail = head[:i], head[i:] + tail temp = self.translate_path(head) if os.path.isdir(temp): for index in self.indices: if os.path.exists(os.path.join(temp, index)): head = posixpath.join(head, index) break ctype = self.guess_type(head) if ctype in self.actions: os.environ['REDIRECT_STATUS'] = '200' head = self.actions[ctype] + head self.path = head + tail + query def translate_path(self, path): path = posixpath.normpath(urllib.unquote(path)) n = len(self.aliases) for i in range(n): url, dir = self.aliases[n-i-1] length = len(url) if path[:length] == url: return dir + path[length:] return '' if __name__ == '__main__': CGIHTTPServer.test(PHPHTTPRequestHandler)
def test(HandlerClass = PTestCGIHandler, ServerClass = BaseHTTPServer.HTTPServer): CGIHTTPServer.test(HandlerClass, ServerClass)
# -*- coding: utf-8 -*- import CGIHTTPServer if __name__ == '__main__': print('あああ') CGIHTTPServer.test();
def server(): CGIHTTPServer.test()
def test(HandlerClass = SymfonyHTTPRequestHandler, ServerClass = HTTPServer): CGIHTTPServer.test(HandlerClass, ServerClass)
break head, tail = head[:i], head[i:] + tail temp = self.translate_path(head) if os.path.isdir(temp): for index in self.indices: if os.path.exists(os.path.join(temp, index)): head = posixpath.join(head, index) break ctype = self.guess_type(head) if ctype in self.actions: os.environ['REDIRECT_STATUS'] = '200' head = self.actions[ctype] + head self.path = head + tail + query def translate_path(self, path): path = posixpath.normpath(urllib.unquote(path)) n = len(self.aliases) for i in range(n): url, dir = self.aliases[n - i - 1] length = len(url) if path[:length] == url: return dir + path[length:] return '' if __name__ == '__main__': CGIHTTPServer.test(PHPHTTPRequestHandler)
#!/usr/bin/env python import os import CGIHTTPServer class PyCGIHandler(CGIHTTPServer.CGIHTTPRequestHandler): def is_cgi(self): splitpath = CGIHTTPServer._url_collapse_path_split(self.path) script_query = splitpath[1].split("?", 1) if script_query[0].endswith(".py"): if splitpath[0].startswith("/"): # Workaround for some weirdness with how CGIHTTPServer # computes the SCRIPT_NAME environment variable. splitpath = list(splitpath) splitpath[0] = '' splitpath = tuple(splitpath) self.cgi_info = splitpath return True return False os.chdir("www") CGIHTTPServer.test(HandlerClass=PyCGIHandler)