diff --git a/paramiko/ber.py b/paramiko/ber.py index 19568dd..4aa788d 100644 --- a/paramiko/ber.py +++ b/paramiko/ber.py @@ -16,8 +16,8 @@ # along with Paramiko; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - -import util +from __future__ import absolute_import +from paramiko import util class BERException (Exception): diff --git a/paramiko/file.py b/paramiko/file.py index 7e2904e..9782218 100644 --- a/paramiko/file.py +++ b/paramiko/file.py @@ -20,7 +20,10 @@ BufferedFile. """ -from cStringIO import StringIO +try: + from cStringIO import StringIO +except ImportError: + from io import StringIO class BufferedFile (object): diff --git a/paramiko/message.py b/paramiko/message.py index fb9e565..e492cd7 100644 --- a/paramiko/message.py +++ b/paramiko/message.py @@ -21,7 +21,10 @@ Implementation of an SSH2 "message". """ import struct -import cStringIO +try: + from cStringIO import StringIO +except ImportError: + from io import StringIO from paramiko import util @@ -46,9 +49,9 @@ class Message (object): @type content: string """ if content != None: - self.packet = cStringIO.StringIO(content) + self.packet = StringIO(content) else: - self.packet = cStringIO.StringIO() + self.packet = StringIO() def __str__(self): """ diff --git a/paramiko/packet.py b/paramiko/packet.py index df443bb..e755782 100644 --- a/paramiko/packet.py +++ b/paramiko/packet.py @@ -347,7 +347,7 @@ class Packetizer (object): if self.__block_engine_in != None: header = self.__block_engine_in.decrypt(header) if self.__dump_packets: - self._log(DEBUG, util.format_binary(header, 'IN: ')); + self._log(DEBUG, util.format_binary(header, 'IN: ')) packet_size = struct.unpack('>I', header[:4])[0] # leftover contains decrypted bytes from the first block (after the length field) leftover = header[4:] @@ -359,7 +359,7 @@ class Packetizer (object): if self.__block_engine_in != None: packet = self.__block_engine_in.decrypt(packet) if self.__dump_packets: - self._log(DEBUG, util.format_binary(packet, 'IN: ')); + self._log(DEBUG, util.format_binary(packet, 'IN: ')) packet = leftover + packet if self.__mac_size_in > 0: diff --git a/paramiko/sftp.py b/paramiko/sftp.py index a0b08e0..329f077 100644 --- a/paramiko/sftp.py +++ b/paramiko/sftp.py @@ -180,7 +180,7 @@ class BaseSFTP (object): size = struct.unpack('>I', x)[0] data = self._read_all(size) if self.ultra_debug: - self._log(DEBUG, util.format_binary(data, 'IN: ')); + self._log(DEBUG, util.format_binary(data, 'IN: ')) if size > 0: t = ord(data[0]) #self._log(DEBUG2, 'read: %s (len=%d)' % (CMD_NAMES.get(t), '0x%02x' % t, len(data)-1)) diff --git a/paramiko/transport.py b/paramiko/transport.py index ca35d53..94f38e6 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -762,7 +762,7 @@ class Transport (threading.Thread): self.lock.release() self._send_user_message(m) while True: - event.wait(0.1); + event.wait(0.1) if not self.active: e = self.get_exception() if e is None: diff --git a/tests/test_pkey.py b/tests/test_pkey.py index 89d5580..deb6d7c 100644 --- a/tests/test_pkey.py +++ b/tests/test_pkey.py @@ -21,7 +21,10 @@ Some unit tests for public/private key objects. """ from binascii import hexlify, unhexlify -import StringIO +try: + from StringIO import StringIO +except ImportError: + from io import StringIO import unittest from paramiko import RSAKey, DSSKey, Message, util from paramiko.common import rng @@ -90,7 +93,7 @@ class KeyTest (unittest.TestCase): self.assertEquals(PUB_RSA.split()[1], key.get_base64()) self.assertEquals(1024, key.get_bits()) - s = StringIO.StringIO() + s = StringIO() key.write_private_key(s) self.assertEquals(RSA_PRIVATE_OUT, s.getvalue()) s.seek(0) @@ -115,7 +118,7 @@ class KeyTest (unittest.TestCase): self.assertEquals(PUB_DSS.split()[1], key.get_base64()) self.assertEquals(1024, key.get_bits()) - s = StringIO.StringIO() + s = StringIO() key.write_private_key(s) self.assertEquals(DSS_PRIVATE_OUT, s.getvalue()) s.seek(0) diff --git a/tests/test_sftp.py b/tests/test_sftp.py index 459d17c..40e0f0d 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -23,6 +23,7 @@ a real actual sftp server is contacted, and a new folder is created there to do test file operations in (so no existing files will be harmed). """ +from __future__ import absolute_import from __future__ import with_statement from binascii import hexlify @@ -31,7 +32,10 @@ import warnings import sys import threading import unittest -import StringIO +try: + from StringIO import StringIO +except ImportError: + from io import StringIO import paramiko from stub_sftp import StubServer, StubSFTPServer @@ -731,7 +735,7 @@ class SFTPTest (unittest.TestCase): Send an empty file and confirm it is sent. """ target = FOLDER + '/empty file.txt' - stream = StringIO.StringIO() + stream = StringIO() try: attrs = sftp.putfo(stream, target) # the returned attributes should not be null diff --git a/tests/test_util.py b/tests/test_util.py index efda9b2..f263696 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -21,7 +21,10 @@ Some unit tests for utility functions. """ from binascii import hexlify -import cStringIO +try: + from cStringIO import StringIO +except ImportError: + from io import StringIO import errno import os import unittest @@ -101,7 +104,7 @@ class UtilTest(ParamikoTest): def test_2_parse_config(self): global test_config_file - f = cStringIO.StringIO(test_config_file) + f = StringIO(test_config_file) config = paramiko.util.parse_ssh_config(f) self.assertEquals(config._config, [{'host': ['*'], 'config': {}}, {'host': ['*'], 'config': {'identityfile': ['~/.ssh/id_rsa'], 'user': 'robey'}}, @@ -111,7 +114,7 @@ class UtilTest(ParamikoTest): def test_3_host_config(self): global test_config_file - f = cStringIO.StringIO(test_config_file) + f = StringIO(test_config_file) config = paramiko.util.parse_ssh_config(f) for host, values in { @@ -172,7 +175,7 @@ Host *.example.com Host * Port 3333 """ - f = cStringIO.StringIO(test_config_file) + f = StringIO(test_config_file) config = paramiko.util.parse_ssh_config(f) host = 'www13.example.com' self.assertEquals( @@ -216,7 +219,7 @@ Host space-delimited Host equals-delimited ProxyCommand=foo bar=biz baz """ - f = cStringIO.StringIO(conf) + f = StringIO(conf) config = paramiko.util.parse_ssh_config(f) for host in ('space-delimited', 'equals-delimited'): self.assertEquals( @@ -228,7 +231,7 @@ Host equals-delimited """ ProxyCommand should perform interpolation on the value """ - config = paramiko.util.parse_ssh_config(cStringIO.StringIO(""" + config = paramiko.util.parse_ssh_config(StringIO(""" Host specific Port 37 ProxyCommand host %h port %p lol @@ -264,7 +267,7 @@ Host www13.* Host * Port 3333 """ - f = cStringIO.StringIO(test_config_file) + f = StringIO(test_config_file) config = paramiko.util.parse_ssh_config(f) host = 'www13.example.com' self.assertEquals( @@ -293,7 +296,7 @@ ProxyCommand foo=bar:%h-%p 'foo=bar:proxy-without-equal-divisor-22'} }.items(): - f = cStringIO.StringIO(test_config_file) + f = StringIO(test_config_file) config = paramiko.util.parse_ssh_config(f) self.assertEquals( paramiko.util.lookup_ssh_host_config(host, config), @@ -323,7 +326,7 @@ IdentityFile id_dsa22 'identityfile': ['id_dsa0', 'id_dsa1', 'id_dsa22']} }.items(): - f = cStringIO.StringIO(test_config_file) + f = StringIO(test_config_file) config = paramiko.util.parse_ssh_config(f) self.assertEquals( paramiko.util.lookup_ssh_host_config(host, config),