diff --git a/isso/__init__.py b/isso/__init__.py index 8965c0b..4cd1eef 100644 --- a/isso/__init__.py +++ b/isso/__init__.py @@ -21,6 +21,54 @@ __version__ = '0.1' +from werkzeug.routing import Map, Rule +from werkzeug.serving import run_simple +from werkzeug.wrappers import Request, Response +from werkzeug.exceptions import HTTPException, NotFound, NotImplemented, InternalServerError + +from isso import admin, comments + +url_map = Map([ + # moderation panel + Rule('/', endpoint='admin.index', methods=['GET', 'POST']), + + # comments API + Rule('/comment//', endpoint='comments.comment', methods=['POST']), + Rule('/comment//', endpoint='comments.comment', + methods=['GET', 'PUT', 'DELETE']), +]) + + +class Isso: + + def __init__(self, conf): + + self.conf = conf + + def dispatch(self, request, start_response): + adapter = url_map.bind_to_environ(request.environ) + try: + endpoint, values = adapter.match() + module, function = endpoint.split('.', 1) + handler = getattr(globals()[module], function) + return handler(self, request.environ, request, **values) + except NotFound, e: + return Response('Not Found', 404) + except HTTPException, e: + return e + except InternalServerError, e: + return Response(e, 500) + + def wsgi_app(self, environ, start_response): + request = Request(environ) + response = self.dispatch(request, start_response) + return response(environ, start_response) + + def __call__(self, environ, start_response): + return self.wsgi_app(environ, start_response) + def main(): - print "Hallo Welt!" + + app = Isso(123) + run_simple('127.0.0.1', 8080, app) diff --git a/isso/admin.py b/isso/admin.py new file mode 100644 index 0000000..db4fd0d --- /dev/null +++ b/isso/admin.py @@ -0,0 +1,6 @@ + +from werkzeug.wrappers import Response + + +def index(app, environ, request): + return Response('', 200) diff --git a/isso/comments.py b/isso/comments.py new file mode 100644 index 0000000..7e569c8 --- /dev/null +++ b/isso/comments.py @@ -0,0 +1,6 @@ + +from werkzeug.wrappers import Response + + +def comment(app, environ, request, path, id=None): + return Response('', 200) diff --git a/setup.py b/setup.py index 8aafc4b..f8aba95 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ setup( "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7" ], - install_requires=['flask'], + install_requires=['werkzeug'], entry_points={ 'console_scripts': ['isso = isso:main'], diff --git a/specs/test_urls.py b/specs/test_urls.py new file mode 100644 index 0000000..271bf42 --- /dev/null +++ b/specs/test_urls.py @@ -0,0 +1,13 @@ + +from werkzeug.test import Client +from werkzeug.wrappers import BaseResponse + +import isso + +client = Client(isso.Isso(123), BaseResponse) + + +def test_200ok(): + + assert client.get('/').status_code == 200 + assert client.get('/comment/asdf/123').status_code == 200