dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00381
[PATCH] client: rework ssh vendor selection
Allow the vendor to be specified on the client class. That way, when
users wish to use a separate vendor, they can just subclass
SSHGitClient, instead of replacing (globally) client.get_ssh_vendor.
---
dulwich/client.py | 7 +++----
dulwich/tests/compat/test_client.py | 25 +++++++++++++------------
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/dulwich/client.py b/dulwich/client.py
index 2b69852..e89879f 100644
--- a/dulwich/client.py
+++ b/dulwich/client.py
@@ -338,12 +338,11 @@ class SSHVendor(object):
stdout=subprocess.PIPE)
return SubprocessWrapper(proc)
-# Can be overridden by users
-get_ssh_vendor = SSHVendor
-
class SSHGitClient(GitClient):
+ ssh_vendor_class = SSHVendor
+
def __init__(self, host, port=None, username=None, *args, **kwargs):
self.host = host
self.port = port
@@ -351,7 +350,7 @@ class SSHGitClient(GitClient):
GitClient.__init__(self, *args, **kwargs)
def _connect(self, cmd, path):
- con = get_ssh_vendor().connect_ssh(
+ con = self.ssh_vendor_class().connect_ssh(
self.host, ["%s '%s'" % ('git-' + cmd, path)],
port=self.port, username=self.username)
return Protocol(con.read, con.write), con.can_read
diff --git a/dulwich/tests/compat/test_client.py b/dulwich/tests/compat/test_client.py
index b632507..63314c5 100644
--- a/dulwich/tests/compat/test_client.py
+++ b/dulwich/tests/compat/test_client.py
@@ -200,30 +200,31 @@ class DulwichTCPClientTest(CompatTestCase, DulwichClientTestBase):
return path
-class TestSSHVendor(object):
- @staticmethod
- def connect_ssh(host, command, username=None, port=None):
- cmd, path = command[0].replace("'", '').split(' ')
- cmd = cmd.split('-', 1)
- p = subprocess.Popen(cmd + [path], stdin=subprocess.PIPE,
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- return client.SubprocessWrapper(p)
+class TestSSHGitClient(client.SSHGitClient):
+
+ class TestSSHVendor(object):
+ @staticmethod
+ def connect_ssh(host, command, username=None, port=None):
+ cmd, path = command[0].replace("'", '').split(' ')
+ cmd = cmd.split('-', 1)
+ p = subprocess.Popen(cmd + [path], stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ return client.SubprocessWrapper(p)
+
+ ssh_vendor_class = TestSSHVendor
class DulwichMockSSHClientTest(CompatTestCase, DulwichClientTestBase):
def setUp(self):
CompatTestCase.setUp(self)
DulwichClientTestBase.setUp(self)
- self.real_vendor = client.get_ssh_vendor
- client.get_ssh_vendor = TestSSHVendor
def tearDown(self):
DulwichClientTestBase.tearDown(self)
CompatTestCase.tearDown(self)
- client.get_ssh_vendor = self.real_vendor
def _client(self):
- return client.SSHGitClient('localhost')
+ return TestSSHGitClient('localhost')
def _build_path(self, path):
return self.gitroot + path
--
1.7.3.2.msysgit.0
Follow ups