Skip to content

Instantly share code, notes, and snippets.

@wickman
Created September 23, 2011 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wickman/1236753 to your computer and use it in GitHub Desktop.
Save wickman/1236753 to your computer and use it in GitHub Desktop.
bottle bug
class BottleServer(object):
@staticmethod
def route(*args, **kwargs):
def annotated(function):
if hasattr(function, '__routes__'):
function.__routes__.append( (args, kwargs) )
else:
function.__routes__ = [(args, kwargs)]
return function
return annotated
def __init__(self):
self._app = bottle.Bottle()
for attr in dir(self):
if hasattr(self, attr) and hasattr(getattr(self, attr), '__routes__'):
for rt in getattr(self,attr).__routes__:
kw = copy.deepcopy(rt[1])
kw.update({'callback': getattr(self, attr)})
self._app.route(*rt[0], **kw)
def run(self, hostname, port):
bottle.run(self._app, host=hostname, port=port)
class Foo(BottleServer):
def __init__(self):
BottleServer.__init__(self)
@BottleServer.route('/hello')
@BottleServer.route('/hello/:first')
def hello(self, **kw):
return 'hello: %s' % repr(kw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment