summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDorian Pula <dorian.pula@amber-penguin-software.ca>2017-05-24 16:22:43 -0700
committerJeff Forcier <jeff@bitprophet.org>2017-05-31 17:14:40 -0700
commit71e204d488f53c688ded4f9631c4256cfea30c5d (patch)
treeba60614fa3a33a4f752688fba941a9dcbbb93cae
parent47a648c002d263c5608fc5df0085fef4cf4d2f6e (diff)
More flake8 fixes and skip some modules.
-rw-r--r--paramiko/file.py41
-rw-r--r--paramiko/hostkeys.py21
-rw-r--r--paramiko/message.py28
-rw-r--r--setup.cfg4
4 files changed, 57 insertions, 37 deletions
diff --git a/paramiko/file.py b/paramiko/file.py
index 5b57dfd6..ab95c063 100644
--- a/paramiko/file.py
+++ b/paramiko/file.py
@@ -15,8 +15,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-from paramiko.common import linefeed_byte_value, crlf, cr_byte, linefeed_byte, \
- cr_byte_value
+from paramiko.common import linefeed_byte_value, crlf, cr_byte, \
+ linefeed_byte, cr_byte_value
from paramiko.py3compat import BytesIO, PY2, u, b, bytes_types
from paramiko.util import ClosingContextManager
@@ -106,9 +106,9 @@ class BufferedFile (ClosingContextManager):
else:
def __next__(self):
"""
- Returns the next line from the input, or raises `.StopIteration` when
- EOF is hit. Unlike python file objects, it's okay to mix calls to
- `.next` and `.readline`.
+ Returns the next line from the input, or raises `.StopIteration`
+ when EOF is hit. Unlike python file objects, it's okay to mix
+ calls to `.next` and `.readline`.
:raises StopIteration: when the end of the file is reached.
@@ -163,9 +163,9 @@ class BufferedFile (ClosingContextManager):
def read(self, size=None):
"""
- Read at most ``size`` bytes from the file (less if we hit the end of the
- file first). If the ``size`` argument is negative or omitted, read all
- the remaining data in the file.
+ Read at most ``size`` bytes from the file (less if we hit the end of
+ the file first). If the ``size`` argument is negative or omitted,
+ read all the remaining data in the file.
.. note::
``'b'`` mode flag is ignored (``self.FLAG_BINARY`` in
@@ -250,7 +250,9 @@ class BufferedFile (ClosingContextManager):
line = self._rbuffer
truncated = False
while True:
- if self._at_trailing_cr and (self._flags & self.FLAG_UNIVERSAL_NEWLINE) and (len(line) > 0):
+ if self._at_trailing_cr and \
+ (self._flags & self.FLAG_UNIVERSAL_NEWLINE) and \
+ (len(line) > 0):
# edge case: the newline may be '\r\n' and we may have read
# only the first '\r' last time.
if line[0] == linefeed_byte_value:
@@ -271,7 +273,9 @@ class BufferedFile (ClosingContextManager):
n = size - len(line)
else:
n = self._bufsize
- if (linefeed_byte in line) or ((self._flags & self.FLAG_UNIVERSAL_NEWLINE) and (cr_byte in line)):
+ if (linefeed_byte in line) or \
+ ((self._flags & self.FLAG_UNIVERSAL_NEWLINE) and
+ (cr_byte in line)):
break
try:
new_data = self._read(n)
@@ -294,12 +298,18 @@ class BufferedFile (ClosingContextManager):
self._pos += len(line)
return line if self._flags & self.FLAG_BINARY else u(line)
xpos = pos + 1
- if (line[pos] == cr_byte_value) and (xpos < len(line)) and (line[xpos] == linefeed_byte_value):
+ if (line[pos] == cr_byte_value) and \
+ (xpos < len(line)) and \
+ (line[xpos] == linefeed_byte_value):
xpos += 1
# if the string was truncated, _rbuffer needs to have the string after
# the newline character plus the truncated part of the line we stored
# earlier in _rbuffer
- self._rbuffer = line[xpos:] + self._rbuffer if truncated else line[xpos:]
+ if truncated:
+ self._rbuffer = line[xpos:] + self._rbuffer
+ else:
+ self._rbuffer = line[xpos:]
+
lf = line[pos:xpos]
line = line[:pos] + linefeed_byte
if (len(self._rbuffer) == 0) and (lf == cr_byte):
@@ -421,7 +431,7 @@ class BufferedFile (ClosingContextManager):
def closed(self):
return self._closed
- ### overrides...
+ # ...overrides...
def _read(self, size):
"""
@@ -449,7 +459,7 @@ class BufferedFile (ClosingContextManager):
"""
return 0
- ### internals...
+ # ...internals...
def _set_mode(self, mode='r', bufsize=-1):
"""
@@ -513,7 +523,8 @@ class BufferedFile (ClosingContextManager):
return
if self.newlines is None:
self.newlines = newline
- elif self.newlines != newline and isinstance(self.newlines, bytes_types):
+ elif self.newlines != newline and \
+ isinstance(self.newlines, bytes_types):
self.newlines = (self.newlines, newline)
elif newline not in self.newlines:
self.newlines += (newline,)
diff --git a/paramiko/hostkeys.py b/paramiko/hostkeys.py
index de7fc8ba..b2a80ca1 100644
--- a/paramiko/hostkeys.py
+++ b/paramiko/hostkeys.py
@@ -179,12 +179,18 @@ class HostKeys (MutableMapping):
self._hostkeys._entries.append(e)
def keys(self):
- return [e.key.get_name() for e in self._entries if e.key is not None]
+ return [
+ e.key.get_name() for e in self._entries
+ if e.key is not None
+ ]
entries = []
for e in self._entries:
for h in e.hostnames:
- if h.startswith('|1|') and not hostname.startswith('|1|') and constant_time_bytes_eq(self.hash_host(hostname, h), h) or h == hostname:
+ if h.startswith('|1|') and not hostname.startswith('|1|') and \
+ constant_time_bytes_eq(
+ self.hash_host(hostname, h), h) \
+ or h == hostname:
entries.append(e)
if len(entries) == 0:
return None
@@ -235,7 +241,7 @@ class HostKeys (MutableMapping):
for key_type in entry.keys():
found = False
for e in self._entries:
- if (hostname in e.hostnames) and (e.key.get_name() == key_type):
+ if (hostname in e.hostnames) and e.key.get_name() == key_type:
# replace
e.key = entry[key_type]
found = True
@@ -264,7 +270,8 @@ class HostKeys (MutableMapping):
hashed hostnames in the known_hosts file.
:param str hostname: the hostname to hash
- :param str salt: optional salt to use when hashing (must be 20 bytes long)
+ :param str salt: optional salt to use when hashing
+ (must be 20 bytes long)
:return: the hashed hostname as a `str`
"""
if salt is None:
@@ -347,8 +354,10 @@ class HostKeyEntry:
included.
"""
if self.valid:
- return '%s %s %s\n' % (','.join(self.hostnames), self.key.get_name(),
- self.key.get_base64())
+ return '%s %s %s\n' % (
+ ','.join(self.hostnames),
+ self.key.get_name(),
+ self.key.get_base64())
return None
def __repr__(self):
diff --git a/paramiko/message.py b/paramiko/message.py
index bf4c6b95..309b8612 100644
--- a/paramiko/message.py
+++ b/paramiko/message.py
@@ -32,7 +32,7 @@ class Message (object):
An SSH2 message is a stream of bytes that encodes some combination of
strings, integers, bools, and infinite-precision integers (known in Python
as longs). This class builds or breaks down such a byte stream.
-
+
Normally you don't need to deal with anything this low-level, but it's
exposed for people implementing custom extensions, or features that
paramiko doesn't support yet.
@@ -200,7 +200,7 @@ class Message (object):
def get_list(self):
"""
Fetch a `list` of `strings <str>` from the stream.
-
+
These are trivially encoded as comma-separated values in a string.
"""
return self.get_text().split(',')
@@ -208,7 +208,7 @@ class Message (object):
def add_bytes(self, b):
"""
Write bytes to the stream, without any formatting.
-
+
:param str b: bytes to add
"""
self.packet.write(b)
@@ -217,7 +217,7 @@ class Message (object):
def add_byte(self, b):
"""
Write a single byte to the stream, without any formatting.
-
+
:param str b: byte to add
"""
self.packet.write(b)
@@ -226,7 +226,7 @@ class Message (object):
def add_boolean(self, b):
"""
Add a boolean value to the stream.
-
+
:param bool b: boolean value to add
"""
if b:
@@ -234,20 +234,20 @@ class Message (object):
else:
self.packet.write(zero_byte)
return self
-
+
def add_int(self, n):
"""
Add an integer to the stream.
-
+
:param int n: integer to add
"""
self.packet.write(struct.pack('>I', n))
return self
-
+
def add_adaptive_int(self, n):
"""
Add an integer to the stream.
-
+
:param int n: integer to add
"""
if n >= Message.big_int:
@@ -270,7 +270,7 @@ class Message (object):
"""
Add a long int to the stream, encoded as an infinite-precision
integer. This method only works on positive numbers.
-
+
:param long z: long int to add
"""
self.add_string(util.deflate_long(z))
@@ -279,7 +279,7 @@ class Message (object):
def add_string(self, s):
"""
Add a string to the stream.
-
+
:param str s: string to add
"""
s = asbytes(s)
@@ -292,12 +292,12 @@ class Message (object):
Add a list of strings to the stream. They are encoded identically to
a single string of values separated by commas. (Yes, really, that's
how SSH2 does it.)
-
+
:param list l: list of strings to add
"""
self.add_string(','.join(l))
return self
-
+
def _add(self, i):
if type(i) is bool:
return self.add_boolean(i)
@@ -315,7 +315,7 @@ class Message (object):
.. warning::
Longs are encoded non-deterministically. Don't use this method.
-
+
:param seq: the sequence of items
"""
for item in seq:
diff --git a/setup.cfg b/setup.cfg
index 7cf39d46..b4280a7e 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -5,6 +5,6 @@ universal = 1
omit = paramiko/_winapi.py
[flake8]
-exclude = sites,.git,build,dist,alt_env,appveyor,demos,tests,test.py
-ignore = E124,E125,E128,E261,E301,E302,E303
+exclude = sites,.git,build,dist,alt_env,appveyor,demos,tests,test.py,kex_gss.py,kex_gex.py
+ignore = E124,E125,E128,E261,E301,E302,E303,E402
max-line-length = 79