Skip to content

Instantly share code, notes, and snippets.

@dz0ny
Created September 7, 2012 10:02
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 dz0ny/3664800 to your computer and use it in GitHub Desktop.
Save dz0ny/3664800 to your computer and use it in GitHub Desktop.
class http_callback(object):
"""
Add callback to plugin defined function. For example request to GET /callback/plugin_name/log_me
would trigger log_me function in plugin
Example:
@Server.http_callback
def compiled(self, req):
print req # urlparse object
return "cool" #to http client
"""
def __init__(self, callback_f):
path = 'http://localhost:35729/callback/%s/%s' % (callback_f.__module__.lower(),
callback_f.__name__)
print callback_f.__class__
callback_f.path = path
self.func_class = callback_f.__module__
self.func_name = callback_f.__name__
self.func = callback_f
print "self.func_class", self.func_class
print "self.func", self.func
sys.modules['Server'].API.callbacks.append({'path': path, 'callback': self})
print 'Server: added callback with url %s' % path
def __call__(self, req):
#print sys.modules['Server'].Plugin.getPlugin("SimpleRefreshCallBack").title
return self.func(sys.modules['Server'].Plugin.getPlugin("SimpleRefreshCallBack"), req)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment