pypi / pypi.cgi

# $Id: pypi.cgi 667 2009-11-05 05:55:15Z richard $

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.'
# 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):

# Now do the actual CGI handling
    sys.path.insert(0, '/data/pypi/src/pypi')
    from webui import WebUI
    import config
    cfg = config.Config('/data/pypi/config.ini')
    request = RequestWrapper(cfg, sys.stdin, sys.stdout)
    handler = WebUI(request, os.environ)
except SystemExit:
    sys.stdout.write('Status: 500 Internal Server Error\r\n')
    sys.stdout.write('Content-Type: text/html\r\n\r\n')
    s = StringIO.StringIO()
    traceback.print_exc(None, s)

# vim: set filetype=python ts=4 sw=4 et si
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.