changeset 971:d24f2b1d606a

Refactoring, fixed Fault codes, fixed return format of the getdiff method.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Wed, 12 Jul 2006 00:14:55 +0200
parents f29c09448353
children 213776426ce2
files MoinMoin/action/SyncPages.py MoinMoin/action/__init__.py MoinMoin/wikiutil.py MoinMoin/xmlrpc/__init__.py
diffstat 4 files changed, 30 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/SyncPages.py	Sun Jul 09 21:08:01 2006 +0200
+++ b/MoinMoin/action/SyncPages.py	Wed Jul 12 00:14:55 2006 +0200
@@ -29,7 +29,7 @@
     def __repr__(self):
         return "<RemoteWiki wiki_url=%r valid=%r>" % (self.valid, self.wiki_url)
 
-class PackagePages:
+class ActionClass:
     def __init__(self, pagename, request):
         self.request = request
         self.pagename = pagename
@@ -72,5 +72,4 @@
         raise ActionStatus(_("Syncronisation finished."))
     
 def execute(pagename, request):
-    """ Glue code for actions """
-    PackagePages(pagename, request).render()
+    ActionClass(pagename, request).render()
--- a/MoinMoin/action/__init__.py	Sun Jul 09 21:08:01 2006 +0200
+++ b/MoinMoin/action/__init__.py	Wed Jul 12 00:14:55 2006 +0200
@@ -427,7 +427,7 @@
     # Save new text
     else:
         try:
-            still_conflict = "/!\ '''Edit conflict" in savetext
+            still_conflict = wikiutil.containsConflictMarker(savetext)
             pg.setConflict(still_conflict)
             savemsg = pg.saveText(savetext, rev, trivial=trivial, comment=comment)
         except pg.EditConflict, e:
--- a/MoinMoin/wikiutil.py	Sun Jul 09 21:08:01 2006 +0200
+++ b/MoinMoin/wikiutil.py	Wed Jul 12 00:14:55 2006 +0200
@@ -1443,6 +1443,9 @@
     else:
         return "%s%s</a>" % (result, text)
 
+def containsConflictMarker(text):
+    """ Returns true if there is a conflict marker in the text. """
+    return "/!\ '''Edit conflict" in text
 
 def linediff(oldlines, newlines, **kw):
     """
--- a/MoinMoin/xmlrpc/__init__.py	Sun Jul 09 21:08:01 2006 +0200
+++ b/MoinMoin/xmlrpc/__init__.py	Wed Jul 12 00:14:55 2006 +0200
@@ -521,6 +521,7 @@
             return xmlrpclib.Fault("INVALID", "Invalid token.")
     
     def xmlrpc_getDiff(self, pagename, from_rev, to_rev):
+        """ Gets the binary difference between two page revisions. See MoinMoin:WikiSyncronisation. """
         from MoinMoin.util.bdiff import textdiff, compress
         
         pagename = self._instr(pagename)
@@ -531,36 +532,48 @@
 
         def allowed_rev_type(data):
             if data is None:
-                return true
+                return True
             return isinstance(data, int) and data > 0
 
-        if not allowed_rev_type(from_rev) or not allowed_rev_type(to_rev):
-            return xmlrpclib.Fault("FIXME", "Incorrect type for revision(s).") # XXX
+        if not allowed_rev_type(from_rev):
+            return xmlrpclib.Fault("FROMREV_INVALID", "Incorrect type for from_rev.")
+        
+        if not allowed_rev_type(to_rev):
+            return xmlrpclib.Fault("TOREV_INVALID", "Incorrect type for to_rev.")
         
         currentpage = Page(self.request, pagename)
+        if not currentpage.exists():
+            return xmlrpclib.Fault("NOT_EXIST", "Page does not exist.")
+        
         revisions = currentpage.getRevList()
         
         if from_rev is not None and from_rev not in revisions:
-            return xmlrpclib.Fault("FIXME", "Unknown from_rev.") # XXX
+            return xmlrpclib.Fault("FROMREV_INVALID", "Unknown from_rev.")
         if to_rev is not None and to_rev not in revisions:
-            return xmlrpclib.Fault("FIXME", "Unknown to_rev.") # XXX
+            return xmlrpclib.Fault("TOREV_INVALID", "Unknown to_rev.")
         
+        # use lambda to defer execution in the next lines
         if from_rev is None:
-            oldcontents = ""
+            oldcontents = lambda: ""
         else:
             oldpage = Page(request, pagename, rev=from_rev)
-            oldcontents = oldpage.get_raw_body()
+            oldcontents = lambda: oldpage.get_raw_body()
         
         if to_rev is None:
-            newcontents = currentpage.get_raw_body()
+            newcontents = lambda: currentpage.get_raw_body()
         else:
             newpage = Page(request, pagename, rev=to_rev)
-            newcontents = newpage.get_raw_body()
+            newcontents = lambda: newpage.get_raw_body()
             newrev = newpage.get_real_rev()
         
-        diffblob = xmlrpclib.Binary(compress(textdiff(oldcontents, newcontents)))
+        if oldcontents() and oldpage.get_real_rev() == newpage.get_real_rev():
+            return xmlrpclib.Fault("ALREADY_CURRENT", "There are no changes.")
         
-        return # XXX
+        newcontents = newcontents().encode("utf-8")
+        conflict = wikiutil.containsConflictMarker(newcontents)
+        diffblob = xmlrpclib.Binary(compress(textdiff(oldcontents().encode("utf-8"), newcontents)))
+        
+        return {"conflict": conflict, "diff": diffblob, "diffversion": 1, "current": currentpage.get_real_rev()}
         
     # XXX BEGIN WARNING XXX
     # All xmlrpc_*Attachment* functions have to be considered as UNSTABLE API -