diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2023-01-11 20:24:13 -0500 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2023-01-11 20:24:13 -0500 |
commit | ec8948158e26df0ec549e333cc2ea4bb22d56350 (patch) | |
tree | 605531478922a9b56d867e8044387711f32b68d2 | |
parent | 19a00412bfecd43d4fa6a13459955ccb13f29e02 (diff) |
blacken
-rw-r--r-- | paramiko/auth_handler.py | 4 | ||||
-rw-r--r-- | paramiko/ber.py | 6 | ||||
-rw-r--r-- | paramiko/common.py | 18 | ||||
-rw-r--r-- | paramiko/file.py | 4 | ||||
-rw-r--r-- | paramiko/kex_gex.py | 2 | ||||
-rw-r--r-- | paramiko/kex_group1.py | 4 | ||||
-rw-r--r-- | paramiko/kex_gss.py | 13 | ||||
-rw-r--r-- | paramiko/message.py | 2 | ||||
-rw-r--r-- | paramiko/pkey.py | 2 | ||||
-rw-r--r-- | paramiko/ssh_exception.py | 4 | ||||
-rw-r--r-- | paramiko/transport.py | 15 | ||||
-rw-r--r-- | paramiko/util.py | 12 | ||||
-rw-r--r-- | paramiko/win_pageant.py | 2 | ||||
-rw-r--r-- | tests/test_client.py | 4 | ||||
-rw-r--r-- | tests/test_file.py | 2 | ||||
-rw-r--r-- | tests/test_kex.py | 2 | ||||
-rw-r--r-- | tests/test_message.py | 24 | ||||
-rw-r--r-- | tests/test_packetizer.py | 2 | ||||
-rw-r--r-- | tests/test_transport.py | 8 | ||||
-rw-r--r-- | tests/util.py | 1 |
20 files changed, 73 insertions, 58 deletions
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. diff --git a/tests/test_client.py b/tests/test_client.py index a0dcab1a..cb34348a 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -803,7 +803,7 @@ class PasswordPassphraseTests(ClientTest): @requires_sha1_signing def test_password_kwarg_used_for_passphrase_when_no_passphrase_kwarg_given( - self + self, ): # noqa # Backwards compatibility: passphrase in the password field. self._test_connection( @@ -814,7 +814,7 @@ class PasswordPassphraseTests(ClientTest): @raises(AuthenticationException) # TODO: more granular @requires_sha1_signing def test_password_kwarg_not_used_for_passphrase_when_passphrase_kwarg_given( # noqa - self + self, ): # Sanity: if we're given both fields, the password field is NOT used as # a passphrase. diff --git a/tests/test_file.py b/tests/test_file.py index b0147450..bcd1ad2b 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -189,7 +189,7 @@ class BufferedFileTest(unittest.TestCase): self.assertRaises(TypeError, f.write, object()) def test_write_unicode_as_binary(self): - text = u"\xa7 why is writing text to a binary file allowed?\n" + text = "\xa7 why is writing text to a binary file allowed?\n" with LoopbackFile("rb+") as f: f.write(text) self.assertEqual(f.read(), text.encode("utf-8")) diff --git a/tests/test_kex.py b/tests/test_kex.py index 24fb8b81..45a691f2 100644 --- a/tests/test_kex.py +++ b/tests/test_kex.py @@ -47,7 +47,7 @@ from paramiko.kex_curve25519 import KexCurve25519 def dummy_urandom(n): - return byte_chr(0xcc) * n + return byte_chr(0xCC) * n def dummy_generate_key_pair(obj): diff --git a/tests/test_message.py b/tests/test_message.py index 23b06858..bd2d5795 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -48,18 +48,18 @@ class MessageTest(unittest.TestCase): msg = Message() msg.add_boolean(True) msg.add_boolean(False) - msg.add_byte(byte_chr(0xf3)) + msg.add_byte(byte_chr(0xF3)) - msg.add_bytes(zero_byte + byte_chr(0x3f)) + msg.add_bytes(zero_byte + byte_chr(0x3F)) msg.add_list(["huey", "dewey", "louie"]) self.assertEqual(msg.asbytes(), self.__b) msg = Message() msg.add_int64(5) - msg.add_int64(0xf5e4d3c2b109) + msg.add_int64(0xF5E4D3C2B109) msg.add_mpint(17) - msg.add_mpint(0xf5e4d3c2b109) - msg.add_mpint(-0x65e4d3c2b109) + msg.add_mpint(0xF5E4D3C2B109) + msg.add_mpint(-0x65E4D3C2B109) self.assertEqual(msg.asbytes(), self.__c) def test_decode(self): @@ -73,22 +73,22 @@ class MessageTest(unittest.TestCase): msg = Message(self.__b) self.assertEqual(msg.get_boolean(), True) self.assertEqual(msg.get_boolean(), False) - self.assertEqual(msg.get_byte(), byte_chr(0xf3)) - self.assertEqual(msg.get_bytes(2), zero_byte + byte_chr(0x3f)) + self.assertEqual(msg.get_byte(), byte_chr(0xF3)) + self.assertEqual(msg.get_bytes(2), zero_byte + byte_chr(0x3F)) self.assertEqual(msg.get_list(), ["huey", "dewey", "louie"]) msg = Message(self.__c) self.assertEqual(msg.get_int64(), 5) - self.assertEqual(msg.get_int64(), 0xf5e4d3c2b109) + self.assertEqual(msg.get_int64(), 0xF5E4D3C2B109) self.assertEqual(msg.get_mpint(), 17) - self.assertEqual(msg.get_mpint(), 0xf5e4d3c2b109) - self.assertEqual(msg.get_mpint(), -0x65e4d3c2b109) + self.assertEqual(msg.get_mpint(), 0xF5E4D3C2B109) + self.assertEqual(msg.get_mpint(), -0x65E4D3C2B109) def test_add(self): msg = Message() msg.add(5) msg.add(0x1122334455) - msg.add(0xf00000000000000000) + msg.add(0xF00000000000000000) msg.add(True) msg.add("cat") msg.add(["a", "b"]) @@ -98,7 +98,7 @@ class MessageTest(unittest.TestCase): msg = Message(self.__d) self.assertEqual(msg.get_adaptive_int(), 5) self.assertEqual(msg.get_adaptive_int(), 0x1122334455) - self.assertEqual(msg.get_adaptive_int(), 0xf00000000000000000) + self.assertEqual(msg.get_adaptive_int(), 0xF00000000000000000) self.assertEqual(msg.get_so_far(), self.__d[:29]) self.assertEqual(msg.get_remainder(), self.__d[29:]) msg.rewind() diff --git a/tests/test_packetizer.py b/tests/test_packetizer.py index 27dee358..d4dd58ad 100644 --- a/tests/test_packetizer.py +++ b/tests/test_packetizer.py @@ -34,7 +34,7 @@ from .loop import LoopSocket x55 = byte_chr(0x55) -x1f = byte_chr(0x1f) +x1f = byte_chr(0x1F) class PacketizerTest(unittest.TestCase): diff --git a/tests/test_transport.py b/tests/test_transport.py index 177e83da..d5cb5576 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -686,7 +686,7 @@ class TransportTest(unittest.TestCase): self.assertEqual(chan.send_ready(), True) total = 0 K = "*" * 1024 - limit = 1 + (64 * 2 ** 15) + limit = 1 + (64 * 2**15) while total < limit: chan.send(K) total += len(K) @@ -874,7 +874,7 @@ class TransportTest(unittest.TestCase): for val, correct in [ (4095, MIN_PACKET_SIZE), (None, DEFAULT_MAX_PACKET_SIZE), - (2 ** 32, MAX_WINDOW_SIZE), + (2**32, MAX_WINDOW_SIZE), ]: self.assertEqual(self.tc._sanitize_packet_size(val), correct) @@ -885,7 +885,7 @@ class TransportTest(unittest.TestCase): for val, correct in [ (32767, MIN_WINDOW_SIZE), (None, DEFAULT_WINDOW_SIZE), - (2 ** 32, MAX_WINDOW_SIZE), + (2**32, MAX_WINDOW_SIZE), ]: self.assertEqual(self.tc._sanitize_window_size(val), correct) @@ -950,7 +950,7 @@ class TransportTest(unittest.TestCase): verify behaviours sending various instances to a channel """ self.setup_test_server() - text = u"\xa7 slice me nicely" + text = "\xa7 slice me nicely" with self.tc.open_session() as chan: schan = self.ts.accept(1.0) if schan is None: diff --git a/tests/util.py b/tests/util.py index f3efb6b0..00642cb0 100644 --- a/tests/util.py +++ b/tests/util.py @@ -78,7 +78,6 @@ if ( def tearDownClass(cls): del cls.realm - else: try: # Try to setup a kerberos environment |