[PATCH 02 of 22] wireproto: introduce an abstractserverproto class

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Fri Mar 28 17:40:28 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1396030233 25200
#      Fri Mar 28 11:10:33 2014 -0700
# Node ID 3047434d86075975df7c6ae430752a6616a8c0bd
# Parent  a403855f263738815a7fcc131a0588d742b5f273
wireproto: introduce an abstractserverproto class

sshserver and webproto now inherit from an abstractserverproto class. This class
is introduced for documentation purpose.

diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py
--- a/mercurial/hgweb/protocol.py
+++ b/mercurial/hgweb/protocol.py
@@ -10,11 +10,11 @@ from mercurial import util, wireproto
 from common import HTTP_OK
 
 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 = ''
         self.ui = ui
     def getargs(self, args):
diff --git a/mercurial/sshserver.py b/mercurial/sshserver.py
--- a/mercurial/sshserver.py
+++ b/mercurial/sshserver.py
@@ -7,11 +7,11 @@
 # GNU General Public License version 2 or any later version.
 
 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
         self.lock = None
         self.fin = ui.fin
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -9,10 +9,57 @@ import urllib, tempfile, os, sys
 from i18n import _
 from node import bin, hex
 import changegroup as changegroupmod
 import peer, error, encoding, util, store
 
+
+class abstractserverproto(object):
+    """abstract class that summarize the protocol API
+
+    Used as reference and documentation.
+    """
+
+    def getargs(self, args):
+        """return the value for arguments in <args>
+
+        return a list of value (same order than <args>)"""
+        raise NotImplementedError()
+
+    def getfile(self, fp):
+        """write the whole content of a file into a file like object
+
+        The file are 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 do install interception, the `restore`
+    # function MUST be defined. output 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 chunk from a changegroup object
+
+        Some protocol may have compressed the content"""
+        raise NotImplementedError()
+
 # abstract batching support
 
 class future(object):
     '''placeholder for a value to be set later'''
     def set(self, value):


More information about the Mercurial-devel mailing list