diff options
-rw-r--r-- | paramiko/packet.py | 16 | ||||
-rw-r--r-- | paramiko/primes.py | 7 | ||||
-rw-r--r-- | paramiko/server.py | 10 | ||||
-rw-r--r-- | paramiko/sftp_file.py | 12 | ||||
-rw-r--r-- | paramiko/ssh_exception.py | 3 | ||||
-rw-r--r-- | paramiko/ssh_gss.py | 16 | ||||
-rw-r--r-- | paramiko/transport.py | 15 | ||||
-rw-r--r-- | paramiko/util.py | 3 | ||||
-rw-r--r-- | tests/test_gssapi.py | 8 |
9 files changed, 58 insertions, 32 deletions
diff --git a/paramiko/packet.py b/paramiko/packet.py index 6f3cd4e2..16288a0a 100644 --- a/paramiko/packet.py +++ b/paramiko/packet.py @@ -394,9 +394,11 @@ class Packetizer (object): self.__sent_bytes += len(out) self.__sent_packets += 1 - if (self.__sent_packets >= self.REKEY_PACKETS or - self.__sent_bytes >= self.REKEY_BYTES)\ - and not self.__need_rekey: + sent_too_much = ( + self.__sent_packets >= self.REKEY_PACKETS or + self.__sent_bytes >= self.REKEY_BYTES + ) + if sent_too_much and not self.__need_rekey: # only ask once for rekeying self._log(DEBUG, 'Rekeying (hit %d packets, %d bytes sent)' % (self.__sent_packets, self.__sent_bytes)) @@ -506,9 +508,11 @@ class Packetizer (object): self.__logger.log(level, msg) def _check_keepalive(self): - if (not self.__keepalive_interval) or \ - (not self.__block_engine_out) or \ - self.__need_rekey: + if ( + not self.__keepalive_interval or + not self.__block_engine_out or + self.__need_rekey + ): # wait till we're encrypting, and not in the middle of rekeying return now = time.time() diff --git a/paramiko/primes.py b/paramiko/primes.py index 50100ad5..48a34e53 100644 --- a/paramiko/primes.py +++ b/paramiko/primes.py @@ -75,8 +75,11 @@ class ModulusPack (object): # type 2 (meets basic structural requirements) # test 4 (more than just a small-prime sieve) # tries < 100 if test & 4 (at least 100 tries of miller-rabin) - if (mod_type < 2) or (tests < 4) or \ - ((tests & 4) and (tests < 8) and (tries < 100)): + if ( + mod_type < 2 or + tests < 4 or + (tests & 4 and tests < 8 and tries < 100) + ): self.discarded.append( (modulus, 'does not meet basic requirements')) return diff --git a/paramiko/server.py b/paramiko/server.py index 89278a82..953bb33f 100644 --- a/paramiko/server.py +++ b/paramiko/server.py @@ -22,8 +22,10 @@ import threading from paramiko import util -from paramiko.common import DEBUG, ERROR, \ - OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED, AUTH_FAILED, AUTH_SUCCESSFUL +from paramiko.common import ( + DEBUG, ERROR, OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED, AUTH_FAILED, + AUTH_SUCCESSFUL, +) from paramiko.py3compat import string_types @@ -450,8 +452,8 @@ class ServerInterface (object): ``True`` if this channel is now hooked up to the requested subsystem; ``False`` if that subsystem can't or won't be provided. """ - handler_class, larg, kwarg = \ - channel.get_transport()._get_subsystem_handler(name) + transport = channel.get_transport() + handler_class, larg, kwarg = transport._get_subsystem_handler(name) if handler_class is None: return False handler = handler_class(channel, name, self, *larg, **kwarg) diff --git a/paramiko/sftp_file.py b/paramiko/sftp_file.py index 13e28e28..58653c79 100644 --- a/paramiko/sftp_file.py +++ b/paramiko/sftp_file.py @@ -194,8 +194,10 @@ class SFTPFile (BufferedFile): data[:chunk] ) self._reqs.append(sftp_async_request) - if not self.pipelined or \ - (len(self._reqs) > 100 and self.sftp.sock.recv_ready()): + if ( + not self.pipelined or + (len(self._reqs) > 100 and self.sftp.sock.recv_ready()) + ): while len(self._reqs): req = self._reqs.popleft() t, msg = self.sftp._read_response(req) @@ -476,8 +478,10 @@ class SFTPFile (BufferedFile): read_chunks = [] for offset, size in chunks: # don't fetch data that's already in the prefetch buffer - if self._data_in_prefetch_buffers(offset) or \ - self._data_in_prefetch_requests(offset, size): + if ( + self._data_in_prefetch_buffers(offset) or + self._data_in_prefetch_requests(offset, size) + ): continue # break up anything larger than the max read size diff --git a/paramiko/ssh_exception.py b/paramiko/ssh_exception.py index eb63df4e..e3584d89 100644 --- a/paramiko/ssh_exception.py +++ b/paramiko/ssh_exception.py @@ -108,8 +108,7 @@ class BadHostKeyException (SSHException): .. versionadded:: 1.6 """ def __init__(self, hostname, got_key, expected_key): - message = 'Host key for server {} does not match : ' \ - 'got {} expected {}' + message = 'Host key for server {} does not match: got {} expected {}' message = message.format( hostname, got_key.get_base64(), expected_key.get_base64()) diff --git a/paramiko/ssh_gss.py b/paramiko/ssh_gss.py index 8bb0c2e0..9c88c6fc 100644 --- a/paramiko/ssh_gss.py +++ b/paramiko/ssh_gss.py @@ -405,12 +405,16 @@ class _SSH_SSPI(_SSH_GSSAuth): _SSH_GSSAuth.__init__(self, auth_method, gss_deleg_creds) if self._gss_deleg_creds: - self._gss_flags = \ - sspicon.ISC_REQ_INTEGRITY | sspicon.ISC_REQ_MUTUAL_AUTH | \ + self._gss_flags = ( + sspicon.ISC_REQ_INTEGRITY | + sspicon.ISC_REQ_MUTUAL_AUTH | sspicon.ISC_REQ_DELEGATE + ) else: - self._gss_flags = \ - sspicon.ISC_REQ_INTEGRITY | sspicon.ISC_REQ_MUTUAL_AUTH + self._gss_flags = ( + sspicon.ISC_REQ_INTEGRITY | + sspicon.ISC_REQ_MUTUAL_AUTH + ) def ssh_init_sec_context(self, target, desired_mech=None, username=None, recv_token=None): @@ -546,8 +550,10 @@ class _SSH_SSPI(_SSH_GSSAuth): :return: ``True`` if credentials are delegated, otherwise ``False`` :rtype: Boolean """ - return self._gss_flags & sspicon.ISC_REQ_DELEGATE and \ + return ( + self._gss_flags & sspicon.ISC_REQ_DELEGATE and (self._gss_srv_ctxt_status or self._gss_flags) + ) def save_client_creds(self, client_token): """ diff --git a/paramiko/transport.py b/paramiko/transport.py index 0a570977..129562d1 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -2125,8 +2125,13 @@ class Transport (threading.Thread, ClosingContextManager): self.packetizer.set_outbound_cipher( engine, block_size, mac_engine, mac_size, mac_key, sdctr) compress_out = self._compression_info[self.local_compression][0] - if (compress_out is not None) and \ - ((self.local_compression != 'zlib@openssh.com') or self.authenticated): + if ( + compress_out is not None and + ( + self.local_compression != 'zlib@openssh.com' or + self.authenticated + ) + ): self._log(DEBUG, 'Switching on outbound compression ...') self.packetizer.set_outbound_compressor(compress_out()) if not self.packetizer.need_rekey(): @@ -2275,8 +2280,10 @@ class Transport (threading.Thread, ClosingContextManager): initial_window_size = m.get_int() max_packet_size = m.get_int() reject = False - if (kind == 'auth-agent@openssh.com') and \ - (self._forward_agent_handler is not None): + if ( + kind == 'auth-agent@openssh.com' and + self._forward_agent_handler is not None + ): self._log(DEBUG, 'Incoming forward agent connection') self.lock.acquire() try: diff --git a/paramiko/util.py b/paramiko/util.py index 82157c24..de099c0c 100644 --- a/paramiko/util.py +++ b/paramiko/util.py @@ -248,8 +248,7 @@ def log_to_file(filename, level=DEBUG): l.setLevel(level) f = open(filename, 'a') lh = logging.StreamHandler(f) - frm = '%(levelname)-.3s [%(asctime)s.%(msecs)03d] thr=%(_threadid)-3d ' \ - '%(name)s: %(message)s' + frm = '%(levelname)-.3s [%(asctime)s.%(msecs)03d] thr=%(_threadid)-3d %(name)s: %(message)s' # noqa lh.setFormatter(logging.Formatter(frm, '%Y%m%d-%H:%M:%S')) l.addHandler(lh) diff --git a/tests/test_gssapi.py b/tests/test_gssapi.py index 96c268d9..bc220108 100644 --- a/tests/test_gssapi.py +++ b/tests/test_gssapi.py @@ -104,9 +104,11 @@ class GSSAPITest(unittest.TestCase): status = gss_srv_ctxt.verify_mic(mic_msg, mic_token) self.assertEquals(0, status) else: - gss_flags = sspicon.ISC_REQ_INTEGRITY |\ - sspicon.ISC_REQ_MUTUAL_AUTH |\ - sspicon.ISC_REQ_DELEGATE + gss_flags = ( + sspicon.ISC_REQ_INTEGRITY | + sspicon.ISC_REQ_MUTUAL_AUTH | + sspicon.ISC_REQ_DELEGATE + ) # Initialize a GSS-API context. target_name = "host/" + socket.getfqdn(targ_name) gss_ctxt = sspi.ClientAuth("Kerberos", |