-
Notifications
You must be signed in to change notification settings - Fork 15
/
server.py
executable file
·34 lines (27 loc) · 975 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
import sys, os
import CGIHTTPServer, BaseHTTPServer
class CGIExtHTTPRequestHandler(CGIHTTPServer.CGIHTTPRequestHandler):
def is_cgi(self):
base = self.path
query = ''
i = base.find('?')
if i != -1:
query = base[i:]
base = base[:i]
if not base.lower().endswith('.cgi'):
return False
[parentDirs, script] = base.rsplit('/', 1)
self.cgi_info = (parentDirs, script+query)
return True
def run_server(port):
dirName = os.getcwd()
blanks = dirName.count(' ')
if 0 < blanks: # server cannot handle blanks in path names
print("The path to this directory contains spaces")
return
server_addr = ('localhost', port)
cgiServer = BaseHTTPServer.HTTPServer(server_addr, CGIExtHTTPRequestHandler)
sys.stderr.write('Localhost CGI server started : %s\n.'%port)
cgiServer.serve_forever()
run_server(8000)