summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJacob Beck <jbeck@colorado.edu>2014-10-14 21:37:45 -0600
committerJacob Beck <jbeck@colorado.edu>2014-10-14 21:37:45 -0600
commit5fbd4e3b6fcdc9edc04f84134d0ae76f349854a7 (patch)
tree88e9d9b51477ae21d3c906017b6c377e102e325b
parentd9caab12578c242294aea95c7ad3dada361c4455 (diff)
Converted all staticmethod/classmethod instances to decorators.
-rw-r--r--paramiko/ber.py6
-rw-r--r--paramiko/dsskey.py2
-rw-r--r--paramiko/ecdsakey.py2
-rw-r--r--paramiko/hostkeys.py4
-rw-r--r--paramiko/pkey.py4
-rw-r--r--paramiko/rsakey.py2
-rw-r--r--paramiko/sftp_attr.py7
-rw-r--r--paramiko/sftp_client.py4
-rw-r--r--paramiko/sftp_server.py4
-rw-r--r--paramiko/transport.py4
-rw-r--r--paramiko/util.py2
-rw-r--r--tests/test_gssapi.py4
-rw-r--r--tests/test_kex_gss.py4
-rwxr-xr-xtests/test_sftp.py7
-rw-r--r--tests/test_ssh_gss.py4
15 files changed, 26 insertions, 34 deletions
diff --git a/paramiko/ber.py b/paramiko/ber.py
index 05152303..a388df07 100644
--- a/paramiko/ber.py
+++ b/paramiko/ber.py
@@ -45,7 +45,7 @@ class BER(object):
def decode(self):
return self.decode_next()
-
+
def decode_next(self):
if self.idx >= len(self.content):
return None
@@ -89,6 +89,7 @@ class BER(object):
# 1: boolean (00 false, otherwise true)
raise BERException('Unknown ber encoding type %d (robey is lazy)' % ident)
+ @staticmethod
def decode_sequence(data):
out = []
ber = BER(data)
@@ -98,7 +99,6 @@ class BER(object):
break
out.append(x)
return out
- decode_sequence = staticmethod(decode_sequence)
def encode_tlv(self, ident, val):
# no need to support ident > 31 here
@@ -125,9 +125,9 @@ class BER(object):
else:
raise BERException('Unknown type for encoding: %s' % repr(type(x)))
+ @staticmethod
def encode_sequence(data):
ber = BER()
for item in data:
ber.encode(item)
return ber.asbytes()
- encode_sequence = staticmethod(encode_sequence)
diff --git a/paramiko/dsskey.py b/paramiko/dsskey.py
index 1901596d..d7dd6275 100644
--- a/paramiko/dsskey.py
+++ b/paramiko/dsskey.py
@@ -154,6 +154,7 @@ class DSSKey (PKey):
def write_private_key(self, file_obj, password=None):
self._write_private_key('DSA', file_obj, self._encode_key(), password)
+ @staticmethod
def generate(bits=1024, progress_func=None):
"""
Generate a new private DSS key. This factory function can be used to
@@ -169,7 +170,6 @@ class DSSKey (PKey):
key = DSSKey(vals=(dsa.p, dsa.q, dsa.g, dsa.y))
key.x = dsa.x
return key
- generate = staticmethod(generate)
### internals...
diff --git a/paramiko/ecdsakey.py b/paramiko/ecdsakey.py
index a7f3c5ed..6b047959 100644
--- a/paramiko/ecdsakey.py
+++ b/paramiko/ecdsakey.py
@@ -126,6 +126,7 @@ class ECDSAKey (PKey):
key = self.signing_key or self.verifying_key
self._write_private_key('EC', file_obj, key.to_der(), password)
+ @staticmethod
def generate(curve=curves.NIST256p, progress_func=None):
"""
Generate a new private RSA key. This factory function can be used to
@@ -139,7 +140,6 @@ class ECDSAKey (PKey):
signing_key = SigningKey.generate(curve)
key = ECDSAKey(vals=(signing_key, signing_key.get_verifying_key()))
return key
- generate = staticmethod(generate)
### internals...
diff --git a/paramiko/hostkeys.py b/paramiko/hostkeys.py
index b94ff0db..84868875 100644
--- a/paramiko/hostkeys.py
+++ b/paramiko/hostkeys.py
@@ -255,6 +255,7 @@ class HostKeys (MutableMapping):
ret.append(self.lookup(k))
return ret
+ @staticmethod
def hash_host(hostname, salt=None):
"""
Return a "hashed" form of the hostname, as used by OpenSSH when storing
@@ -274,7 +275,6 @@ class HostKeys (MutableMapping):
hmac = HMAC(salt, b(hostname), sha1).digest()
hostkey = '|1|%s|%s' % (u(encodebytes(salt)), u(encodebytes(hmac)))
return hostkey.replace('\n', '')
- hash_host = staticmethod(hash_host)
class InvalidHostKey(Exception):
@@ -294,6 +294,7 @@ class HostKeyEntry:
self.hostnames = hostnames
self.key = key
+ @classmethod
def from_line(cls, line, lineno=None):
"""
Parses the given line of text to find the names for the host,
@@ -336,7 +337,6 @@ class HostKeyEntry:
raise InvalidHostKey(line, e)
return cls(names, key)
- from_line = classmethod(from_line)
def to_line(self):
"""
diff --git a/paramiko/pkey.py b/paramiko/pkey.py
index 2daf3723..1b4af010 100644
--- a/paramiko/pkey.py
+++ b/paramiko/pkey.py
@@ -160,6 +160,7 @@ class PKey (object):
"""
return False
+ @classmethod
def from_private_key_file(cls, filename, password=None):
"""
Create a key object by reading a private key file. If the private
@@ -181,8 +182,8 @@ class PKey (object):
"""
key = cls(filename=filename, password=password)
return key
- from_private_key_file = classmethod(from_private_key_file)
+ @classmethod
def from_private_key(cls, file_obj, password=None):
"""
Create a key object by reading a private key from a file (or file-like)
@@ -202,7 +203,6 @@ class PKey (object):
"""
key = cls(file_obj=file_obj, password=password)
return key
- from_private_key = classmethod(from_private_key)
def write_private_key_file(self, filename, password=None):
"""
diff --git a/paramiko/rsakey.py b/paramiko/rsakey.py
index d1f3ecfe..4ebd8354 100644
--- a/paramiko/rsakey.py
+++ b/paramiko/rsakey.py
@@ -131,6 +131,7 @@ class RSAKey (PKey):
def write_private_key(self, file_obj, password=None):
self._write_private_key('RSA', file_obj, self._encode_key(), password)
+ @staticmethod
def generate(bits, progress_func=None):
"""
Generate a new private RSA key. This factory function can be used to
@@ -148,7 +149,6 @@ class RSAKey (PKey):
key.p = rsa.p
key.q = rsa.q
return key
- generate = staticmethod(generate)
### internals...
diff --git a/paramiko/sftp_attr.py b/paramiko/sftp_attr.py
index d12eff8d..cf48f654 100644
--- a/paramiko/sftp_attr.py
+++ b/paramiko/sftp_attr.py
@@ -60,6 +60,7 @@ class SFTPAttributes (object):
self.st_mtime = None
self.attr = {}
+ @classmethod
def from_stat(cls, obj, filename=None):
"""
Create an `.SFTPAttributes` object from an existing ``stat`` object (an
@@ -79,13 +80,12 @@ class SFTPAttributes (object):
if filename is not None:
attr.filename = filename
return attr
- from_stat = classmethod(from_stat)
def __repr__(self):
return '<SFTPAttributes: %s>' % self._debug_str()
### internals...
-
+ @classmethod
def _from_msg(cls, msg, filename=None, longname=None):
attr = cls()
attr._unpack(msg)
@@ -94,7 +94,6 @@ class SFTPAttributes (object):
if longname is not None:
attr.longname = longname
return attr
- _from_msg = classmethod(_from_msg)
def _unpack(self, msg):
self._flags = msg.get_int()
@@ -159,6 +158,7 @@ class SFTPAttributes (object):
out += ']'
return out
+ @staticmethod
def _rwx(n, suid, sticky=False):
if suid:
suid = 2
@@ -168,7 +168,6 @@ class SFTPAttributes (object):
else:
out += '-xSs'[suid + (n & 1)]
return out
- _rwx = staticmethod(_rwx)
def __str__(self):
"""create a unix-style long description of the file (like ls -l)"""
diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py
index 62127cc2..89840eaa 100644
--- a/paramiko/sftp_client.py
+++ b/paramiko/sftp_client.py
@@ -65,7 +65,7 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
Used to open an SFTP session across an open SSH `.Transport` and perform
remote file operations.
-
+
Instances of this class may be used as context managers.
"""
def __init__(self, sock):
@@ -101,6 +101,7 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
raise SSHException('EOF during negotiation')
self._log(INFO, 'Opened sftp connection (server version %d)' % server_version)
+ @classmethod
def from_transport(cls, t, window_size=None, max_packet_size=None):
"""
Create an SFTP client channel from an open `.Transport`.
@@ -129,7 +130,6 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
return None
chan.invoke_subsystem('sftp')
return cls(chan)
- from_transport = classmethod(from_transport)
def _log(self, level, msg, *args):
if isinstance(msg, list):
diff --git a/paramiko/sftp_server.py b/paramiko/sftp_server.py
index 2d8d1909..ce287e8f 100644
--- a/paramiko/sftp_server.py
+++ b/paramiko/sftp_server.py
@@ -129,6 +129,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
self.file_table = {}
self.folder_table = {}
+ @staticmethod
def convert_errno(e):
"""
Convert an errno value (as from an ``OSError`` or ``IOError``) into a
@@ -146,8 +147,8 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
return SFTP_NO_SUCH_FILE
else:
return SFTP_FAILURE
- convert_errno = staticmethod(convert_errno)
+ @staticmethod
def set_file_attr(filename, attr):
"""
Change a file's attributes on the local filesystem. The contents of
@@ -173,7 +174,6 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
if attr._flags & attr.FLAG_SIZE:
with open(filename, 'w+') as f:
f.truncate(attr.st_size)
- set_file_attr = staticmethod(set_file_attr)
### internals...
diff --git a/paramiko/transport.py b/paramiko/transport.py
index bf30c784..6ce9225d 100644
--- a/paramiko/transport.py
+++ b/paramiko/transport.py
@@ -88,7 +88,7 @@ class Transport (threading.Thread, ClosingContextManager):
`channels <.Channel>`, across the session. Multiple channels can be
multiplexed across a single session (and often are, in the case of port
forwardings).
-
+
Instances of this class may be used as context managers.
"""
_PROTO_ID = '2.0'
@@ -508,6 +508,7 @@ class Transport (threading.Thread, ClosingContextManager):
pass
return None
+ @staticmethod
def load_server_moduli(filename=None):
"""
(optional)
@@ -547,7 +548,6 @@ class Transport (threading.Thread, ClosingContextManager):
# none succeeded
Transport._modulus_pack = None
return False
- load_server_moduli = staticmethod(load_server_moduli)
def close(self):
"""
diff --git a/paramiko/util.py b/paramiko/util.py
index 88ca2bc4..2b3389a8 100644
--- a/paramiko/util.py
+++ b/paramiko/util.py
@@ -307,9 +307,9 @@ class Counter (object):
self.value = array.array('c', zero_byte * (self.blocksize - len(x)) + x)
return self.value.tostring()
+ @classmethod
def new(cls, nbits, initial_value=long(1), overflow=long(0)):
return cls(nbits, initial_value=initial_value, overflow=overflow)
- new = classmethod(new)
def constant_time_bytes_eq(a, b):
diff --git a/tests/test_gssapi.py b/tests/test_gssapi.py
index a328dd65..96c268d9 100644
--- a/tests/test_gssapi.py
+++ b/tests/test_gssapi.py
@@ -27,15 +27,13 @@ import socket
class GSSAPITest(unittest.TestCase):
-
+ @staticmethod
def init(hostname=None, srv_mode=False):
global krb5_mech, targ_name, server_mode
krb5_mech = "1.2.840.113554.1.2.2"
targ_name = hostname
server_mode = srv_mode
- init = staticmethod(init)
-
def test_1_pyasn1(self):
"""
Test the used methods of pyasn1.
diff --git a/tests/test_kex_gss.py b/tests/test_kex_gss.py
index 8769d09c..91d4c9b2 100644
--- a/tests/test_kex_gss.py
+++ b/tests/test_kex_gss.py
@@ -58,14 +58,12 @@ class NullServer (paramiko.ServerInterface):
class GSSKexTest(unittest.TestCase):
-
+ @staticmethod
def init(username, hostname):
global krb5_principal, targ_name
krb5_principal = username
targ_name = hostname
- init = staticmethod(init)
-
def setUp(self):
self.username = krb5_principal
self.hostname = socket.getfqdn(targ_name)
diff --git a/tests/test_sftp.py b/tests/test_sftp.py
index 72c7ba03..cb8f7f84 100755
--- a/tests/test_sftp.py
+++ b/tests/test_sftp.py
@@ -97,7 +97,7 @@ def get_sftp():
class SFTPTest (unittest.TestCase):
-
+ @staticmethod
def init(hostname, username, keyfile, passwd):
global sftp, tc
@@ -129,8 +129,8 @@ class SFTPTest (unittest.TestCase):
sys.stderr.write('\n')
sys.exit(1)
sftp = paramiko.SFTP.from_transport(t)
- init = staticmethod(init)
+ @staticmethod
def init_loopback():
global sftp, tc
@@ -150,12 +150,11 @@ class SFTPTest (unittest.TestCase):
event.wait(1.0)
sftp = paramiko.SFTP.from_transport(tc)
- init_loopback = staticmethod(init_loopback)
+ @staticmethod
def set_big_file_test(onoff):
global g_big_file_test
g_big_file_test = onoff
- set_big_file_test = staticmethod(set_big_file_test)
def setUp(self):
global FOLDER
diff --git a/tests/test_ssh_gss.py b/tests/test_ssh_gss.py
index 595081b8..99ccdc9c 100644
--- a/tests/test_ssh_gss.py
+++ b/tests/test_ssh_gss.py
@@ -57,14 +57,12 @@ class NullServer (paramiko.ServerInterface):
class GSSAuthTest(unittest.TestCase):
-
+ @staticmethod
def init(username, hostname):
global krb5_principal, targ_name
krb5_principal = username
targ_name = hostname
- init = staticmethod(init)
-
def setUp(self):
self.username = krb5_principal
self.hostname = socket.getfqdn(targ_name)