From 66cfa97cce92b1d60383d178887b18dddb999fc1 Mon Sep 17 00:00:00 2001 From: Scott Maxwell Date: Wed, 30 Oct 2013 16:19:30 -0700 Subject: Fix imports --- test.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'test.py') diff --git a/test.py b/test.py index 6702e53a..159794c5 100755 --- a/test.py +++ b/test.py @@ -32,19 +32,19 @@ import threading sys.path.append('tests') -from test_message import MessageTest -from test_file import BufferedFileTest -from test_buffered_pipe import BufferedPipeTest -from test_util import UtilTest -from test_hostkeys import HostKeysTest -from test_pkey import KeyTest -from test_kex import KexTest -from test_packetizer import PacketizerTest -from test_auth import AuthTest -from test_transport import TransportTest -from test_sftp import SFTPTest -from test_sftp_big import BigSFTPTest -from test_client import SSHClientTest +from tests.test_message import MessageTest +from tests.test_file import BufferedFileTest +from tests.test_buffered_pipe import BufferedPipeTest +from tests.test_util import UtilTest +from tests.test_hostkeys import HostKeysTest +from tests.test_pkey import KeyTest +from tests.test_kex import KexTest +from tests.test_packetizer import PacketizerTest +from tests.test_auth import AuthTest +from tests.test_transport import TransportTest +from tests.test_sftp import SFTPTest +from tests.test_sftp_big import BigSFTPTest +from tests.test_client import SSHClientTest default_host = 'localhost' default_user = os.environ.get('USER', 'nobody') -- cgit v1.2.3 From 06b866cf406c035ecaffd7a8abd31d6e07b8811a Mon Sep 17 00:00:00 2001 From: Scott Maxwell Date: Fri, 1 Nov 2013 01:06:17 -0700 Subject: Don't import test_sftp or test_sftp_big unless we are going to do the tests --- test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test.py') diff --git a/test.py b/test.py index 159794c5..1162da07 100755 --- a/test.py +++ b/test.py @@ -42,8 +42,6 @@ from tests.test_kex import KexTest from tests.test_packetizer import PacketizerTest from tests.test_auth import AuthTest from tests.test_transport import TransportTest -from tests.test_sftp import SFTPTest -from tests.test_sftp_big import BigSFTPTest from tests.test_client import SSHClientTest default_host = 'localhost' @@ -109,13 +107,16 @@ def main(): paramiko.util.log_to_file('test.log') if options.use_sftp: + from tests.test_sftp import SFTPTest if options.use_loopback_sftp: SFTPTest.init_loopback() else: SFTPTest.init(options.hostname, options.username, options.keyfile, options.password) if not options.use_big_file: SFTPTest.set_big_file_test(False) - + if options.use_big_file: + from tests.test_sftp_big import BigSFTPTest + suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(MessageTest)) suite.addTest(unittest.makeSuite(BufferedFileTest)) -- cgit v1.2.3 From 7decda3297089b2b2e73bb9cd7e577f9b2cb2789 Mon Sep 17 00:00:00 2001 From: Scott Maxwell Date: Fri, 1 Nov 2013 12:32:57 -0700 Subject: Fix thread stop for Py3 --- test.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test.py') diff --git a/test.py b/test.py index 1162da07..c8ac6bc3 100755 --- a/test.py +++ b/test.py @@ -29,6 +29,7 @@ import unittest from optparse import OptionParser import paramiko import threading +from paramiko.py3compat import PY3 sys.path.append('tests') @@ -148,7 +149,10 @@ def main(): # TODO: make that not a problem, jeez for thread in threading.enumerate(): if thread is not threading.currentThread(): - thread._Thread__stop() + if PY3: + thread._stop() + else: + thread._Thread__stop() # Exit correctly if not result.wasSuccessful(): sys.exit(1) -- cgit v1.2.3 From 3ce336c88b7bfbfad03fab17bff8cb3c3a77176c Mon Sep 17 00:00:00 2001 From: Scott Maxwell Date: Tue, 19 Nov 2013 07:30:45 -0800 Subject: Change conditional from PY3 to PY2 to be better prepared for a possible Py4. --- paramiko/common.py | 8 +-- paramiko/file.py | 6 +-- paramiko/py3compat.py | 146 +++++++++++++++++++++++++++----------------------- paramiko/util.py | 4 +- test.py | 8 +-- tests/test_pkey.py | 2 +- tests/test_sftp.py | 4 +- 7 files changed, 96 insertions(+), 82 deletions(-) (limited to 'test.py') diff --git a/paramiko/common.py b/paramiko/common.py index 223aac1a..e30df73a 100644 --- a/paramiko/common.py +++ b/paramiko/common.py @@ -131,12 +131,12 @@ cr_byte = byte_chr(13) linefeed_byte = byte_chr(10) crlf = cr_byte + linefeed_byte -if PY3: - cr_byte_value = 13 - linefeed_byte_value = 10 -else: +if PY2: cr_byte_value = cr_byte linefeed_byte_value = linefeed_byte +else: + cr_byte_value = 13 + linefeed_byte_value = 10 def asbytes(s): diff --git a/paramiko/file.py b/paramiko/file.py index a0d94ef2..c9f191a4 100644 --- a/paramiko/file.py +++ b/paramiko/file.py @@ -92,8 +92,8 @@ class BufferedFile (object): self._wbuffer = BytesIO() return - if PY3: - def __next__(self): + if PY2: + def next(self): """ Returns the next line from the input, or raises L{StopIteration} when EOF is hit. Unlike python file objects, it's okay to mix calls to @@ -109,7 +109,7 @@ class BufferedFile (object): raise StopIteration return line else: - def next(self): + def __next__(self): """ Returns the next line from the input, or raises L{StopIteration} when EOF is hit. Unlike python file objects, it's okay to mix calls to diff --git a/paramiko/py3compat.py b/paramiko/py3compat.py index 0aad3618..22285992 100644 --- a/paramiko/py3compat.py +++ b/paramiko/py3compat.py @@ -1,76 +1,13 @@ import sys import base64 -__all__ = ['PY3', 'string_types', 'integer_types', 'text_type', 'bytes_types', 'bytes', 'long', 'input', +__all__ = ['PY2', 'string_types', 'integer_types', 'text_type', 'bytes_types', 'bytes', 'long', 'input', 'decodebytes', 'encodebytes', 'bytestring', 'byte_ord', 'byte_chr', 'byte_mask', 'b', 'u', 'b2s', 'StringIO', 'BytesIO', 'is_callable', 'MAXSIZE', 'next'] -PY3 = sys.version_info[0] >= 3 +PY2 = sys.version_info[0] < 3 -if PY3: - import collections - import struct - string_types = str - text_type = str - bytes = bytes - bytes_types = bytes - integer_types = int - class long(int): - pass - input = input - decodebytes = base64.decodebytes - encodebytes = base64.encodebytes - - def bytestring(s): - return s - - def byte_ord(c): - assert isinstance(c, int) - return c - - def byte_chr(c): - assert isinstance(c, int) - return struct.pack('B', c) - - def byte_mask(c, mask): - assert isinstance(c, int) - return struct.pack('B', c & mask) - - def b(s, encoding='utf8'): - """cast unicode or bytes to bytes""" - if isinstance(s, bytes): - return s - elif isinstance(s, str): - return s.encode(encoding) - else: - raise TypeError("Expected unicode or bytes, got %r" % s) - - def u(s, encoding='utf8'): - """cast bytes or unicode to unicode""" - if isinstance(s, bytes): - return s.decode(encoding) - elif isinstance(s, str): - return s - else: - raise TypeError("Expected unicode or bytes, got %r" % s) - - def b2s(s): - return s.decode() if isinstance(s, bytes) else s - - import io - StringIO = io.StringIO # NOQA - BytesIO = io.BytesIO # NOQA - - def is_callable(c): - return isinstance(c, collections.Callable) - - def get_next(c): - return c.__next__ - - next = next - - MAXSIZE = sys.maxsize # NOQA -else: +if PY2: string_types = basestring text_type = unicode bytes_types = str @@ -81,17 +18,21 @@ else: decodebytes = base64.decodestring encodebytes = base64.encodestring + def bytestring(s): # NOQA if isinstance(s, unicode): return s.encode('utf-8') return s + byte_ord = ord # NOQA byte_chr = chr # NOQA + def byte_mask(c, mask): return chr(ord(c) & mask) + def b(s, encoding='utf8'): # NOQA """cast unicode or bytes to bytes""" if isinstance(s, str): @@ -101,6 +42,7 @@ else: else: raise TypeError("Expected unicode or bytes, got %r" % s) + def u(s, encoding='utf8'): # NOQA """cast bytes or unicode to unicode""" if isinstance(s, str): @@ -110,24 +52,31 @@ else: else: raise TypeError("Expected unicode or bytes, got %r" % s) + def b2s(s): return s + try: import cStringIO + StringIO = cStringIO.StringIO # NOQA except ImportError: import StringIO + StringIO = StringIO.StringIO # NOQA BytesIO = StringIO + def is_callable(c): # NOQA return callable(c) + def get_next(c): # NOQA return c.next + def next(c): return c.next() @@ -135,6 +84,8 @@ else: class X(object): def __len__(self): return 1 << 31 + + try: len(X()) except OverflowError: @@ -144,3 +95,66 @@ else: # 64-bit MAXSIZE = int((1 << 63) - 1) # NOQA del X +else: + import collections + import struct + string_types = str + text_type = str + bytes = bytes + bytes_types = bytes + integer_types = int + class long(int): + pass + input = input + decodebytes = base64.decodebytes + encodebytes = base64.encodebytes + + def bytestring(s): + return s + + def byte_ord(c): + assert isinstance(c, int) + return c + + def byte_chr(c): + assert isinstance(c, int) + return struct.pack('B', c) + + def byte_mask(c, mask): + assert isinstance(c, int) + return struct.pack('B', c & mask) + + def b(s, encoding='utf8'): + """cast unicode or bytes to bytes""" + if isinstance(s, bytes): + return s + elif isinstance(s, str): + return s.encode(encoding) + else: + raise TypeError("Expected unicode or bytes, got %r" % s) + + def u(s, encoding='utf8'): + """cast bytes or unicode to unicode""" + if isinstance(s, bytes): + return s.decode(encoding) + elif isinstance(s, str): + return s + else: + raise TypeError("Expected unicode or bytes, got %r" % s) + + def b2s(s): + return s.decode() if isinstance(s, bytes) else s + + import io + StringIO = io.StringIO # NOQA + BytesIO = io.BytesIO # NOQA + + def is_callable(c): + return isinstance(c, collections.Callable) + + def get_next(c): + return c.__next__ + + next = next + + MAXSIZE = sys.maxsize # NOQA diff --git a/paramiko/util.py b/paramiko/util.py index 51fa6d66..71fc4673 100644 --- a/paramiko/util.py +++ b/paramiko/util.py @@ -63,8 +63,8 @@ def inflate_long(s, always_positive=False): out -= (long(1) << (8 * len(s))) return out -deflate_zero = 0 if PY3 else zero_byte -deflate_ff = 0xff if PY3 else max_byte +deflate_zero = zero_byte if PY2 else 0 +deflate_ff = max_byte if PY2 else 0xff def deflate_long(n, add_sign_padding=True): "turns a long-int into a normalized byte string (adapted from Crypto.Util.number)" diff --git a/test.py b/test.py index c8ac6bc3..bd966d1e 100755 --- a/test.py +++ b/test.py @@ -29,7 +29,7 @@ import unittest from optparse import OptionParser import paramiko import threading -from paramiko.py3compat import PY3 +from paramiko.py3compat import PY2 sys.path.append('tests') @@ -149,10 +149,10 @@ def main(): # TODO: make that not a problem, jeez for thread in threading.enumerate(): if thread is not threading.currentThread(): - if PY3: - thread._stop() - else: + if PY2: thread._Thread__stop() + else: + thread._stop() # Exit correctly if not result.wasSuccessful(): sys.exit(1) diff --git a/tests/test_pkey.py b/tests/test_pkey.py index f8549468..19c5c698 100644 --- a/tests/test_pkey.py +++ b/tests/test_pkey.py @@ -23,7 +23,7 @@ Some unit tests for public/private key objects. from binascii import hexlify, unhexlify import unittest from paramiko import RSAKey, DSSKey, ECDSAKey, Message, util -from paramiko.common import rng, StringIO, byte_chr, b, PY3, bytes +from paramiko.common import rng, StringIO, byte_chr, b, bytes from tests.util import test_path # from openssh's ssh-keygen diff --git a/tests/test_sftp.py b/tests/test_sftp.py index b84b3fd6..4a412582 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -72,8 +72,8 @@ FOLDER = os.environ.get('TEST_FOLDER', 'temp-testing000') sftp = None tc = None g_big_file_test = True -unicode_folder = eval(compile(r"'\u00fcnic\u00f8de'" if PY3 else r"u'\u00fcnic\u00f8de'", 'test_sftp.py', 'eval')) -utf8_folder = eval(compile(r"b'/\xc3\xbcnic\xc3\xb8\x64\x65'" if PY3 else r"'/\xc3\xbcnic\xc3\xb8\x64\x65'", 'test_sftp.py', 'eval')) +unicode_folder = eval(compile(r"u'\u00fcnic\u00f8de'" if PY2 else r"'\u00fcnic\u00f8de'", 'test_sftp.py', 'eval')) +utf8_folder = eval(compile(r"'/\xc3\xbcnic\xc3\xb8\x64\x65'" if PY2 else r"b'/\xc3\xbcnic\xc3\xb8\x64\x65'", 'test_sftp.py', 'eval')) def get_sftp(): global sftp -- cgit v1.2.3