浏览代码

Another python2.6 fix.

Jelmer Vernooij 9 年之前
父节点
当前提交
671d752b3b
共有 2 个文件被更改,包括 11 次插入4 次删除
  1. 7 4
      dulwich/client.py
  2. 4 0
      dulwich/tests/test_client.py

+ 7 - 4
dulwich/client.py

@@ -835,8 +835,10 @@ class SubprocessSSHVendor(SSHVendor):
     """SSH vendor that shells out to the local 'ssh' command."""
 
     def run_command(self, host, command, username=None, port=None):
-        if type(command) is not list:
+        if (type(command) is not list or
+            not all([isinstance(b, bytes) for b in command])):
             raise TypeError(command)
+
         import subprocess
         #FIXME: This has no way to deal with passwords..
         args = ['ssh', '-x']
@@ -939,7 +941,8 @@ else:
 
         def run_command(self, host, command, username=None, port=None,
                         progress_stderr=None):
-            if type(command) is not list:
+            if (type(command) is not list or
+                not all([isinstance(b, bytes) for b in command])):
                 raise TypeError(command)
             # Paramiko needs an explicit port. None is not valid
             if port is None:
@@ -977,8 +980,8 @@ class SSHGitClient(TraditionalGitClient):
 
     def _get_cmd_path(self, cmd):
         cmd = self.alternative_paths.get(cmd, b'git-' + cmd)
-        if sys.version == 2:
-            return [x.decode('ascii') for x in shlex.split(cmd)]
+        if sys.version_info[0:2] >= (2, 7):
+            return [b.decode('ascii') for b in shlex.split(cmd)]
         else:
             return shlex.split(cmd.decode('ascii'))
 

+ 4 - 0
dulwich/tests/test_client.py

@@ -498,6 +498,10 @@ class TestSSHVendor(object):
         self.port = None
 
     def run_command(self, host, command, username=None, port=None):
+        if (type(command) is not list or
+            not all([isinstance(b, bytes) for b in command])):
+            raise TypeError(command)
+
         self.host = host
         self.command = command
         self.username = username