summaryrefslogtreecommitdiff
path: root/paramiko/sftp.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2023-01-10 07:51:23 -0500
committerAlex Gaynor <alex.gaynor@gmail.com>2023-01-10 07:52:27 -0500
commit1cd22f097aca2667cbfde6320178e2354d07199b (patch)
treed326a6d543068c608142b9a5da931bd9475bdad0 /paramiko/sftp.py
parenta9ead5ec359038efc96603ad28b0f2eb9255ec3b (diff)
downloadparamiko-1cd22f097aca2667cbfde6320178e2354d07199b.tar.gz
Improve performance by reducing expensive bytes conversion
In two core parts of the codebase, complex type-switch based code is used to convert a value to bytes. However, in all cases (except for one, fixed in this PR), the caller is specifying a Message instance. We can make this code much simpler by directly calling the correct method on Message. In #2110 this is measured to massively speed up large SFTP transfers.
Diffstat (limited to 'paramiko/sftp.py')
-rw-r--r--paramiko/sftp.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/paramiko/sftp.py b/paramiko/sftp.py
index 2e9dff66..144edd4a 100644
--- a/paramiko/sftp.py
+++ b/paramiko/sftp.py
@@ -129,7 +129,9 @@ class BaseSFTP(object):
# ...internals...
def _send_version(self):
- self._send_packet(CMD_INIT, struct.pack(">I", _VERSION))
+ m = Message()
+ m.add_int(_VERSION)
+ self._send_packet(CMD_INIT, m)
t, data = self._read_packet()
if t != CMD_VERSION:
raise SFTPError("Incompatible sftp protocol")
@@ -190,7 +192,7 @@ class BaseSFTP(object):
return out
def _send_packet(self, t, packet):
- packet = util.asbytes(packet)
+ packet = packet.asbytes()
out = struct.pack(">I", len(packet) + 1) + byte_chr(t) + packet
if self.ultra_debug:
self._log(DEBUG, util.format_binary(out, "OUT: "))