Skip to content

Instantly share code, notes, and snippets.

@saurabh-hirani
Last active December 18, 2015 06:59
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 saurabh-hirani/5743458 to your computer and use it in GitHub Desktop.
Save saurabh-hirani/5743458 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
class MyApp():
def __init__(self):
self.func_map = {}
def register(self, name):
def func_wrapper(func):
self.func_map[name] = func
return func
return func_wrapper
def call_registered(self, name=None):
func = self.func_map.get(name, None)
if func is None:
raise Exception("No function registered against - " + str(name))
return func()
app = MyApp()
@app.register('/')
def main_page_func():
return "This is the main page."
@app.register('/next_page')
def next_page_func():
return "This is the next page."
print app.call_registered('/')
print app.call_registered('/next_page')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment