# -*- python -*- # -*- coding: utf8 -*- from paste.request import parse_formvars import pkg_resources import simplejson from ConfigParser import ConfigParser from urllib import quote_plus my_config = ConfigParser() my_config.readfp(pkg_resources.resource_stream(__name__, 'ddportfolio.ini')) def build_urls(fields): result = {} qfields = dict([(key, quote_plus(fields[key])) for key in fields]) for section in my_config.sections(): if my_config.has_option(section, 'urls'): for url in my_config.get(section, 'urls').split(','): if my_config.has_option(section, url + '.pattern'): try: result[section + '.' + url] = \ my_config.get(section, url + '.pattern', False, qfields) except Exception, e: print "unable to parse %s: %s" % (my_config.get(section, url + '.pattern', True), e) return result def application(environ, start_response): fields = parse_formvars(environ) if environ['REQUEST_METHOD'] == 'POST': data = build_urls(fields) if ('mode' in fields and fields['mode'] == 'json'): start_response('200 OK', [('content-type', 'text/json')]) return [simplejson.dumps(data)] else: start_response('200 OK', [('content-type', 'text/html')]) return [''' Debian Developer Portfolio '] else: start_response('200 OK', [('content-type', 'text/html')]) return [''' Debian Developer Portfolio
Debian Developer Portfolio







'''] if __name__ == '__main__': from paste import httpserver httpserver.serve(application, host='127.0.0.1', port='8080')