From 8917d83221f2422f1c4c3e6fb8538ea9e1f9a150 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Thu, 19 Apr 2012 15:19:59 -0700 Subject: [PATCH] safe type checking (isinstance instead of type-is) Maintainer note: added changelog entry. --- CHANGES | 3 +++ ssh/sftp_client.py | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 69c1caf..be3b2ad 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,9 @@ Temporary, post-Paramiko changelog while we get our sh!t together. * #15: Implemented parameter substitution in SSHConfig, matching the implementation of `ssh_config(5)`. Thanks to Olle Lundberg for the patch. +* #24: Switch some internal type checking to use `isinstance` to help prevent + problems with client libraries using subclasses of builtin types. Thanks to + Alex Morega for the patch. ## ssh 1.7.13 (2012-02-13) diff --git a/ssh/sftp_client.py b/ssh/sftp_client.py index 3f4e358..f5b4d79 100644 --- a/ssh/sftp_client.py +++ b/ssh/sftp_client.py @@ -641,13 +641,13 @@ class SFTPClient (BaseSFTP): msg = Message() msg.add_int(self.request_number) for item in arg: - if type(item) is int: + if isinstance(item, int): msg.add_int(item) - elif type(item) is long: + elif isinstance(item, long): msg.add_int64(item) - elif type(item) is str: + elif isinstance(item, str): msg.add_string(item) - elif type(item) is SFTPAttributes: + elif isinstance(item, SFTPAttributes): item._pack(msg) else: raise Exception('unknown type for %r type %r' % (item, type(item)))