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.cgi
executable file
·57 lines (52 loc) · 1.76 KB
/
pypi.cgi
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
#!/usr/bin/python
#
# $Id$
import sys, os, cgi, StringIO, traceback
from BaseHTTPServer import BaseHTTPRequestHandler, DEFAULT_ERROR_MESSAGE
# turn this on if you need to do server maintenance
if 0:
sys.stdout.write('Status: 503 Server down for maintenance\r\n')
sys.stdout.write('Content-Type: text/plain\r\n\r\n')
print 'The Cheese Shop server is down for a short time for maintenance.'
print 'Please try to connect later.'
sys.exit(0)
#
# Provide interface to CGI HTTP response handling
#
class RequestWrapper:
'''Used to make the CGI server look like a BaseHTTPRequestHandler
'''
def __init__(self, config, rfile, wfile):
self.wfile = wfile
self.rfile = rfile
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")
#
# Now do the actual CGI handling
#
try:
sys.path.insert(0, '/data/pypi/src/pypi')
from webui import WebUI
import config
cfg = config.Config(os.environ.get("PYPI_COFNIG", "config.ini"))
request = RequestWrapper(cfg, sys.stdin, sys.stdout)
handler = WebUI(request, os.environ)
handler.run()
except SystemExit:
pass
except:
sys.stdout.write('Status: 500 Internal Server Error\r\n')
sys.stdout.write('Content-Type: text/html\r\n\r\n')
sys.stdout.write("<pre>")
s = StringIO.StringIO()
traceback.print_exc(None, s)
sys.stdout.write(cgi.escape(s.getvalue()))
sys.stdout.write("</pre>\n")
# vim: set filetype=python ts=4 sw=4 et si