@@ -0,0 +1,1959 @@
+# coding: utf-8%0A#%0A# Copyright 2011 Alexandre Fiori%0A# based on the original Tornado by Facebook%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22); you may%0A# not use this file except in compliance with the License. You may obtain%0A# a copy of the License at%0A#%0A#     http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A# License for the specific language governing permissions and limitations%0A# under the License.%0A%0Aimport cyclone.web%0Aimport functools%0Aimport sys%0A%0Afrom twisted.python import log%0Afrom twisted.internet import reactor%0A%0A__handlers = %5B%5D%0A%0Aclass Router:%0A    def __init__(self):%0A        self.items = %5B%5D%0A%0A    def add(self, method, callback):%0A        self.items.append((method, callback))%0A%0A    def __call__(self, *args, **kwargs):%0A        obj = cyclone.web.RequestHandler(*args, **kwargs)%0A        for (method, callback) in self.items:%0A            callback = functools.partial(callback, obj)%0A            setattr(obj, method.lower(), callback)%0A        return obj%0A%0Adef route(path=None, method=%22GET%22, callback=None, **kwargs):%0A    if callable(path):%0A        path, callback = None, path%0A%0A    def decorator(callback):%0A        __handlers.append((path, method, callback, kwargs))%0A        return callback%0A%0A    return decorator%0A%0A%0Adef run(**settings):%0A    handlers = %7B%7D%0A    for (path, method, callback, kwargs) in __handlers:%0A        if path not in handlers:%0A            handlers%5Bpath%5D = Router()%0A        handlers%5Bpath%5D.add(method, callback)%0A%0A    log.startLogging(settings.get(%22log%22, sys.stdout))%0A    application = cyclone.web.Application(handlers.items(), **settings)%0A    port = settings.get(%22port%22, 8888)%0A    interface = settings.get(%22host%22, %22127.0.0.1%22)%0A    reactor.listenTCP(port, application, interface=interface)%0A    reactor.run()%0A

support for bottle-like apps