diff options
author | Robey Pointer <robey@lag.net> | 2006-08-29 11:18:36 -0700 |
---|---|---|
committer | Robey Pointer <robey@lag.net> | 2006-08-29 11:18:36 -0700 |
commit | 1f4a3f19764bdc7483ae503a946e631681ab3e6e (patch) | |
tree | 2e6b73c1b54e25f21db1dd506dc11c824681a944 | |
parent | b23079b1350c45e46f77851b86c6b518da857a43 (diff) |
[project @ robey@lag.net-20060829181836-1cd17df7729c4db8]
remove usage of has_key, which is dangerous and deprecated
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | paramiko/pkey.py | 4 | ||||
-rw-r--r-- | paramiko/primes.py | 2 | ||||
-rw-r--r-- | paramiko/sftp_server.py | 16 | ||||
-rw-r--r-- | paramiko/transport.py | 30 |
6 files changed, 28 insertions, 26 deletions
@@ -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 @@ -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 diff --git a/paramiko/pkey.py b/paramiko/pkey.py index 47f2378e..61babfb7 100644 --- a/paramiko/pkey.py +++ b/paramiko/pkey.py @@ -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: diff --git a/paramiko/primes.py b/paramiko/primes.py index f64d11a6..9bcc4dc8 100644 --- a/paramiko/primes.py +++ b/paramiko/primes.py @@ -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)) diff --git a/paramiko/sftp_server.py b/paramiko/sftp_server.py index 91328e24..e7dcaa6a 100644 --- a/paramiko/sftp_server.py +++ b/paramiko/sftp_server.py @@ -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)) diff --git a/paramiko/transport.py b/paramiko/transport.py index 02f67cb8..458155c6 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -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: |