This repository has been archived by the owner on May 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
pypi.fcgi
executable file
·66 lines (61 loc) · 1.88 KB
/
pypi.fcgi
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
import thfcgi, os, sys, StringIO, traceback, cgi, syslog
#
# Provide interface to CGI HTTP response handling
#
class RequestWrapper:
'''Used to make the FCGI server look like a BaseHTTPRequestHandler
'''
def __init__(self, config, req):
self.wfile = req.out
self.rfile = req.stdin
self.config = config
def send_response(self, code, message=''):
self.wfile.write('Status: %s %s\r\n'%(code, message))
def send_header(self, keyword, value):
self.wfile.write("%s: %s\r\n" % (keyword, value))
def set_content_type(self, content_type):
self.send_header('Content-Type', content_type)
def end_headers(self):
self.wfile.write("\r\n")
def handle_request(req, env):
try:
import store
store.keep_conn = True
from webui import WebUI
request = RequestWrapper(cfg, req)
handler = WebUI(request, env)
handler.run()
except SystemExit:
pass
except:
req.out.write('Status: 500 Internal Server Error\r\n')
req.out.write('Content-Type: text/html\r\n\r\n')
req.out.write("<pre>")
s = StringIO.StringIO()
traceback.print_exc(None, s)
req.out.write(cgi.escape(s.getvalue()))
req.out.write("</pre>\n")
req.finish()
#
# Now do the actual CGI handling
#
os.umask(002) # make directories group-writable
prefix = os.path.dirname(__file__)
sys.path.insert(0, prefix)
import config
cfg = config.Config('/data/pypi/config.ini')
fcg = thfcgi.FCGI(handle_request,
max_requests=-1,
backlog=50,
max_threads=1)
try:
try:
fcg.run()
syslog.syslog("pypi.fcgi: run completed")
except:
import traceback
syslog.syslog(''.join(traceback.format_exception(*sys.exc_info())))
raise
finally:
syslog.syslog("pypi.fcgi: exiting")