From ec8948158e26df0ec549e333cc2ea4bb22d56350 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Wed, 11 Jan 2023 20:24:13 -0500 Subject: blacken --- paramiko/auth_handler.py | 4 +--- paramiko/ber.py | 6 +++--- paramiko/common.py | 18 +++++++++++------- paramiko/file.py | 4 +--- paramiko/kex_gex.py | 2 +- paramiko/kex_group1.py | 4 ++-- paramiko/kex_gss.py | 13 +++++++++---- paramiko/message.py | 2 +- paramiko/pkey.py | 2 +- paramiko/ssh_exception.py | 4 +--- paramiko/transport.py | 15 ++++++++++----- paramiko/util.py | 12 ++++++++++-- paramiko/win_pageant.py | 2 +- 13 files changed, 52 insertions(+), 36 deletions(-) (limited to 'paramiko') diff --git a/paramiko/auth_handler.py b/paramiko/auth_handler.py index f18a3ed6..18c83293 100644 --- a/paramiko/auth_handler.py +++ b/paramiko/auth_handler.py @@ -613,9 +613,7 @@ Error Message: {} self._log(INFO, "Auth rejected: public key: {}".format(str(e))) key = None except Exception as e: - msg = ( - "Auth rejected: unsupported or mangled public key ({}: {})" - ) # noqa + msg = "Auth rejected: unsupported or mangled public key ({}: {})" # noqa self._log(INFO, msg.format(e.__class__.__name__, e)) key = None if key is None: diff --git a/paramiko/ber.py b/paramiko/ber.py index 4e93e66f..051a9537 100644 --- a/paramiko/ber.py +++ b/paramiko/ber.py @@ -57,7 +57,7 @@ class BER(object): while self.idx < len(self.content): t = byte_ord(self.content[self.idx]) self.idx += 1 - ident = (ident << 7) | (t & 0x7f) + ident = (ident << 7) | (t & 0x7F) if not (t & 0x80): break if self.idx >= len(self.content): @@ -68,7 +68,7 @@ class BER(object): if size & 0x80: # more complimicated... # FIXME: theoretically should handle indefinite-length (0x80) - t = size & 0x7f + t = size & 0x7F if self.idx + t > len(self.content): return None size = util.inflate_long( @@ -106,7 +106,7 @@ class BER(object): def encode_tlv(self, ident, val): # no need to support ident > 31 here self.content += byte_chr(ident) - if len(val) > 0x7f: + if len(val) > 0x7F: lenstr = util.deflate_long(len(val)) self.content += byte_chr(0x80 + len(lenstr)) + lenstr else: diff --git a/paramiko/common.py b/paramiko/common.py index 3721efe4..b57149b7 100644 --- a/paramiko/common.py +++ b/paramiko/common.py @@ -26,20 +26,24 @@ import struct # Formerly of py3compat.py. May be fully delete'able with a deeper look? # + def byte_chr(c): assert isinstance(c, int) return struct.pack("B", c) + def byte_mask(c, mask): assert isinstance(c, int) return struct.pack("B", c & mask) + def byte_ord(c): # In case we're handed a string instead of an int. if not isinstance(c, int): c = ord(c) return c + ( MSG_DISCONNECT, MSG_IGNORE, @@ -198,7 +202,7 @@ CONNECTION_FAILED_CODE = { zero_byte = byte_chr(0) one_byte = byte_chr(1) four_byte = byte_chr(4) -max_byte = byte_chr(0xff) +max_byte = byte_chr(0xFF) cr_byte = byte_chr(13) linefeed_byte = byte_chr(10) crlf = cr_byte + linefeed_byte @@ -206,7 +210,7 @@ cr_byte_value = 13 linefeed_byte_value = 10 -xffffffff = 0xffffffff +xffffffff = 0xFFFFFFFF x80000000 = 0x80000000 o666 = 438 o660 = 432 @@ -225,17 +229,17 @@ CRITICAL = logging.CRITICAL # Common IO/select/etc sleep period, in seconds io_sleep = 0.01 -DEFAULT_WINDOW_SIZE = 64 * 2 ** 15 -DEFAULT_MAX_PACKET_SIZE = 2 ** 15 +DEFAULT_WINDOW_SIZE = 64 * 2**15 +DEFAULT_MAX_PACKET_SIZE = 2**15 # lower bound on the max packet size we'll accept from the remote host # Minimum packet size is 32768 bytes according to # http://www.ietf.org/rfc/rfc4254.txt -MIN_WINDOW_SIZE = 2 ** 15 +MIN_WINDOW_SIZE = 2**15 # However, according to http://www.ietf.org/rfc/rfc4253.txt it is perfectly # legal to accept a size much smaller, as OpenSSH client does as size 16384. -MIN_PACKET_SIZE = 2 ** 12 +MIN_PACKET_SIZE = 2**12 # Max windows size according to http://www.ietf.org/rfc/rfc4254.txt -MAX_WINDOW_SIZE = 2 ** 32 - 1 +MAX_WINDOW_SIZE = 2**32 - 1 diff --git a/paramiko/file.py b/paramiko/file.py index a30e5137..b1450ac9 100644 --- a/paramiko/file.py +++ b/paramiko/file.py @@ -520,9 +520,7 @@ class BufferedFile(ClosingContextManager): return if self.newlines is None: self.newlines = newline - elif self.newlines != newline and isinstance( - self.newlines, bytes - ): + elif self.newlines != newline and isinstance(self.newlines, bytes): self.newlines = (self.newlines, newline) elif newline not in self.newlines: self.newlines += (newline,) diff --git a/paramiko/kex_gex.py b/paramiko/kex_gex.py index 7bf24ddd..aa68efa5 100644 --- a/paramiko/kex_gex.py +++ b/paramiko/kex_gex.py @@ -111,7 +111,7 @@ class KexGex(object): qnorm = util.deflate_long(q, 0) qhbyte = byte_ord(qnorm[0]) byte_count = len(qnorm) - qmask = 0xff + qmask = 0xFF while not (qhbyte & 0x80): qhbyte <<= 1 qmask >>= 1 diff --git a/paramiko/kex_group1.py b/paramiko/kex_group1.py index 1e3d55f6..f4ac4944 100644 --- a/paramiko/kex_group1.py +++ b/paramiko/kex_group1.py @@ -33,7 +33,7 @@ from paramiko.ssh_exception import SSHException _MSG_KEXDH_INIT, _MSG_KEXDH_REPLY = range(30, 32) c_MSG_KEXDH_INIT, c_MSG_KEXDH_REPLY = [byte_chr(c) for c in range(30, 32)] -b7fffffffffffffff = byte_chr(0x7f) + max_byte * 7 +b7fffffffffffffff = byte_chr(0x7F) + max_byte * 7 b0000000000000000 = zero_byte * 8 @@ -86,7 +86,7 @@ class KexGroup1(object): # potential x). while 1: x_bytes = os.urandom(128) - x_bytes = byte_mask(x_bytes[0], 0x7f) + x_bytes[1:] + x_bytes = byte_mask(x_bytes[0], 0x7F) + x_bytes[1:] if ( x_bytes[:8] != b7fffffffffffffff and x_bytes[:8] != b0000000000000000 diff --git a/paramiko/kex_gss.py b/paramiko/kex_gss.py index 55f3f5e7..a826cc0a 100644 --- a/paramiko/kex_gss.py +++ b/paramiko/kex_gss.py @@ -41,7 +41,12 @@ import os from hashlib import sha1 from paramiko.common import ( - DEBUG, max_byte, zero_byte, byte_chr, byte_mask, byte_ord, + DEBUG, + max_byte, + zero_byte, + byte_chr, + byte_mask, + byte_ord, ) from paramiko import util from paramiko.message import Message @@ -77,7 +82,7 @@ class KexGSSGroup1(object): # draft-ietf-secsh-transport-09.txt, page 17 P = 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF # noqa G = 2 - b7fffffffffffffff = byte_chr(0x7f) + max_byte * 7 # noqa + b7fffffffffffffff = byte_chr(0x7F) + max_byte * 7 # noqa b0000000000000000 = zero_byte * 8 # noqa NAME = "gss-group1-sha1-toWM5Slw5Ew8Mqkay+al2g==" @@ -147,7 +152,7 @@ class KexGSSGroup1(object): """ while 1: x_bytes = os.urandom(128) - x_bytes = byte_mask(x_bytes[0], 0x7f) + x_bytes[1:] + x_bytes = byte_mask(x_bytes[0], 0x7F) + x_bytes[1:] first = x_bytes[:8] if first not in (self.b7fffffffffffffff, self.b0000000000000000): break @@ -402,7 +407,7 @@ class KexGSSGex(object): qnorm = util.deflate_long(q, 0) qhbyte = byte_ord(qnorm[0]) byte_count = len(qnorm) - qmask = 0xff + qmask = 0xFF while not (qhbyte & 0x80): qhbyte <<= 1 qmask >>= 1 diff --git a/paramiko/message.py b/paramiko/message.py index fc832732..5833f9dd 100644 --- a/paramiko/message.py +++ b/paramiko/message.py @@ -39,7 +39,7 @@ class Message(object): paramiko doesn't support yet. """ - big_int = 0xff000000 + big_int = 0xFF000000 def __init__(self, content=None): """ diff --git a/paramiko/pkey.py b/paramiko/pkey.py index 5e4a51ca..895fd840 100644 --- a/paramiko/pkey.py +++ b/paramiko/pkey.py @@ -50,7 +50,7 @@ def _unpad_openssh(data): # really ought to be made constant time (possibly by upstreaming this logic # into pyca/cryptography). padding_length = six.indexbytes(data, -1) - if 0x20 <= padding_length < 0x7f: + if 0x20 <= padding_length < 0x7F: return data # no padding, last byte part comment (printable ascii) if padding_length > 15: raise SSHException("Invalid key") diff --git a/paramiko/ssh_exception.py b/paramiko/ssh_exception.py index 620ab259..c7b0c249 100644 --- a/paramiko/ssh_exception.py +++ b/paramiko/ssh_exception.py @@ -125,9 +125,7 @@ class BadHostKeyException(SSHException): self.expected_key = expected_key def __str__(self): - msg = ( - "Host key for server '{}' does not match: got '{}', expected '{}'" - ) # noqa + msg = "Host key for server '{}' does not match: got '{}', expected '{}'" # noqa return msg.format( self.hostname, self.key.get_base64(), diff --git a/paramiko/transport.py b/paramiko/transport.py index b2e8d432..1d5f9014 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -112,7 +112,12 @@ from paramiko.ssh_exception import ( IncompatiblePeer, ProxyCommandFailure, ) -from paramiko.util import retry_on_signal, ClosingContextManager, clamp_value, b +from paramiko.util import ( + retry_on_signal, + ClosingContextManager, + clamp_value, + b, +) # for thread cleanup @@ -1875,9 +1880,9 @@ class Transport(threading.Thread, ClosingContextManager): """you are holding the lock""" chanid = self._channel_counter while self._channels.get(chanid) is not None: - self._channel_counter = (self._channel_counter + 1) & 0xffffff + self._channel_counter = (self._channel_counter + 1) & 0xFFFFFF chanid = self._channel_counter - self._channel_counter = (self._channel_counter + 1) & 0xffffff + self._channel_counter = (self._channel_counter + 1) & 0xFFFFFF return chanid def _unlink_channel(self, chanid): @@ -2592,7 +2597,7 @@ class Transport(threading.Thread, ClosingContextManager): def _activate_inbound(self): """switch on newly negotiated encryption parameters for - inbound traffic""" + inbound traffic""" block_size = self._cipher_info[self.remote_cipher]["block-size"] if self.server_mode: IV_in = self._compute_key("A", block_size) @@ -2628,7 +2633,7 @@ class Transport(threading.Thread, ClosingContextManager): def _activate_outbound(self): """switch on newly negotiated encryption parameters for - outbound traffic""" + outbound traffic""" m = Message() m.add_byte(cMSG_NEWKEYS) self._send_message(m) diff --git a/paramiko/util.py b/paramiko/util.py index 5e2f6392..5a21977e 100644 --- a/paramiko/util.py +++ b/paramiko/util.py @@ -29,7 +29,14 @@ import traceback import threading import logging -from paramiko.common import DEBUG, zero_byte, xffffffff, max_byte, byte_ord, byte_chr +from paramiko.common import ( + DEBUG, + zero_byte, + xffffffff, + max_byte, + byte_ord, + byte_chr, +) from paramiko.config import SSHConfig @@ -67,7 +74,7 @@ def deflate_long(n, add_sign_padding=True): for i in enumerate(s): if (n == 0) and (i[1] != 0): break - if (n == -1) and (i[1] != 0xff): + if (n == -1) and (i[1] != 0xFF): break else: # degenerate case, n was either 0 or -1 @@ -330,6 +337,7 @@ def b(s, encoding="utf8"): else: raise TypeError("Expected unicode or bytes, got {!r}".format(s)) + # TODO: clean this up / force callers to assume bytes OR unicode def u(s, encoding="utf8"): """cast bytes or unicode to unicode""" diff --git a/paramiko/win_pageant.py b/paramiko/win_pageant.py index 93f74621..a1096ee8 100644 --- a/paramiko/win_pageant.py +++ b/paramiko/win_pageant.py @@ -36,7 +36,7 @@ except ImportError: from . import _winapi -_AGENT_COPYDATA_ID = 0x804e50ba +_AGENT_COPYDATA_ID = 0x804E50BA _AGENT_MAX_MSGLEN = 8192 # Note: The WM_COPYDATA value is pulled from win32con, as a workaround # so we do not have to import this huge library just for this one variable. -- cgit v1.2.1