[Python 3]: Added fix for enabling proper adding of integers under both Python 2 and 3.
This commit is contained in:
parent
3c33c763a7
commit
9ffd9efb20
|
@ -20,11 +20,15 @@
|
||||||
Implementation of an SSH2 "message".
|
Implementation of an SSH2 "message".
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
try:
|
try:
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
import six
|
||||||
|
if six.PY3:
|
||||||
|
long = lambda x: int(x)
|
||||||
|
|
||||||
from paramiko import util
|
from paramiko import util
|
||||||
|
|
||||||
|
@ -219,7 +223,7 @@ class Message (object):
|
||||||
else:
|
else:
|
||||||
self.add_byte('\x00')
|
self.add_byte('\x00')
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def add_int(self, n):
|
def add_int(self, n):
|
||||||
"""
|
"""
|
||||||
Add an integer to the stream.
|
Add an integer to the stream.
|
||||||
|
@ -273,17 +277,21 @@ class Message (object):
|
||||||
"""
|
"""
|
||||||
self.add_string(','.join(l))
|
self.add_string(','.join(l))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def _add(self, i):
|
def _add(self, i):
|
||||||
if type(i) is str:
|
if type(i) is str:
|
||||||
return self.add_string(i)
|
return self.add_string(i)
|
||||||
elif type(i) is int:
|
|
||||||
return self.add_int(i)
|
elif type(i) in six.integer_types:
|
||||||
elif type(i) is long:
|
|
||||||
if i > long(0xffffffff):
|
if type(i) is int and not six.PY3:
|
||||||
return self.add_mpint(i)
|
|
||||||
else:
|
|
||||||
return self.add_int(i)
|
return self.add_int(i)
|
||||||
|
else:
|
||||||
|
if i > long(0xffffffff):
|
||||||
|
return self.add_mpint(i)
|
||||||
|
else:
|
||||||
|
return self.add_int(i)
|
||||||
|
|
||||||
elif type(i) is bool:
|
elif type(i) is bool:
|
||||||
return self.add_boolean(i)
|
return self.add_boolean(i)
|
||||||
elif type(i) is list:
|
elif type(i) is list:
|
||||||
|
|
Loading…
Reference in New Issue