diff options
author | Chris Rose <offline@offby1.net> | 2018-05-17 10:13:38 -0400 |
---|---|---|
committer | Chris Rose <offline@offby1.net> | 2018-05-17 10:13:38 -0400 |
commit | 7f2c35052183b400827d9949a68b41c90f90a32d (patch) | |
tree | fea4a1ec04b7ee3ced14d61e8b6cf3f479e22704 /paramiko/util.py | |
parent | 52551321a2297bdb966869fa719e584c868dd857 (diff) | |
download | paramiko-7f2c35052183b400827d9949a68b41c90f90a32d.tar.gz |
Blacken Paramiko on 2.4
Diffstat (limited to 'paramiko/util.py')
-rw-r--r-- | paramiko/util.py | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/paramiko/util.py b/paramiko/util.py index 2854ef98..c60c040c 100644 --- a/paramiko/util.py +++ b/paramiko/util.py @@ -49,7 +49,7 @@ def inflate_long(s, always_positive=False): # noinspection PyAugmentAssignment s = filler * (4 - len(s) % 4) + s for i in range(0, len(s), 4): - out = (out << 32) + struct.unpack('>I', s[i:i + 4])[0] + out = (out << 32) + struct.unpack(">I", s[i:i + 4])[0] if negative: out -= (long(1) << (8 * len(s))) return out @@ -66,7 +66,7 @@ def deflate_long(n, add_sign_padding=True): s = bytes() n = long(n) while (n != 0) and (n != -1): - s = struct.pack('>I', n & xffffffff) + s + s = struct.pack(">I", n & xffffffff) + s n >>= 32 # strip off leading zeros, FFs for i in enumerate(s): @@ -90,7 +90,7 @@ def deflate_long(n, add_sign_padding=True): return s -def format_binary(data, prefix=''): +def format_binary(data, prefix=""): x = 0 out = [] while len(data) > x + 16: @@ -102,22 +102,21 @@ def format_binary(data, prefix=''): def format_binary_line(data): - left = ' '.join(['{:02X}'.format(byte_ord(c)) for c in data]) - right = ''.join([ - '.{:c}..'.format(byte_ord(c))[(byte_ord(c) + 63) // 95] - for c in data - ]) - return '{:50s} {}'.format(left, right) + left = " ".join(["{:02X}".format(byte_ord(c)) for c in data]) + right = "".join( + [".{:c}..".format(byte_ord(c))[(byte_ord(c) + 63) // 95] for c in data] + ) + return "{:50s} {}".format(left, right) def safe_string(s): - out = b'' + out = b"" for c in s: i = byte_ord(c) if 32 <= i <= 127: out += byte_chr(i) else: - out += b('%{:02X}'.format(i)) + out += b("%{:02X}".format(i)) return out @@ -137,7 +136,7 @@ def bit_length(n): def tb_strings(): - return ''.join(traceback.format_exception(*sys.exc_info())).split('\n') + return "".join(traceback.format_exception(*sys.exc_info())).split("\n") def generate_key_bytes(hash_alg, salt, key, nbytes): @@ -188,6 +187,7 @@ def load_host_keys(filename): nested dict of `.PKey` objects, indexed by hostname and then keytype """ from paramiko.hostkeys import HostKeys + return HostKeys(filename) @@ -249,15 +249,16 @@ def log_to_file(filename, level=DEBUG): if len(l.handlers) > 0: return l.setLevel(level) - f = open(filename, 'a') + f = open(filename, "a") lh = logging.StreamHandler(f) - 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')) + 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) # make only one filter object, so it doesn't get applied more than once -class PFilter (object): +class PFilter(object): + def filter(self, record): record._threadid = get_thread_id() return True @@ -293,6 +294,7 @@ def constant_time_bytes_eq(a, b): class ClosingContextManager(object): + def __enter__(self): return self |