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 MANIFEST *.log demos/*.log
rm -f paramiko/*.pyc rm -f paramiko/*.pyc
rm -f test.log rm -f test.log
rm -rf paramiko.egg-info
test: test:
python ./test.py python ./test.py

1
README
View File

@ -239,6 +239,7 @@ v1.5 PARAS
*** MISSING LINKS *** MISSING LINKS
* allow setting chmod bits on SFTPClient.open() for create
* host-based auth (yuck!) * host-based auth (yuck!)
* ctr forms of ciphers are missing (blowfish-ctr, aes128-ctr, aes256-ctr) * ctr forms of ciphers are missing (blowfish-ctr, aes128-ctr, aes256-ctr)
* sftp protocol 6 support (ugh....) -- once it settles down more * 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])) data = base64.decodestring(''.join(lines[start:end]))
except base64.binascii.Error, e: except base64.binascii.Error, e:
raise SSHException('base64 decoding error: ' + str(e)) raise SSHException('base64 decoding error: ' + str(e))
if not headers.has_key('proc-type'): if 'proc-type' not in headers:
# unencryped: done # unencryped: done
return data return data
# encrypted keyfile: will need a password # encrypted keyfile: will need a password
@ -315,7 +315,7 @@ class PKey (object):
encryption_type, saltstr = headers['dek-info'].split(',') encryption_type, saltstr = headers['dek-info'].split(',')
except: except:
raise SSHException('Can\'t parse DEK-info in private key file') 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) 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 no password was passed in, raise an exception pointing out that we need one
if password is None: if password is None:

View File

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

View File

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

View File

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