remove usage of has_key, which is dangerous and deprecated
This commit is contained in:
Robey Pointer 2006-08-29 11:18:36 -07:00
parent b23079b135
commit 1f4a3f1976
6 changed files with 28 additions and 26 deletions

View File

@ -41,6 +41,7 @@ clean:
rm -f MANIFEST *.log demos/*.log
rm -f paramiko/*.pyc
rm -f test.log
rm -rf paramiko.egg-info
test:
python ./test.py

1
README
View File

@ -239,6 +239,7 @@ v1.5 PARAS
*** MISSING LINKS
* allow setting chmod bits on SFTPClient.open() for create
* host-based auth (yuck!)
* ctr forms of ciphers are missing (blowfish-ctr, aes128-ctr, aes256-ctr)
* sftp protocol 6 support (ugh....) -- once it settles down more

View File

@ -305,7 +305,7 @@ class PKey (object):
data = base64.decodestring(''.join(lines[start:end]))
except base64.binascii.Error, e:
raise SSHException('base64 decoding error: ' + str(e))
if not headers.has_key('proc-type'):
if 'proc-type' not in headers:
# unencryped: done
return data
# encrypted keyfile: will need a password
@ -315,7 +315,7 @@ class PKey (object):
encryption_type, saltstr = headers['dek-info'].split(',')
except:
raise SSHException('Can\'t parse DEK-info in private key file')
if not self._CIPHER_TABLE.has_key(encryption_type):
if encryption_type not in self._CIPHER_TABLE:
raise SSHException('Unknown private key cipher "%s"' % encryption_type)
# if no password was passed in, raise an exception pointing out that we need one
if password is None:

View File

@ -103,7 +103,7 @@ class ModulusPack (object):
if (bl != size) and (bl != size + 1):
self.discarded.append((modulus, 'incorrectly reported bit length %d' % size))
return
if not self.pack.has_key(bl):
if bl not in self.pack:
self.pack[bl] = []
self.pack[bl].append((generator, modulus))

View File

@ -239,7 +239,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
start = msg.get_int64()
length = msg.get_int64()
block_size = msg.get_int()
if not self.file_table.has_key(handle):
if handle not in self.file_table:
self._send_status(request_number, SFTP_BAD_MESSAGE, 'Invalid handle')
return
f = self.file_table[handle]
@ -315,11 +315,11 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
self._send_handle_response(request_number, self.server.open(path, flags, attr))
elif t == CMD_CLOSE:
handle = msg.get_string()
if self.folder_table.has_key(handle):
if handle in self.folder_table:
del self.folder_table[handle]
self._send_status(request_number, SFTP_OK)
return
if self.file_table.has_key(handle):
if handle in self.file_table:
self.file_table[handle].close()
del self.file_table[handle]
self._send_status(request_number, SFTP_OK)
@ -329,7 +329,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
handle = msg.get_string()
offset = msg.get_int64()
length = msg.get_int()
if not self.file_table.has_key(handle):
if handle not in self.file_table:
self._send_status(request_number, SFTP_BAD_MESSAGE, 'Invalid handle')
return
data = self.file_table[handle].read(offset, length)
@ -344,7 +344,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
handle = msg.get_string()
offset = msg.get_int64()
data = msg.get_string()
if not self.file_table.has_key(handle):
if handle not in self.file_table:
self._send_status(request_number, SFTP_BAD_MESSAGE, 'Invalid handle')
return
self._send_status(request_number, self.file_table[handle].write(offset, data))
@ -368,7 +368,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
return
elif t == CMD_READDIR:
handle = msg.get_string()
if not self.folder_table.has_key(handle):
if handle not in self.folder_table:
self._send_status(request_number, SFTP_BAD_MESSAGE, 'Invalid handle')
return
folder = self.folder_table[handle]
@ -389,7 +389,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
self._send_status(request_number, resp)
elif t == CMD_FSTAT:
handle = msg.get_string()
if not self.file_table.has_key(handle):
if handle not in self.file_table:
self._send_status(request_number, SFTP_BAD_MESSAGE, 'Invalid handle')
return
resp = self.file_table[handle].stat()
@ -404,7 +404,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
elif t == CMD_FSETSTAT:
handle = msg.get_string()
attr = SFTPAttributes._from_msg(msg)
if not self.file_table.has_key(handle):
if handle not in self.file_table:
self._response(request_number, SFTP_BAD_MESSAGE, 'Invalid handle')
return
self._send_status(request_number, self.file_table[handle].chattr(attr))

View File

@ -619,7 +619,7 @@ class Transport (threading.Thread):
self.lock.acquire()
try:
chanid = self.channel_counter
while self.channels.has_key(chanid):
while chanid in self.channels:
self.channel_counter = (self.channel_counter + 1) & 0xffffff
chanid = self.channel_counter
self.channel_counter = (self.channel_counter + 1) & 0xffffff
@ -653,7 +653,7 @@ class Transport (threading.Thread):
break
self.lock.acquire()
try:
if self.channels.has_key(chanid):
if chanid in self.channels:
return chan
finally:
self.lock.release()
@ -1242,7 +1242,7 @@ class Transport (threading.Thread):
"used by a Channel to remove itself from the active channel list"
try:
self.lock.acquire()
if self.channels.has_key(chanid):
if chanid in self.channels:
del self.channels[chanid]
finally:
self.lock.release()
@ -1307,7 +1307,7 @@ class Transport (threading.Thread):
return out[:nbytes]
def _get_cipher(self, name, key, iv):
if not self._cipher_info.has_key(name):
if name not in self._cipher_info:
raise SSHException('Unknown client cipher ' + name)
return self._cipher_info[name]['class'].new(key, self._cipher_info[name]['mode'], iv)
@ -1354,19 +1354,19 @@ class Transport (threading.Thread):
self.kex_engine.parse_next(ptype, m)
continue
if self._handler_table.has_key(ptype):
if ptype in self._handler_table:
self._handler_table[ptype](self, m)
elif self._channel_handler_table.has_key(ptype):
elif ptype in self._channel_handler_table:
chanid = m.get_int()
if self.channels.has_key(chanid):
if chanid in self.channels:
self._channel_handler_table[ptype](self.channels[chanid], m)
elif self.channels_seen.has_key(chanid):
elif chanid in self.channels_seen:
self._log(DEBUG, 'Ignoring message for dead channel %d' % chanid)
else:
self._log(ERROR, 'Channel request for unknown channel %d' % chanid)
self.active = False
self.packetizer.close()
elif (self.auth_handler is not None) and self.auth_handler._handler_table.has_key(ptype):
elif (self.auth_handler is not None) and (ptype in self.auth_handler._handler_table):
self.auth_handler._handler_table[ptype](self.auth_handler, m)
else:
self._log(WARNING, 'Oops, unhandled type %d' % ptype)
@ -1736,7 +1736,7 @@ class Transport (threading.Thread):
server_chanid = m.get_int()
server_window_size = m.get_int()
server_max_packet_size = m.get_int()
if not self.channels.has_key(chanid):
if chanid not in self.channels:
self._log(WARNING, 'Success for unrequested channel! [??]')
return
self.lock.acquire()
@ -1744,7 +1744,7 @@ class Transport (threading.Thread):
chan = self.channels[chanid]
chan._set_remote_channel(server_chanid, server_window_size, server_max_packet_size)
self._log(INFO, 'Secsh channel %d opened.' % chanid)
if self.channel_events.has_key(chanid):
if chanid in self.channel_events:
self.channel_events[chanid].set()
del self.channel_events[chanid]
finally:
@ -1761,9 +1761,9 @@ class Transport (threading.Thread):
self.lock.acquire()
try:
self.saved_exception = ChannelException(reason, reason_text)
if self.channel_events.has_key(chanid):
if chanid in self.channel_events:
del self.channels[chanid]
if self.channel_events.has_key(chanid):
if chanid in self.channel_events:
self.channel_events[chanid].set()
del self.channel_events[chanid]
finally:
@ -1784,7 +1784,7 @@ class Transport (threading.Thread):
self.lock.acquire()
try:
my_chanid = self.channel_counter
while self.channels.has_key(my_chanid):
while my_chanid in self.channels:
self.channel_counter = (self.channel_counter + 1) & 0xffffff
my_chanid = self.channel_counter
self.channel_counter = (self.channel_counter + 1) & 0xffffff
@ -1837,7 +1837,7 @@ class Transport (threading.Thread):
def _get_subsystem_handler(self, name):
try:
self.lock.acquire()
if not self.subsystem_table.has_key(name):
if name not in self.subsystem_table:
return (None, [], {})
return self.subsystem_table[name]
finally: