+ create=create,
+ help=helpHandler)
+
+def printHeaders(headers):
+ for key, value in headers.iteritems():
+ print '%s: %s' % (key, value)
+ print
+
+
+def getUser():
+ """Return the current user based on the SSL environment variables"""
+ if 'SSL_CLIENT_S_DN_Email' in os.environ:
+ username = os.environ['SSL_CLIENT_S_DN_Email'].split("@")[0]
+ return User(username, os.environ['SSL_CLIENT_S_DN_Email'])
+ else:
+ return User('moo', 'nobody')
+
+def main(operation, user, fields):
+ fun = mapping.get(operation, badOperation)
+
+ if fun not in (helpHandler, ):
+ connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
+ try:
+ output = fun(u, fields)
+
+ headers = dict(DEFAULT_HEADERS)
+ if isinstance(output, tuple):
+ new_headers, output = output
+ headers.update(new_headers)
+
+ e = revertStandardError()
+ if e:
+ output.addError(e)
+ printHeaders(headers)
+ print output
+ except Exception, err:
+ if not fields.has_key('js'):
+ if isinstance(err, CodeError):
+ print 'Content-Type: text/html\n'
+ e = revertStandardError()
+ print error(operation, u, fields, err, e)
+ sys.exit(1)
+ if isinstance(err, InvalidInput):
+ print 'Content-Type: text/html\n'
+ e = revertStandardError()
+ print invalidInput(operation, u, fields, err, e)
+ sys.exit(1)
+ print 'Content-Type: text/plain\n'
+ print 'Uh-oh! We experienced an error.'
+ print 'Please email sipb-xen@mit.edu with the contents of this page.'
+ print '----'
+ e = revertStandardError()
+ print e
+ print '----'
+ raise