changeset 20903:8d477543882b

wireproto: introduce an abstractserverproto class sshserver and webproto now inherit from an abstractserverproto class. This class is introduced for documentation purpose.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 28 Mar 2014 11:10:33 -0700
parents 1e4fda2f5cf1
children 3dbe6bcd7f62
files mercurial/hgweb/protocol.py mercurial/sshserver.py mercurial/wireproto.py
diffstat 3 files changed, 49 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/protocol.py	Fri Mar 28 11:37:42 2014 -0700
+++ b/mercurial/hgweb/protocol.py	Fri Mar 28 11:10:33 2014 -0700
@@ -12,7 +12,7 @@
 HGTYPE = 'application/mercurial-0.1'
 HGERRTYPE = 'application/hg-error'
 
-class webproto(object):
+class webproto(wireproto.abstractserverproto):
     def __init__(self, req, ui):
         self.req = req
         self.response = ''
--- a/mercurial/sshserver.py	Fri Mar 28 11:37:42 2014 -0700
+++ b/mercurial/sshserver.py	Fri Mar 28 11:10:33 2014 -0700
@@ -9,7 +9,7 @@
 import util, hook, wireproto, changegroup
 import os, sys
 
-class sshserver(object):
+class sshserver(wireproto.abstractserverproto):
     def __init__(self, ui, repo):
         self.ui = ui
         self.repo = repo
--- a/mercurial/wireproto.py	Fri Mar 28 11:37:42 2014 -0700
+++ b/mercurial/wireproto.py	Fri Mar 28 11:10:33 2014 -0700
@@ -11,6 +11,53 @@
 import changegroup as changegroupmod
 import peer, error, encoding, util, store
 
+
+class abstractserverproto(object):
+    """abstract class that summarizes the protocol API
+
+    Used as reference and documentation.
+    """
+
+    def getargs(self, args):
+        """return the value for arguments in <args>
+
+        returns a list of values (same order as <args>)"""
+        raise NotImplementedError()
+
+    def getfile(self, fp):
+        """write the whole content of a file into a file like object
+
+        The file is in the form::
+
+            (<chunk-size>\n<chunk>)+0\n
+
+        chunk size is the ascii version of the int.
+        """
+        raise NotImplementedError()
+
+    def redirect(self):
+        """may setup interception for stdout and stderr
+
+        See also the `restore` method."""
+        raise NotImplementedError()
+
+    # If the `redirect` function does install interception, the `restore`
+    # function MUST be defined. If interception is not used, this function
+    # MUST NOT be defined.
+    #
+    # left commented here on purpose
+    #
+    #def restore(self):
+    #    """reinstall previous stdout and stderr and return intercepted stdout
+    #    """
+    #    raise NotImplementedError()
+
+    def groupchunks(self, cg):
+        """return 4096 chunks from a changegroup object
+
+        Some protocols may have compressed the contents."""
+        raise NotImplementedError()
+
 # abstract batching support
 
 class future(object):