safe type checking (isinstance instead of type-is)

Maintainer note: added changelog entry.
This commit is contained in:
Jeff Forcier 2012-04-19 15:19:59 -07:00
parent ccb9d75177
commit 8917d83221
2 changed files with 7 additions and 4 deletions

View File

@ -4,6 +4,9 @@ Temporary, post-Paramiko changelog while we get our sh!t together.
* #15: Implemented parameter substitution in SSHConfig, matching the * #15: Implemented parameter substitution in SSHConfig, matching the
implementation of `ssh_config(5)`. Thanks to Olle Lundberg for the patch. 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) ## ssh 1.7.13 (2012-02-13)

View File

@ -641,13 +641,13 @@ class SFTPClient (BaseSFTP):
msg = Message() msg = Message()
msg.add_int(self.request_number) msg.add_int(self.request_number)
for item in arg: for item in arg:
if type(item) is int: if isinstance(item, int):
msg.add_int(item) msg.add_int(item)
elif type(item) is long: elif isinstance(item, long):
msg.add_int64(item) msg.add_int64(item)
elif type(item) is str: elif isinstance(item, str):
msg.add_string(item) msg.add_string(item)
elif type(item) is SFTPAttributes: elif isinstance(item, SFTPAttributes):
item._pack(msg) item._pack(msg)
else: else:
raise Exception('unknown type for %r type %r' % (item, type(item))) raise Exception('unknown type for %r type %r' % (item, type(item)))