소스 검색

Make _connect asyncio.

Jelmer Vernooij 5 년 전
부모
커밋
6630baf39c
2개의 변경된 파일14개의 추가작업 그리고 11개의 파일을 삭제
  1. 10 8
      dulwich/client.py
  2. 4 3
      dulwich/tests/test_client.py

+ 10 - 8
dulwich/client.py

@@ -822,7 +822,7 @@ class TraditionalGitClient(GitClient):
         self._remote_path_encoding = path_encoding
         super(TraditionalGitClient, self).__init__(**kwargs)
 
-    def _connect(self, cmd, path):
+    async def _connect(self, cmd, path):
         """Create a connection to the server.
 
         This method is abstract - concrete implementations should
@@ -860,7 +860,8 @@ class TraditionalGitClient(GitClient):
                          and rejects ref updates
 
         """
-        proto, unused_can_read, stderr = self._connect(b'receive-pack', path)
+        proto, unused_can_read, stderr = await self._connect(
+            b'receive-pack', path)
         with proto:
             try:
                 old_refs, server_capabilities = read_pkt_refs(proto)
@@ -939,7 +940,8 @@ class TraditionalGitClient(GitClient):
           FetchPackResult object
 
         """
-        proto, can_read, stderr = self._connect(b'upload-pack', path)
+        proto, can_read, stderr = await self._connect(
+            b'upload-pack', path)
         with proto:
             try:
                 refs, server_capabilities = read_pkt_refs(proto)
@@ -976,7 +978,7 @@ class TraditionalGitClient(GitClient):
         """Retrieve the current refs from a git smart server.
         """
         # stock `git ls-remote` uses upload-pack
-        proto, _, stderr = self._connect(b'upload-pack', path)
+        proto, _, stderr = await self._connect(b'upload-pack', path)
         with proto:
             try:
                 refs, _ = read_pkt_refs(proto)
@@ -988,7 +990,7 @@ class TraditionalGitClient(GitClient):
     async def archive_async(self, path, committish, write_data, progress=None,
                             write_error=None, format=None, subdirs=None,
                             prefix=None):
-        proto, can_read, stderr = self._connect(b'upload-archive', path)
+        proto, can_read, stderr = await self._connect(b'upload-archive', path)
         with proto:
             if format is not None:
                 proto.write_pkt_line(b"argument --format=" + format)
@@ -1041,7 +1043,7 @@ class TCPGitClient(TraditionalGitClient):
             netloc += ":%d" % self._port
         return urlparse.urlunsplit(("git", netloc, path, '', ''))
 
-    def _connect(self, cmd, path):
+    async def _connect(self, cmd, path):
         if not isinstance(cmd, bytes):
             raise TypeError(cmd)
         if not isinstance(path, bytes):
@@ -1134,7 +1136,7 @@ class SubprocessGitClient(TraditionalGitClient):
 
     git_command = None
 
-    def _connect(self, service, path):
+    async def _connect(self, service, path):
         if not isinstance(service, bytes):
             raise TypeError(service)
         if isinstance(path, bytes):
@@ -1463,7 +1465,7 @@ class SSHGitClient(TraditionalGitClient):
         assert isinstance(cmd, bytes)
         return cmd
 
-    def _connect(self, cmd, path):
+    async def _connect(self, cmd, path):
         if not isinstance(cmd, bytes):
             raise TypeError(cmd)
         if isinstance(path, bytes):

+ 4 - 3
dulwich/tests/test_client.py

@@ -18,6 +18,7 @@
 # License, Version 2.0.
 #
 
+import asyncio
 from io import BytesIO
 import base64
 import sys
@@ -100,7 +101,7 @@ class DummyClient(TraditionalGitClient):
         self.write = write
         TraditionalGitClient.__init__(self)
 
-    def _connect(self, service, path):
+    async def _connect(self, service, path):
         return Protocol(self.read, self.write), self.can_read, None
 
 
@@ -746,12 +747,12 @@ class SSHGitClientTests(TestCase):
         client.username = b"username"
         client.port = 1337
 
-        client._connect(b"command", b"/path/to/repo")
+        asyncio.run(client._connect(b"command", b"/path/to/repo"))
         self.assertEqual(b"username", server.username)
         self.assertEqual(1337, server.port)
         self.assertEqual("git-command '/path/to/repo'", server.command)
 
-        client._connect(b"relative-command", b"/~/path/to/repo")
+        asyncio.run(client._connect(b"relative-command", b"/~/path/to/repo"))
         self.assertEqual("git-relative-command '~/path/to/repo'",
                          server.command)