Skip to content

Commit

Permalink
Even more flake8.
Browse files Browse the repository at this point in the history
  • Loading branch information
dorianpula authored and bitprophet committed Jun 1, 2017
1 parent 28218bf commit fa96fe0
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 109 deletions.
37 changes: 20 additions & 17 deletions paramiko/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ def open_only(func):
"""
@wraps(func)
def _check(self, *args, **kwds):
if (
self.closed
or self.eof_received
or self.eof_sent
or not self.active
):
if self.closed or self.eof_received or self.eof_sent or \
not self.active:
raise SSHException('Channel is not open')
return func(self, *args, **kwds)
return _check
Expand All @@ -74,7 +70,7 @@ class Channel (ClosingContextManager):
flow-controlled independently.) Similarly, if the server isn't reading
data you send, calls to `send` may block, unless you set a timeout. This
is exactly like a normal network socket, so it shouldn't be too surprising.
Instances of this class may be used as context managers.
"""

Expand Down Expand Up @@ -157,7 +153,8 @@ def get_pty(self, term='vt100', width=80, height=24, width_pixels=0,
It isn't necessary (or desirable) to call this method if you're going
to execute a single command with `exec_command`.
:param str term: the terminal type to emulate (for example, ``'vt100'``)
:param str term: the terminal type to emulate
(for example, ``'vt100'``)
:param int width: width (in characters) of the terminal screen
:param int height: height (in characters) of the terminal screen
:param int width_pixels: width (in pixels) of the terminal screen
Expand Down Expand Up @@ -347,8 +344,14 @@ def send_exit_status(self, status):
self.transport._send_user_message(m)

@open_only
def request_x11(self, screen_number=0, auth_protocol=None, auth_cookie=None,
single_connection=False, handler=None):
def request_x11(
self,
screen_number=0,
auth_protocol=None,
auth_cookie=None,
single_connection=False,
handler=None
):
"""
Request an x11 session on this channel. If the server allows it,
further x11 requests can be made from the server to the client,
Expand All @@ -364,7 +367,7 @@ def request_x11(self, screen_number=0, auth_protocol=None, auth_cookie=None,
generated, used, and returned. You will need to use this value to
verify incoming x11 requests and replace them with the actual local
x11 cookie (which requires some knowledge of the x11 protocol).
If a handler is passed in, the handler is called from another thread
whenever a new x11 connection arrives. The default handler queues up
incoming x11 connections, which may be retrieved using
Expand Down Expand Up @@ -497,16 +500,16 @@ def set_combine_stderr(self, combine):
self._feed(data)
return old

### socket API
# ...socket API...

def settimeout(self, timeout):
"""
Set a timeout on blocking read/write operations. The ``timeout``
argument can be a nonnegative float expressing seconds, or ``None``. If
a float is given, subsequent channel read/write operations will raise
a timeout exception if the timeout period value has elapsed before the
operation has completed. Setting a timeout of ``None`` disables
timeouts on socket operations.
argument can be a nonnegative float expressing seconds, or ``None``.
If a float is given, subsequent channel read/write operations will
raise a timeout exception if the timeout period value has elapsed
before the operation has completed. Setting a timeout of ``None``
disables timeouts on socket operations.
``chan.settimeout(0.0)`` is equivalent to ``chan.setblocking(0)``;
``chan.settimeout(None)`` is equivalent to ``chan.setblocking(1)``.
Expand Down
8 changes: 5 additions & 3 deletions paramiko/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
Common constants and global variables.
"""
import logging
from paramiko.py3compat import byte_chr, PY2, bytes_types, string_types, b, long
from paramiko.py3compat import byte_chr, PY2, bytes_types, string_types, b,\
long

MSG_DISCONNECT, MSG_IGNORE, MSG_UNIMPLEMENTED, MSG_DEBUG, \
MSG_SERVICE_REQUEST, MSG_SERVICE_ACCEPT = range(1, 7)
Expand All @@ -31,7 +32,7 @@
MSG_USERAUTH_INFO_REQUEST, MSG_USERAUTH_INFO_RESPONSE = range(60, 62)
MSG_USERAUTH_GSSAPI_RESPONSE, MSG_USERAUTH_GSSAPI_TOKEN = range(60, 62)
MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE, MSG_USERAUTH_GSSAPI_ERROR,\
MSG_USERAUTH_GSSAPI_ERRTOK, MSG_USERAUTH_GSSAPI_MIC = range(63, 67)
MSG_USERAUTH_GSSAPI_ERRTOK, MSG_USERAUTH_GSSAPI_MIC = range(63, 67)
MSG_GLOBAL_REQUEST, MSG_REQUEST_SUCCESS, MSG_REQUEST_FAILURE = range(80, 83)
MSG_CHANNEL_OPEN, MSG_CHANNEL_OPEN_SUCCESS, MSG_CHANNEL_OPEN_FAILURE, \
MSG_CHANNEL_WINDOW_ADJUST, MSG_CHANNEL_DATA, MSG_CHANNEL_EXTENDED_DATA, \
Expand Down Expand Up @@ -171,6 +172,7 @@ def asbytes(s):
raise Exception('Unknown type')
return s


xffffffff = long(0xffffffff)
x80000000 = long(0x80000000)
o666 = 438
Expand Down Expand Up @@ -203,4 +205,4 @@ def asbytes(s):
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
16 changes: 11 additions & 5 deletions paramiko/kex_gex.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def _parse_kexdh_gex_request(self, m):
# generate prime
pack = self.transport._get_modulus_pack()
if pack is None:
raise SSHException('Can\'t do server-side gex with no modulus pack')
raise SSHException(
'Can\'t do server-side gex with no modulus pack')
self.transport._log(
DEBUG,
'Picking p (%d <= %d <= %d bits)' % (
Expand All @@ -162,7 +163,8 @@ def _parse_kexdh_gex_request_old(self, m):
# generate prime
pack = self.transport._get_modulus_pack()
if pack is None:
raise SSHException('Can\'t do server-side gex with no modulus pack')
raise SSHException(
'Can\'t do server-side gex with no modulus pack')
self.transport._log(
DEBUG, 'Picking p (~ %d bits)' % (self.preferred_bits,))
self.g, self.p = pack.get_modulus(
Expand All @@ -181,7 +183,9 @@ def _parse_kexdh_gex_group(self, m):
# reject if p's bit length < 1024 or > 8192
bitlen = util.bit_length(self.p)
if (bitlen < 1024) or (bitlen > 8192):
raise SSHException('Server-generated gex p (don\'t ask) is out of range (%d bits)' % bitlen)
raise SSHException(
'Server-generated gex p (don\'t ask) is out of range '
'(%d bits)' % bitlen)
self.transport._log(DEBUG, 'Got server p (%d bits)' % bitlen)
self._generate_x()
# now compute e = g^x mod p
Expand All @@ -200,7 +204,8 @@ def _parse_kexdh_gex_init(self, m):
self.f = pow(self.g, self.x, self.p)
K = pow(self.e, self.x, self.p)
key = self.transport.get_server_key().asbytes()
# okay, build up the hash H of (V_C || V_S || I_C || I_S || K_S || min || n || max || p || g || e || f || K)
# okay, build up the hash H of
# (V_C || V_S || I_C || I_S || K_S || min || n || max || p || g || e || f || K) # noqa
hm = Message()
hm.add(self.transport.remote_version, self.transport.local_version,
self.transport.remote_kex_init, self.transport.local_kex_init,
Expand Down Expand Up @@ -235,7 +240,8 @@ def _parse_kexdh_gex_reply(self, m):
if (self.f < 1) or (self.f > self.p - 1):
raise SSHException('Server kex "f" is out of range')
K = pow(self.f, self.x, self.p)
# okay, build up the hash H of (V_C || V_S || I_C || I_S || K_S || min || n || max || p || g || e || f || K)
# okay, build up the hash H of
# (V_C || V_S || I_C || I_S || K_S || min || n || max || p || g || e || f || K) # noqa
hm = Message()
hm.add(self.transport.local_version, self.transport.remote_version,
self.transport.local_kex_init, self.transport.remote_kex_init,
Expand Down
17 changes: 10 additions & 7 deletions paramiko/kex_group1.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
class KexGroup1(object):

# draft-ietf-secsh-transport-09.txt, page 17
P = 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF
P = 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF # noqa
G = 2

name = 'diffie-hellman-group1-sha1'
Expand Down Expand Up @@ -75,14 +75,15 @@ def parse_next(self, ptype, m):
return self._parse_kexdh_reply(m)
raise SSHException('KexGroup1 asked to handle packet type %d' % ptype)

### internals...
# ...internals...

def _generate_x(self):
# generate an "x" (1 < x < q), where q is (p-1)/2.
# p is a 128-byte (1024-bit) number, where the first 64 bits are 1.
# p is a 128-byte (1024-bit) number, where the first 64 bits are 1.
# therefore q can be approximated as a 2^1023. we drop the subset of
# potential x where the first 63 bits are 1, because some of those will be
# larger than q (but this is a tiny tiny subset of potential x).
# potential x where the first 63 bits are 1, because some of those
# will be larger than q (but this is a tiny tiny subset of
# potential x).
while 1:
x_bytes = os.urandom(128)
x_bytes = byte_mask(x_bytes[0], 0x7f) + x_bytes[1:]
Expand All @@ -99,7 +100,8 @@ def _parse_kexdh_reply(self, m):
raise SSHException('Server kex "f" is out of range')
sig = m.get_binary()
K = pow(self.f, self.x, self.P)
# okay, build up the hash H of (V_C || V_S || I_C || I_S || K_S || e || f || K)
# okay, build up the hash H of
# (V_C || V_S || I_C || I_S || K_S || e || f || K)
hm = Message()
hm.add(self.transport.local_version, self.transport.remote_version,
self.transport.local_kex_init, self.transport.remote_kex_init)
Expand All @@ -118,7 +120,8 @@ def _parse_kexdh_init(self, m):
raise SSHException('Client kex "e" is out of range')
K = pow(self.e, self.x, self.P)
key = self.transport.get_server_key().asbytes()
# okay, build up the hash H of (V_C || V_S || I_C || I_S || K_S || e || f || K)
# okay, build up the hash H of
# (V_C || V_S || I_C || I_S || K_S || e || f || K)
hm = Message()
hm.add(self.transport.remote_version, self.transport.local_version,
self.transport.remote_kex_init, self.transport.local_kex_init)
Expand Down
Loading

0 comments on commit fa96fe0

Please sign in to comment.