فهرست منبع

Use standard strings in more places.

Jelmer Vernooij 8 سال پیش
والد
کامیت
6086ed2e51
4فایلهای تغییر یافته به همراه10 افزوده شده و 17 حذف شده
  1. 5 7
      dulwich/client.py
  2. 0 2
      dulwich/contrib/paramiko_vendor.py
  3. 3 3
      dulwich/tests/compat/test_client.py
  4. 2 5
      dulwich/tests/test_client.py

+ 5 - 7
dulwich/client.py

@@ -970,9 +970,6 @@ class SubprocessSSHVendor(SSHVendor):
     """SSH vendor that shells out to the local 'ssh' command."""
 
     def run_command(self, host, command, username=None, port=None):
-        if not isinstance(command, bytes):
-            raise TypeError(command)
-
         # FIXME: This has no way to deal with passwords..
         args = ['ssh', '-x']
         if port is not None:
@@ -1035,11 +1032,12 @@ class SSHGitClient(TraditionalGitClient):
     def _connect(self, cmd, path):
         if not isinstance(cmd, bytes):
             raise TypeError(cmd)
-        if not isinstance(path, bytes):
-            path = path.encode(self._remote_path_encoding)
-        if path.startswith(b"/~"):
+        if isinstance(path, bytes):
+            path = path.decode(self._remote_path_encoding)
+        if path.startswith("/~"):
             path = path[1:]
-        argv = self._get_cmd_path(cmd) + b" '" + path + b"'"
+        argv = (self._get_cmd_path(cmd).decode(self._remote_path_encoding) +
+                " '" + path + "'")
         con = self.ssh_vendor.run_command(
             self.host, argv, port=self.port, username=self.username)
         return (Protocol(con.read, con.write, con.close,

+ 0 - 2
dulwich/contrib/paramiko_vendor.py

@@ -116,8 +116,6 @@ class ParamikoSSHVendor(object):
 
     def run_command(self, host, command, username=None, port=None,
                     progress_stderr=None):
-        if not isinstance(command, bytes):
-            raise TypeError(command)
         # Paramiko needs an explicit port. None is not valid
         if port is None:
             port = 22

+ 3 - 3
dulwich/tests/compat/test_client.py

@@ -324,9 +324,9 @@ class TestSSHVendor(object):
 
     @staticmethod
     def run_command(host, command, username=None, port=None):
-        cmd, path = command.split(b' ')
-        cmd = cmd.split(b'-', 1)
-        path = path.replace(b"'", b"")
+        cmd, path = command.split(' ')
+        cmd = cmd.split('-', 1)
+        path = path.replace("'", "")
         p = subprocess.Popen(cmd + [path], bufsize=0, stdin=subprocess.PIPE,
                              stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         return client.SubprocessWrapper(p)

+ 2 - 5
dulwich/tests/test_client.py

@@ -612,9 +612,6 @@ class TestSSHVendor(object):
         self.port = None
 
     def run_command(self, host, command, username=None, port=None):
-        if not isinstance(command, bytes):
-            raise TypeError(command)
-
         self.host = host
         self.command = command
         self.username = username
@@ -686,10 +683,10 @@ class SSHGitClientTests(TestCase):
         client._connect(b"command", b"/path/to/repo")
         self.assertEqual(b"username", server.username)
         self.assertEqual(1337, server.port)
-        self.assertEqual(b"git-command '/path/to/repo'", server.command)
+        self.assertEqual("git-command '/path/to/repo'", server.command)
 
         client._connect(b"relative-command", b"/~/path/to/repo")
-        self.assertEqual(b"git-relative-command '~/path/to/repo'",
+        self.assertEqual("git-relative-command '~/path/to/repo'",
                          server.command)