@@ -40,6 +40,12 @@ async def _read_all(read: Callable[[int], Coroutine], n: Optional[int] = None) -
40
40
return b"" .join (result )
41
41
42
42
43
+ async def _getpass (* args , ** kwargs ) -> str :
44
+ from getpass import getpass
45
+
46
+ return await asyncio .to_thread (getpass , * args , ** kwargs )
47
+
48
+
43
49
class _StderrWrapper :
44
50
def __init__ (self , stderr : "SSHReader" , loop : asyncio .AbstractEventLoop ) -> None :
45
51
self .stderr = stderr
@@ -202,8 +208,6 @@ async def public_key_auth_requested( # noqa: C901
202
208
return None
203
209
204
210
async def _read_private_key_interactive (self , path : "FilePath" ) -> "SSHKey" :
205
- from getpass import getpass
206
-
207
211
from asyncssh .public_key import (
208
212
KeyEncryptionError ,
209
213
KeyImportError ,
@@ -217,9 +221,7 @@ async def _read_private_key_interactive(self, path: "FilePath") -> "SSHKey":
217
221
218
222
loop = asyncio .get_running_loop ()
219
223
for _ in range (3 ):
220
- passphrase = await loop .run_in_executor (
221
- None , getpass , f"Enter passphrase for key '{ path } ': "
222
- )
224
+ passphrase = await _getpass (f"Enter passphrase for key { path !r} : " )
223
225
if passphrase :
224
226
try :
225
227
key = read_private_key (path , passphrase = passphrase )
@@ -239,23 +241,20 @@ async def kbdint_challenge_received( # pylint: disable=invalid-overridden-metho
239
241
lang : str ,
240
242
prompts : "KbdIntPrompts" ,
241
243
) -> Optional ["KbdIntResponse" ]:
242
- from getpass import getpass
243
-
244
244
if os .environ .get ("GIT_TERMINAL_PROMPT" ) == "0" :
245
245
return None
246
246
247
- def _getpass (prompt : str ) -> str :
248
- return getpass (prompt = prompt ).rstrip ()
249
-
250
247
if instructions :
251
248
pass
252
- loop = asyncio .get_running_loop ()
253
- return [
254
- await loop .run_in_executor (
255
- None , _getpass , f"({ name } ) { prompt } " if name else prompt
256
- )
257
- for prompt , _ in prompts
258
- ]
249
+
250
+ response : list [str ] = []
251
+ for prompt , _echo in prompts :
252
+ p = await _getpass (f"({ name } ) { prompt } " if name else prompt )
253
+ response .append (p .rstrip ())
254
+ return response
255
+
256
+ async def password_auth_requested (self ) -> str :
257
+ return await _getpass ()
259
258
260
259
261
260
class AsyncSSHVendor (BaseAsyncObject , SSHVendor ):
0 commit comments