diff options
author | Dorian Pula <dorian.pula@amber-penguin-software.ca> | 2017-05-24 16:42:23 -0700 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2017-05-31 17:14:40 -0700 |
commit | 28218bf90b97451d3aba9d2c9ee01d87349a8886 (patch) | |
tree | 27651281db872bbf86fdf819292f1efe3f53aaae /paramiko/util.py | |
parent | 71e204d488f53c688ded4f9631c4256cfea30c5d (diff) | |
download | paramiko-28218bf90b97451d3aba9d2c9ee01d87349a8886.tar.gz |
More flake8 fixes and fix tests.
Diffstat (limited to 'paramiko/util.py')
-rw-r--r-- | paramiko/util.py | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/paramiko/util.py b/paramiko/util.py index b69e8882..f6885c60 100644 --- a/paramiko/util.py +++ b/paramiko/util.py @@ -35,7 +35,8 @@ from paramiko.config import SSHConfig def inflate_long(s, always_positive=False): - """turns a normalized byte string into a long-int (adapted from Crypto.Util.number)""" + """turns a normalized byte string into a long-int + (adapted from Crypto.Util.number)""" out = long(0) negative = 0 if not always_positive and (len(s) > 0) and (byte_ord(s[0]) >= 0x80): @@ -48,17 +49,19 @@ 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 + deflate_zero = zero_byte if PY2 else 0 deflate_ff = max_byte if PY2 else 0xff def deflate_long(n, add_sign_padding=True): - """turns a long-int into a normalized byte string (adapted from Crypto.Util.number)""" + """turns a long-int into a normalized byte string + (adapted from Crypto.Util.number)""" # after much testing, this algorithm was deemed to be the fastest s = bytes() n = long(n) @@ -91,7 +94,7 @@ def format_binary(data, prefix=''): x = 0 out = [] while len(data) > x + 16: - out.append(format_binary_line(data[x:x+16])) + out.append(format_binary_line(data[x:x + 16])) x += 16 if x < len(data): out.append(format_binary_line(data[x:])) @@ -100,7 +103,7 @@ def format_binary(data, prefix=''): def format_binary_line(data): left = ' '.join(['%02X' % byte_ord(c) for c in data]) - right = ''.join([('.%c..' % c)[(byte_ord(c)+63)//95] for c in data]) + right = ''.join([('.%c..' % c)[(byte_ord(c) + 63) // 95] for c in data]) return '%-50s %s' % (left, right) @@ -215,6 +218,7 @@ def mod_inverse(x, m): u2 += m return u2 + _g_thread_ids = {} _g_thread_counter = 0 _g_thread_lock = threading.Lock() @@ -236,15 +240,17 @@ def get_thread_id(): def log_to_file(filename, level=DEBUG): - """send paramiko logs to a logfile, if they're not already going somewhere""" + """send paramiko logs to a logfile, + if they're not already going somewhere""" l = logging.getLogger("paramiko") if len(l.handlers) > 0: return l.setLevel(level) f = open(filename, 'a') lh = logging.StreamHandler(f) - lh.setFormatter(logging.Formatter('%(levelname)-.3s [%(asctime)s.%(msecs)03d] thr=%(_threadid)-3d %(name)s: %(message)s', - '%Y%m%d-%H:%M:%S')) + frm = '%(levelname)-.3s [%(asctime)s.%(msecs)03d] thr=%(_threadid)-3d ' \ + '%(name)s: %(message)s' + lh.setFormatter(logging.Formatter(frm, '%Y%m%d-%H:%M:%S')) l.addHandler(lh) @@ -253,6 +259,8 @@ class PFilter (object): def filter(self, record): record._threadid = get_thread_id() return True + + _pfilter = PFilter() @@ -277,7 +285,7 @@ def constant_time_bytes_eq(a, b): return False res = 0 # noinspection PyUnresolvedReferences - for i in (xrange if PY2 else range)(len(a)): + for i in (xrange if PY2 else range)(len(a)): # noqa: F821 res |= byte_ord(a[i]) ^ byte_ord(b[i]) return res == 0 |