Created
          September 23, 2011 04:38 
        
      - 
      
- 
        Save wickman/1236753 to your computer and use it in GitHub Desktop. 
    bottle bug
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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