#
# Copyright (c) 2005 rpath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#
import netclient

class ShimNetClient(netclient.NetworkRepositoryClient):
    """
    A subclass of NetworkRepositoryClient which can take a NetworkRepositoryServer
    instance (plus a few other pieces of information) and expose the netclient
    interface without the overhead of XMLRPC.
    """
    def __init__(self, server, protocol, port, authToken, repMap):
        netclient.NetworkRepositoryClient.__init__(self, repMap)
        self.server = ShimServerProxy(server, protocol, port, authToken)

class _ShimMethod(netclient._Method):
    def __init__(self, server, protocol, port, authToken, name):
        self._server = server
        self._authToken = authToken
        self._name = name
        self._protocol = protocol
        self._port = port

    def __repr__(self):
        return "<server._ShimMethod(%r)>" % (self._ShimMethod__name)

    def __call__(self, *args):
        isException, result = self._server.callWrapper(
            self._protocol, self._port,
            self._name, self._authToken, args)

        if not isException:
            return result
        else:
            self.handleError(result)

class ShimServerProxy(netclient.ServerProxy):
    def __init__(self, server, protocol, port, authToken):
        self._authToken = authToken
        self._server = server
        self._protocol = protocol
        self._port = port

    def __getattr__(self, name):
        return _ShimMethod(self._server,
            self._protocol, self._port,
            self._authToken, name)

@@ -583,16 +583,282 @@
 client%0A%0A
+# this returns the same server for any server name or label%0A# requested; because a shim can only refer to one server.%0Aclass FakeServerCache:%0A    def __init__(self, server):%0A        self._server = server%0A%0A    def __getitem__(self, item):%0A        return self._server%0A%0A
 class Sh
@@ -1273,19 +1273,13 @@
     
-self.server
+proxy
  = S
@@ -1327,16 +1327,56 @@
 thToken)
+%0A        self.c = FakeServerCache(proxy)
 %0A%0Aclass 
@@ -1719,16 +1719,16 @@
 _name)%0A%0A
-
     def 
@@ -1750,16 +1750,76 @@
 *args):%0A
+        args = %5Bnetclient.CLIENT_VERSIONS%5B-1%5D%5D + list(args)%0A
         

fix the shimclient to actually work by creating a 'fake' servercache object and pass the latest client version to the server.