diff options
author | Dorian Pula <dorian.pula@amber-penguin-software.ca> | 2017-05-30 12:02:17 -0400 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2017-05-31 17:14:40 -0700 |
commit | ecb297518267487853813109da946d7240d717e1 (patch) | |
tree | 9974aecc603adad39e6bb88034c08dd74d91340e | |
parent | 98f682815cdd33a2f1999b931582e2467bb59754 (diff) |
Additional PEP8 fixes.
-rw-r--r-- | paramiko/ber.py | 6 | ||||
-rw-r--r-- | paramiko/dsskey.py | 11 | ||||
-rw-r--r-- | paramiko/ecdsakey.py | 4 | ||||
-rw-r--r-- | paramiko/primes.py | 14 | ||||
-rw-r--r-- | paramiko/proxy.py | 1 | ||||
-rw-r--r-- | paramiko/py3compat.py | 28 | ||||
-rw-r--r-- | paramiko/resource.py | 16 | ||||
-rw-r--r-- | paramiko/sftp_attr.py | 20 | ||||
-rw-r--r-- | paramiko/sftp_si.py | 22 | ||||
-rw-r--r-- | paramiko/win_pageant.py | 13 |
10 files changed, 77 insertions, 58 deletions
diff --git a/paramiko/ber.py b/paramiko/ber.py index a388df07..7725f944 100644 --- a/paramiko/ber.py +++ b/paramiko/ber.py @@ -71,7 +71,8 @@ class BER(object): t = size & 0x7f if self.idx + t > len(self.content): return None - size = util.inflate_long(self.content[self.idx: self.idx + t], True) + size = util.inflate_long( + self.content[self.idx: self.idx + t], True) self.idx += t if self.idx + size > len(self.content): # can't fit @@ -87,7 +88,8 @@ class BER(object): return util.inflate_long(data) else: # 1: boolean (00 false, otherwise true) - raise BERException('Unknown ber encoding type %d (robey is lazy)' % ident) + raise BERException( + 'Unknown ber encoding type %d (robey is lazy)' % ident) @staticmethod def decode_sequence(data): diff --git a/paramiko/dsskey.py b/paramiko/dsskey.py index 4644e9a6..c8452f23 100644 --- a/paramiko/dsskey.py +++ b/paramiko/dsskey.py @@ -42,7 +42,8 @@ class DSSKey(PKey): data. """ - def __init__(self, msg=None, data=None, filename=None, password=None, vals=None, file_obj=None): + def __init__(self, msg=None, data=None, filename=None, password=None, + vals=None, file_obj=None): self.p = None self.q = None self.g = None @@ -222,7 +223,7 @@ class DSSKey(PKey): key.x = numbers.x return key - ### internals... + # ...internals... def _from_private_key_file(self, filename, password): data = self._read_private_key_file('DSA', filename, password) @@ -239,8 +240,10 @@ class DSSKey(PKey): keylist = BER(data).decode() except BERException as e: raise SSHException('Unable to parse key file: ' + str(e)) - if (type(keylist) is not list) or (len(keylist) < 6) or (keylist[0] != 0): - raise SSHException('not a valid DSA private key file (bad ber encoding)') + if (type(keylist) is not list) or (len(keylist) < 6) or \ + (keylist[0] != 0): + raise SSHException( + 'not a valid DSA private key file (bad ber encoding)') self.p = keylist[1] self.q = keylist[2] self.g = keylist[3] diff --git a/paramiko/ecdsakey.py b/paramiko/ecdsakey.py index e4f74310..51f8d8ce 100644 --- a/paramiko/ecdsakey.py +++ b/paramiko/ecdsakey.py @@ -237,13 +237,13 @@ class ECDSAKey(PKey): if bits is not None: curve = cls._ECDSA_CURVES.get_by_key_length(bits) if curve is None: - raise ValueError("Unsupported key length: %d"%(bits)) + raise ValueError("Unsupported key length: %d" % bits) curve = curve.curve_class() private_key = ec.generate_private_key(curve, backend=default_backend()) return ECDSAKey(vals=(private_key, private_key.public_key())) - ### internals... + # ...internals... def _from_private_key_file(self, filename, password): data = self._read_private_key_file('EC', filename, password) diff --git a/paramiko/primes.py b/paramiko/primes.py index d0e17575..50100ad5 100644 --- a/paramiko/primes.py +++ b/paramiko/primes.py @@ -25,7 +25,7 @@ import os from paramiko import util from paramiko.py3compat import byte_mask, long from paramiko.ssh_exception import SSHException -from paramiko.common import * +from paramiko.common import * # noqa def _roll_random(n): @@ -62,7 +62,8 @@ class ModulusPack (object): self.discarded = [] def _parse_modulus(self, line): - timestamp, mod_type, tests, tries, size, generator, modulus = line.split() + timestamp, mod_type, tests, tries, size, generator, modulus = \ + line.split() mod_type = int(mod_type) tests = int(tests) tries = int(tries) @@ -74,8 +75,10 @@ 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)): - self.discarded.append((modulus, 'does not meet basic requirements')) + 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 if generator == 0: generator = 2 @@ -85,7 +88,8 @@ class ModulusPack (object): # this is okay. bl = util.bit_length(modulus) if (bl != size) and (bl != size + 1): - self.discarded.append((modulus, 'incorrectly reported bit length %d' % size)) + self.discarded.append( + (modulus, 'incorrectly reported bit length %d' % size)) return if bl not in self.pack: self.pack[bl] = [] diff --git a/paramiko/proxy.py b/paramiko/proxy.py index 7d67680a..c4ec627c 100644 --- a/paramiko/proxy.py +++ b/paramiko/proxy.py @@ -17,7 +17,6 @@ # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -from datetime import datetime import os from shlex import split as shlsplit import signal diff --git a/paramiko/py3compat.py b/paramiko/py3compat.py index 6fafc31d..095b0d09 100644 --- a/paramiko/py3compat.py +++ b/paramiko/py3compat.py @@ -1,20 +1,22 @@ import sys import base64 -__all__ = ['PY2', 'string_types', 'integer_types', 'text_type', 'bytes_types', 'bytes', 'long', 'input', - 'decodebytes', 'encodebytes', 'bytestring', 'byte_ord', 'byte_chr', 'byte_mask', - 'b', 'u', 'b2s', 'StringIO', 'BytesIO', 'is_callable', 'MAXSIZE', 'next', 'builtins'] +__all__ = ['PY2', 'string_types', 'integer_types', 'text_type', 'bytes_types', + 'bytes', 'long', 'input', 'decodebytes', 'encodebytes', + 'bytestring', 'byte_ord', 'byte_chr', 'byte_mask', 'b', 'u', 'b2s', + 'StringIO', 'BytesIO', 'is_callable', 'MAXSIZE', + 'next', 'builtins'] PY2 = sys.version_info[0] < 3 if PY2: - string_types = basestring - text_type = unicode + string_types = basestring # NOQA + text_type = unicode # NOQA bytes_types = str bytes = str - integer_types = (int, long) - long = long - input = raw_input + integer_types = (int, long) # NOQA + long = long # NOQA + input = raw_input # NOQA decodebytes = base64.decodestring encodebytes = base64.encodestring @@ -22,7 +24,7 @@ if PY2: def bytestring(s): # NOQA - if isinstance(s, unicode): + if isinstance(s, unicode): # NOQA return s.encode('utf-8') return s @@ -39,9 +41,9 @@ if PY2: """cast unicode or bytes to bytes""" if isinstance(s, str): return s - elif isinstance(s, unicode): + elif isinstance(s, unicode): # NOQA return s.encode(encoding) - elif isinstance(s, buffer): + elif isinstance(s, buffer): # NOQA return s else: raise TypeError("Expected unicode or bytes, got %r" % s) @@ -51,9 +53,9 @@ if PY2: """cast bytes or unicode to unicode""" if isinstance(s, str): return s.decode(encoding) - elif isinstance(s, unicode): + elif isinstance(s, unicode): # NOQA return s - elif isinstance(s, buffer): + elif isinstance(s, buffer): # NOQA return s.decode(encoding) else: raise TypeError("Expected unicode or bytes, got %r" % s) diff --git a/paramiko/resource.py b/paramiko/resource.py index 9809afbe..5fed22ad 100644 --- a/paramiko/resource.py +++ b/paramiko/resource.py @@ -27,30 +27,30 @@ class ResourceManager (object): """ A registry of objects and resources that should be closed when those objects are deleted. - + This is meant to be a safer alternative to Python's ``__del__`` method, which can cause reference cycles to never be collected. Objects registered with the ResourceManager can be collected but still free resources when they die. - + Resources are registered using `register`, and when an object is garbage collected, each registered resource is closed by having its ``close()`` method called. Multiple resources may be registered per object, but a resource will only be closed once, even if multiple objects register it. (The last object to register it wins.) """ - + def __init__(self): self._table = {} - + def register(self, obj, resource): """ Register a resource to be closed with an object is collected. - + When the given ``obj`` is garbage-collected by the Python interpreter, - the ``resource`` will be closed by having its ``close()`` method called. - Any exceptions are ignored. - + the ``resource`` will be closed by having its ``close()`` method + called. Any exceptions are ignored. + :param object obj: the object to track :param object resource: the resource to close when the object is collected diff --git a/paramiko/sftp_attr.py b/paramiko/sftp_attr.py index 0eaca30b..5597948a 100644 --- a/paramiko/sftp_attr.py +++ b/paramiko/sftp_attr.py @@ -84,7 +84,7 @@ class SFTPAttributes (object): def __repr__(self): return '<SFTPAttributes: %s>' % self._debug_str() - ### internals... + # ...internals... @classmethod def _from_msg(cls, msg, filename=None, longname=None): attr = cls() @@ -189,9 +189,12 @@ class SFTPAttributes (object): ks = 's' else: ks = '?' - ks += self._rwx((self.st_mode & o700) >> 6, self.st_mode & stat.S_ISUID) - ks += self._rwx((self.st_mode & o70) >> 3, self.st_mode & stat.S_ISGID) - ks += self._rwx(self.st_mode & 7, self.st_mode & stat.S_ISVTX, True) + ks += self._rwx( + (self.st_mode & o700) >> 6, self.st_mode & stat.S_ISUID) + ks += self._rwx( + (self.st_mode & o70) >> 3, self.st_mode & stat.S_ISGID) + ks += self._rwx( + self.st_mode & 7, self.st_mode & stat.S_ISVTX, True) else: ks = '?---------' # compute display date @@ -201,9 +204,11 @@ class SFTPAttributes (object): else: if abs(time.time() - self.st_mtime) > 15552000: # (15552000 = 6 months) - datestr = time.strftime('%d %b %Y', time.localtime(self.st_mtime)) + datestr = time.strftime( + '%d %b %Y', time.localtime(self.st_mtime)) else: - datestr = time.strftime('%d %b %H:%M', time.localtime(self.st_mtime)) + datestr = time.strftime( + '%d %b %H:%M', time.localtime(self.st_mtime)) filename = getattr(self, 'filename', '?') # not all servers support uid/gid @@ -217,7 +222,8 @@ class SFTPAttributes (object): if size is None: size = 0 - return '%s 1 %-8d %-8d %8d %-12s %s' % (ks, uid, gid, size, datestr, filename) + return '%s 1 %-8d %-8d %8d %-12s %s' % ( + ks, uid, gid, size, datestr, filename) def asbytes(self): return b(str(self)) diff --git a/paramiko/sftp_si.py b/paramiko/sftp_si.py index 7ab00ad7..c335eaec 100644 --- a/paramiko/sftp_si.py +++ b/paramiko/sftp_si.py @@ -35,16 +35,15 @@ class SFTPServerInterface (object): SFTP sessions). However, raising an exception will usually cause the SFTP session to abruptly end, so you will usually want to catch exceptions and return an appropriate error code. - + All paths are in string form instead of unicode because not all SFTP clients & servers obey the requirement that paths be encoded in UTF-8. """ - def __init__(self, server, *largs, **kwargs): """ Create a new SFTPServerInterface object. This method does nothing by default and is meant to be overridden by subclasses. - + :param .ServerInterface server: the server object associated with this channel and SFTP subsystem """ @@ -92,7 +91,7 @@ class SFTPServerInterface (object): The ``attr`` object contains requested attributes of the file if it has to be created. Some or all attribute fields may be missing if the client didn't specify them. - + .. note:: The SFTP protocol defines all files to be in "binary" mode. There is no equivalent to Python's "text" mode. @@ -123,11 +122,12 @@ class SFTPServerInterface (object): In case of an error, you should return one of the ``SFTP_*`` error codes, such as `.SFTP_PERMISSION_DENIED`. - :param str path: the requested path (relative or absolute) to be listed. + :param str path: the requested path (relative or absolute) to be + listed. :return: a list of the files in the given folder, using `.SFTPAttributes` objects. - + .. note:: You should normalize the given ``path`` first (see the `os.path` module) and check appropriate permissions before returning the list @@ -189,7 +189,7 @@ class SFTPServerInterface (object): and since there's no other (easy) way to move files via SFTP, it's probably a good idea to implement "move" in this method too, even for files that cross disk partition boundaries, if at all possible. - + .. note:: You should return an error if a file with the same name as ``newpath`` already exists. (The rename operation should be non-desctructive.) @@ -267,25 +267,25 @@ class SFTPServerInterface (object): # on windows, normalize backslashes to sftp/posix format out = out.replace('\\', '/') return out - + def readlink(self, path): """ Return the target of a symbolic link (or shortcut) on the server. If the specified path doesn't refer to a symbolic link, an error should be returned. - + :param str path: path (relative or absolute) of the symbolic link. :return: the target `str` path of the symbolic link, or an error code like `.SFTP_NO_SUCH_FILE`. """ return SFTP_OP_UNSUPPORTED - + def symlink(self, target_path, path): """ Create a symbolic link on the server, as new pathname ``path``, with ``target_path`` as the target of the link. - + :param str target_path: path (relative or absolute) of the target for this new symbolic link. diff --git a/paramiko/win_pageant.py b/paramiko/win_pageant.py index 4b482bee..c8c2c7bc 100644 --- a/paramiko/win_pageant.py +++ b/paramiko/win_pageant.py @@ -25,13 +25,13 @@ import array import ctypes.wintypes import platform import struct -from paramiko.util import * +from paramiko.util import * # noqa from paramiko.py3compat import b try: - import _thread as thread # Python 3.x + import _thread as thread # Python 3.x except ImportError: - import thread # Python 2.5-2.7 + import thread # Python 2.5-2.7 from . import _winapi @@ -57,7 +57,10 @@ def can_talk_to_agent(): return bool(_get_pageant_window_object()) -ULONG_PTR = ctypes.c_uint64 if platform.architecture()[0] == '64bit' else ctypes.c_uint32 +if platform.architecture()[0] == '64bit': + ULONG_PTR = ctypes.c_uint64 +else: + ULONG_PTR = ctypes.c_uint32 class COPYDATASTRUCT(ctypes.Structure): @@ -91,7 +94,7 @@ def _query_pageant(msg): with pymap: pymap.write(msg) # Create an array buffer containing the mapped filename - char_buffer = array.array("b", b(map_name) + zero_byte) + char_buffer = array.array("b", b(map_name) + zero_byte) # noqa char_buffer_address, char_buffer_size = char_buffer.buffer_info() # Create a string to use for the SendMessage function call cds = COPYDATASTRUCT(_AGENT_COPYDATA_ID, char_buffer_size, |