# HG changeset patch # User Jeff Hammel # Date 1349910116 25200 # Node ID b3fd8f98df32390a3d4cc40fc632b40357846dbc initial stub diff -r 000000000000 -r b3fd8f98df32 README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Wed Oct 10 16:01:56 2012 -0700 @@ -0,0 +1,8 @@ +dogdish +---------- + +dogfooding for b2g upderver + +-- + +http://update.boot2gecko.org/nightly/update.xml \ No newline at end of file diff -r 000000000000 -r b3fd8f98df32 dogdish/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dogdish/__init__.py Wed Oct 10 16:01:56 2012 -0700 @@ -0,0 +1,1 @@ +# diff -r 000000000000 -r b3fd8f98df32 dogdish/dispatcher.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dogdish/dispatcher.py Wed Oct 10 16:01:56 2012 -0700 @@ -0,0 +1,95 @@ +""" +request dispatcher +""" + +from webob import Request, exc + +from cgi import escape +from urlparse import urlparse +from webob import Response, exc + +class Handler(object): + def __init__(self, request): + self.request = request + self.application_path = urlparse(request.application_url)[2] + + def link(self, path=(), permanant=False): + if isinstance(path, basestring): + path = [ path ] + path = [ i.strip('/') for i in path ] + if permanant: + application_url = [ self.request.application_url ] + else: + application_url = [ self.application_path ] + path = application_url + path + return '/'.join(path) + + def redirect(self, location): + raise exc.HTTPSeeOther(location=location) + +class Get(Handler): + + body = """ + + + + +""" + + @classmethod + def match(cls, request): + return request.method == 'GET' + + def __call__(self): + name = self.request.GET.get('name', 'world') + retval = """
Hello, +
""" + return Response(content_type='text/html', + body=retval % name) + +class Dispatcher(object): + + ### class level variables + defaults = {} + + def __init__(self, **kw): + for key in self.defaults: + setattr(self, key, kw.get(key, self.defaults[key])) + self.handlers = [ Get ] + if self.app: + assert hasattr(self.app, '__call__') + + ### methods dealing with HTTP + def __call__(self, environ, start_response): + request = Request(environ) + for h in self.handlers: + if h.match(request): + handler = h(request) + break + else: + if self.app: + return self.app(environ, start_response) + handler = exc.HTTPNotFound + res = handler() + return res(environ, start_response) + +def main(args=sys.argv[1:]): + """CLI entry point""" + + import optparse + from wsgiref import simple_server + + parser = optparse.OptionParser() + + parser.add_option('-p', '--port', dest='port', + default=8080, type='int', + help="port to serve on") + options, args = parser.parse_args() + + dispatcher = Dispatcher() + + server = simple_server.make_server(host='0.0.0.0', port=options.port, app=app) + server.serve_forever() + +if __name__ == '__main__': + main() diff -r 000000000000 -r b3fd8f98df32 setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Wed Oct 10 16:01:56 2012 -0700 @@ -0,0 +1,28 @@ +from setuptools import setup, find_packages + +try: + description = file('README.txt').read() +except IOError: + description = '' + +version = "0.0" + +setup(name='dogdish', + version=version, + description="dogfooding for b2g upderver", + long_description=description, + classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers + author='Jeff Hammel', + author_email='jhammel@mozilla.com', + url='http://update.boot2gecko.org/nightly/update.xml', + license="", + packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), + include_package_data=True, + zip_safe=False, + install_requires=[ + # -*- Extra requirements: -*- + 'WebOb' + ], + entry_points=""" + """, + )