[PATCH 07 of 21 V2] speedy: add interface hiding client/server communication details

Tomasz Kleczek tkleczek at fb.com
Thu Dec 13 20:52:19 CST 2012


# HG changeset patch
# User Tomasz Kleczek <tkleczek at fb.com>
# Date 1354924803 28800
# Node ID 2020a29e9e1100521b2a70ab8ce704a2b754c2a0
# Parent  f18b4628ae086a3b4474d0c2a4fe5b3bb9151edc
speedy: add interface hiding client/server communication details

This patch is a step in providing support for forwarding queries
to a remove server.

It introduces a proxyclient interface that is used by metapeer
to send the query to send the server and receive the respond.

Also provides the simple implementation of the interface for
the local communication.

diff --git a/hgext/speedy/localtransport.py b/hgext/speedy/localtransport.py
new file mode 100644
--- /dev/null
+++ b/hgext/speedy/localtransport.py
@@ -0,0 +1,23 @@
+# Copyright 2012 Facebook
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+"""Local client/server communication conforming to the abstract interface
+
+`Local` means client and server are run in the same interpreter instance.
+"""
+
+import transport
+
+class localclient(transport.clientproxy):
+    """Talks directly to the history server.
+
+    Used when server and client are run in the same interpreter instance.
+    """
+
+    def __init__(self, server):
+        self._server = server
+
+    def request(self, queryname, args):
+        return getattr(self._server, queryname)(*args)
diff --git a/hgext/speedy/transport.py b/hgext/speedy/transport.py
new file mode 100644
--- /dev/null
+++ b/hgext/speedy/transport.py
@@ -0,0 +1,12 @@
+# Copyright 2012 Facebook
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+"""Abstracting low-level details of the client/server communication."""
+
+class clientproxy(object):
+
+    def request(queryname, args):
+        raise NotImplementedError
+


More information about the Mercurial-devel mailing list