+ args = list(subst_none(args))
+ kwargs = dict(zip(kwargs.keys(), list(subst_none(kwargs.values()))))
+ ret = self._xmlrpc_handler.send_rpc(cmd, self._in_fd, self._out_fd,
+ *args, **kwargs)
+ if ret == IkiWikiProcedureProxy._IKIWIKI_NIL_SENTINEL:
+ ret = None
+ return ret
+
+ def hook(self, type, function, name=None, id=None, last=False):
+ if self._imported:
+ raise AlreadyImported()
+
+ if name is None:
+ name = function.__name__
+
+ if id is None:
+ id = self._id
+
+ def hook_proxy(*args):
+# curpage = args[0]
+# kwargs = dict([args[i:i+2] for i in xrange(1, len(args), 2)])
+ ret = function(self, *args)
+ self._debug_fn(
+ "{0} hook `{1}' returned: [{2}]".format(type, name, repr(ret)))
+ if ret == IkiWikiProcedureProxy._IKIWIKI_NIL_SENTINEL:
+ raise InvalidReturnValue(
+ 'hook functions are not allowed to return {0}'.format(
+ IkiWikiProcedureProxy._IKIWIKI_NIL_SENTINEL))
+ if ret is None:
+ ret = IkiWikiProcedureProxy._IKIWIKI_NIL_SENTINEL
+ return ret
+
+ self._hooks.append((id, type, name, last))
+ self._xmlrpc_handler.register_function(hook_proxy, name=name)
+
+ def inject(self, rname, function, name=None, memoize=True):
+ if self._imported:
+ raise AlreadyImported()
+
+ if name is None:
+ name = function.__name__
+
+ self._functions.append((rname, name, memoize))
+ self._xmlrpc_handler.register_function(function, name=name)
+
+ def getargv(self):
+ return self.rpc('getargv')
+
+ def setargv(self, argv):
+ return self.rpc('setargv', argv)
+
+ def getvar(self, hash, key):
+ return self.rpc('getvar', hash, key)
+
+ def setvar(self, hash, key, value):
+ return self.rpc('setvar', hash, key, value)
+
+ def getstate(self, page, id, key):
+ return self.rpc('getstate', page, id, key)
+
+ def setstate(self, page, id, key, value):
+ return self.rpc('setstate', page, id, key, value)
+
+ def pagespec_match(self, spec):
+ return self.rpc('pagespec_match', spec)
+
+ def error(self, msg):
+ try:
+ self.rpc('error', msg)
+ except IOError as e:
+ if e.errno != 32:
+ raise
+ import posix
+ sys.exit(posix.EX_SOFTWARE)