Created
September 7, 2012 10:02
-
-
Save dz0ny/3664800 to your computer and use it in GitHub Desktop.
This file contains 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 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