From dc58b7bcb2bf6c945878a841b1861f0f195a3075 Mon Sep 17 00:00:00 2001 From: Scott Maxwell Date: Sat, 2 Nov 2013 20:19:52 -0700 Subject: [PATCH] Fix message to handle long properly, even on Py3 --- paramiko/message.py | 5 +++-- paramiko/sftp_client.py | 6 +++--- paramiko/sftp_server.py | 6 +++--- tests/test_message.py | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/paramiko/message.py b/paramiko/message.py index 8e81e69..4508621 100644 --- a/paramiko/message.py +++ b/paramiko/message.py @@ -170,7 +170,7 @@ class Message (object): @return: a 64-bit unsigned integer. @rtype: long """ - return self.get_int() + return struct.unpack('>Q', self.get_bytes(8))[0] def get_mpint(self): """ @@ -289,7 +289,8 @@ class Message (object): @param n: long int to add @type n: long """ - return self.add_int(n) + self.packet.write(struct.pack('>Q', n)) + return self def add_mpint(self, z): """ diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index 31e6697..5a08db6 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -695,10 +695,10 @@ class SFTPClient (BaseSFTP): msg = Message() msg.add_int(self.request_number) for item in arg: - if isinstance(item, int): - msg.add_int(item) - elif isinstance(item, long): + if isinstance(item, long): msg.add_int64(item) + elif isinstance(item, int): + msg.add_int(item) elif isinstance(item, (string_types, bytes_types)): msg.add_string(item) elif isinstance(item, SFTPAttributes): diff --git a/paramiko/sftp_server.py b/paramiko/sftp_server.py index 2a1a443..38adc63 100644 --- a/paramiko/sftp_server.py +++ b/paramiko/sftp_server.py @@ -183,10 +183,10 @@ class SFTPServer (BaseSFTP, SubsystemHandler): msg = Message() msg.add_int(request_number) for item in arg: - if type(item) is int: - msg.add_int(item) - elif type(item) is long: + if isinstance(item, long): msg.add_int64(item) + elif isinstance(item, int): + msg.add_int(item) elif isinstance(item, (string_types, bytes_types)): msg.add_string(item) elif type(item) is SFTPAttributes: diff --git a/tests/test_message.py b/tests/test_message.py index f983b4d..cb815f9 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -30,7 +30,7 @@ class MessageTest (unittest.TestCase): __a = unhexlify(b('000000170760e09000000001710000000568656c6c6f000003e8')) + (b('x') * 1000) __b = unhexlify(b('0100f3003f00000010687565792c64657765792c6c6f756965')) - __c = unhexlify(b('00000005ff0000000700f5e4d3c2b10900000001110000000700f5e4d3c2b109000000069a1b2c3d4ef7')) + __c = unhexlify(b('00000000000000050000f5e4d3c2b10900000001110000000700f5e4d3c2b109000000069a1b2c3d4ef7')) __d = unhexlify(b('00000005ff000000051122334455ff0000000a00f00000000000000000010000000363617400000003612c62')) def test_1_encode(self):