| OLD | NEW |
| 1 """HTTP server classes. | 1 """HTTP server classes. |
| 2 | 2 |
| 3 Note: BaseHTTPRequestHandler doesn't implement any HTTP request; see | 3 Note: BaseHTTPRequestHandler doesn't implement any HTTP request; see |
| 4 SimpleHTTPRequestHandler for simple implementations of GET, HEAD and POST, | 4 SimpleHTTPRequestHandler for simple implementations of GET, HEAD and POST, |
| 5 and CGIHTTPRequestHandler for CGI scripts. | 5 and CGIHTTPRequestHandler for CGI scripts. |
| 6 | 6 |
| 7 It does, however, optionally implement HTTP/1.1 persistent connections, | 7 It does, however, optionally implement HTTP/1.1 persistent connections, |
| 8 as of version 0.3. | 8 as of version 0.3. |
| 9 | 9 |
| 10 Notes on CGIHTTPRequestHandler | 10 Notes on CGIHTTPRequestHandler |
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 | 955 |
| 956 If any exception is raised, the caller should assume that | 956 If any exception is raised, the caller should assume that |
| 957 self.path was rejected as invalid and act accordingly. | 957 self.path was rejected as invalid and act accordingly. |
| 958 | 958 |
| 959 The default implementation tests whether the normalized url | 959 The default implementation tests whether the normalized url |
| 960 path begins with one of the strings in self.cgi_directories | 960 path begins with one of the strings in self.cgi_directories |
| 961 (and the next character is a '/' or the end of the string). | 961 (and the next character is a '/' or the end of the string). |
| 962 | 962 |
| 963 """ | 963 """ |
| 964 collapsed_path = _url_collapse_path(self.path) | 964 collapsed_path = _url_collapse_path(self.path) |
| 965 dir_sep = collapsed_path.find('/', 1) | 965 for cgi_path in self.cgi_directories: |
| 966 head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:] | 966 if cgi_path == collapsed_path: |
| 967 if head in self.cgi_directories: | 967 self.cgi_info = (cgi_path, '') |
| 968 self.cgi_info = head, tail | 968 return True |
| 969 return True | 969 elif (collapsed_path.startswith(cgi_path) |
| 970 return False | 970 and collapsed_path[len(cgi_path)] == '/'): |
| 971 | 971 self.cgi_info = cgi_path, collapsed_path[len(cgi_path) + 1:] |
| 972 return True |
| 972 | 973 |
| 973 cgi_directories = ['/cgi-bin', '/htbin'] | 974 cgi_directories = ['/cgi-bin', '/htbin'] |
| 974 | 975 |
| 975 def is_executable(self, path): | 976 def is_executable(self, path): |
| 976 """Test whether argument path is an executable file.""" | 977 """Test whether argument path is an executable file.""" |
| 977 return executable(path) | 978 return executable(path) |
| 978 | 979 |
| 979 def is_python(self, path): | 980 def is_python(self, path): |
| 980 """Test whether argument path is a Python script.""" | 981 """Test whether argument path is a Python script.""" |
| 981 head, tail = os.path.splitext(path) | 982 head, tail = os.path.splitext(path) |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 help='Run as CGI Server') | 1203 help='Run as CGI Server') |
| 1203 parser.add_argument('port', action='store', | 1204 parser.add_argument('port', action='store', |
| 1204 default=8000, type=int, | 1205 default=8000, type=int, |
| 1205 nargs='?', | 1206 nargs='?', |
| 1206 help='Specify alternate port [default: 8000]') | 1207 help='Specify alternate port [default: 8000]') |
| 1207 args = parser.parse_args() | 1208 args = parser.parse_args() |
| 1208 if args.cgi: | 1209 if args.cgi: |
| 1209 test(HandlerClass=CGIHTTPRequestHandler, port=args.port) | 1210 test(HandlerClass=CGIHTTPRequestHandler, port=args.port) |
| 1210 else: | 1211 else: |
| 1211 test(HandlerClass=SimpleHTTPRequestHandler, port=args.port) | 1212 test(HandlerClass=SimpleHTTPRequestHandler, port=args.port) |
| OLD | NEW |