summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorScott Maxwell <scott@codecobblers.com>2013-11-02 20:19:52 -0700
committerScott Maxwell <scott@codecobblers.com>2013-11-02 20:19:52 -0700
commitdc58b7bcb2bf6c945878a841b1861f0f195a3075 (patch)
tree586d7fca5938a33b1d5ac32405d4d342992d9570
parent7444a999931cddc1e61bb35270468aa45da2687e (diff)
Fix message to handle long properly, even on Py3
-rw-r--r--paramiko/message.py5
-rw-r--r--paramiko/sftp_client.py6
-rw-r--r--paramiko/sftp_server.py6
-rw-r--r--tests/test_message.py2
4 files changed, 10 insertions, 9 deletions
diff --git a/paramiko/message.py b/paramiko/message.py
index 8e81e69b..45086213 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 31e66972..5a08db6a 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 2a1a4430..38adc63c 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 f983b4de..cb815f9f 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):