From 51b92a1ebf485127caa0af76545650a3266a7ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 10 Feb 2011 12:50:01 +0200 Subject: [PATCH] use __getattr__ to make object any symbol callable --- doku.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/doku.py b/doku.py index 9b898ed..0348f9a 100644 --- a/doku.py +++ b/doku.py @@ -14,22 +14,16 @@ class DokuWiki: def __init__(self): self.callcache = {} - def __call(self, call, id): - key = "%s-%s" % (call, id) + def __getattr__(self, callback): + self.callback = callback + return self.__dokucall + + def __dokucall(self, *args): + args = list(args) + key = "%s:%s" % (self.callback, ",".join(args)) if not self.callcache.has_key(key): - cmd = ['./doku.php', call, id] + cmd = ['./doku.php', self.callback ] + args res = subprocess.Popen(cmd, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, close_fds = True).communicate() + print "%s->%s" % (cmd, res) self.callcache[key] = res[0] return self.callcache[key] - - def wikiFn(self, id): - return self.__call('wikiFn', id) - - def mediaFn(self, id): - return self.__call('mediaFn', id) - - def getNS(self, id): - return self.__call('getNS', id) - - def cleanID(self, id): - return self.__call('cleanID', id)