diff MoinMoin/xmlrpc/__init__.py @ 5816:b661a89ef0be

xmlrpc: new methods xmlrpc_getProcessingInstruction and xmlrpc_getProcessingInstructionVersion
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 25 Dec 2011 23:56:09 +0100
parents a7b3ccda38d8
children dfbc455e2c46
line wrap: on
line diff
--- a/MoinMoin/xmlrpc/__init__.py	Sun Dec 25 23:33:14 2011 +0100
+++ b/MoinMoin/xmlrpc/__init__.py	Sun Dec 25 23:56:09 2011 +0100
@@ -447,6 +447,36 @@
             'version': version,
             }
 
+    def xmlrpc_getProcessingInstruction(self, pagename, pi):
+        """
+        Invoke getProcessingInstructionVersion with rev=None
+        """
+        return self.xmlrpc_getProcessingInstructionVersion(pagename, rev=None, pi=pi)
+
+    def xmlrpc_getProcessingInstructionVersion(self, pagename, rev, pi):
+        """
+        Returns value of Processing Instruction
+        @param pagename: pagename (utf-8)
+        @param rev: revision number (int)
+        @param pi: PI key
+        """
+        # User may read page?
+        if not self.request.user.may.read(pagename):
+            return self.notAllowedFault()
+        if rev is not None:
+            page = Page(self.request, pagename, rev=rev)
+        else:
+            page = Page(self.request, pagename)
+        if not page.exists():
+            return xmlrpclib.Fault("NOT_EXIST", "Page does not exist.")
+        if pi is None:
+            return xmlrpclib.Fault("NOT_EXIST", "Processing Instruction not given.")
+        try:
+            instruction = page.pi[pi]
+        except KeyError:
+            return xmlrpclib.Fault("NOT_EXIST", "Processing Instruction does not exist.")
+        return self._outstr(instruction)
+
     def xmlrpc_getPage(self, pagename):
         """
         Invoke xmlrpc_getPageVersion with rev=None