Skip to content

Commit f5396b8

Browse files
committed
allow passing kwargs to sftp client
1 parent c127831 commit f5396b8

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

sshfs/pools/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def __init__(
3838
self.unsafe_terminate = unsafe_terminate
3939
self._stack = AsyncExitStack()
4040

41+
self.other_init_params = kwargs or {}
42+
4143
async def _maybe_new_channel(self):
4244
# If there is no hard limit or the limit is not hit yet
4345
# try to create a new channel
@@ -47,7 +49,7 @@ async def _maybe_new_channel(self):
4749
):
4850
try:
4951
return await self._stack.enter_async_context(
50-
self.client.start_sftp_client()
52+
self.client.start_sftp_client(**self.other_init_params)
5153
)
5254
except ChannelOpenError:
5355
# If we can't create any more channels, then change

sshfs/spec.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def __init__(
4545
SSH host to connect.
4646
**kwargs: Any
4747
Any option that will be passed to either the top level
48-
`AsyncFileSystem` or the `asyncssh.connect`.
48+
`AsyncFileSystem` (e.g. timeout)
49+
or `asyncssh.SSHClientConnection.start_sftp_client` (e.g. env, send_env, path_encoding, path_errors, sftp_version)
50+
or the `asyncssh.connect`.
4951
pool_type: sshfs.pools.base.BaseSFTPChannelPool
5052
Pool manager to use (when doing concurrent operations together,
5153
pool managers offer the flexibility of prioritizing channels
@@ -54,6 +56,17 @@ def __init__(
5456

5557
super().__init__(self, **kwargs)
5658

59+
_sftp_client_args = {
60+
k: kwargs.pop(k) for k in kwargs.copy().keys()
61+
if k in {
62+
"env",
63+
"send_env",
64+
"path_encoding",
65+
"path_errors",
66+
"sftp_version",
67+
}
68+
}
69+
_timeout = kwargs.pop("timeout", None)
5770
max_sessions = kwargs.pop("max_sessions", _DEFAULT_MAX_SESSIONS)
5871
if max_sessions <= _SHELL_CHANNELS:
5972
raise ValueError(
@@ -68,7 +81,9 @@ def __init__(
6881
host,
6982
pool_type,
7083
max_sftp_channels=max_sessions - _SHELL_CHANNELS,
71-
**_client_args,
84+
timeout=_timeout, # goes to sync_wrapper
85+
connect_args=_client_args, # for asyncssh.connect
86+
sftp_client_args=_sftp_client_args, # for asyncssh.SSHClientConnection.start_sftp_client
7287
)
7388
weakref.finalize(
7489
self, sync, self.loop, self._finalize, self._pool, self._stack
@@ -89,13 +104,13 @@ def _get_kwargs_from_urls(urlpath):
89104

90105
@wrap_exceptions
91106
async def _connect(
92-
self, host, pool_type, max_sftp_channels, **client_args
107+
self, host, pool_type, max_sftp_channels, connect_args, sftp_client_args
93108
):
94109
self._client_lock = asyncio.Semaphore(_SHELL_CHANNELS)
95110

96-
_raw_client = asyncssh.connect(host, **client_args)
111+
_raw_client = asyncssh.connect(host, **connect_args)
97112
client = await self._stack.enter_async_context(_raw_client)
98-
pool = pool_type(client, max_channels=max_sftp_channels)
113+
pool = pool_type(client, max_channels=max_sftp_channels, **sftp_client_args)
99114
return client, pool
100115

101116
connect = sync_wrapper(_connect)

0 commit comments

Comments
 (0)