Skip to content

Commit

Permalink
Use classmethod decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigc committed Aug 20, 2016
1 parent 45d3b7e commit 98c8912
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
9 changes: 3 additions & 6 deletions src/twisted/conch/client/knownhosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(self, hostnames, keyType, publicKey, comment):
super(PlainEntry, self).__init__(keyType, publicKey, comment)


@classmethod
def fromString(cls, string):
"""
Parse a plain-text entry in a known_hosts file, and return a
Expand Down Expand Up @@ -149,8 +150,6 @@ def fromString(cls, string):
self = cls(hostnames.split(b","), keyType, key, comment)
return self

fromString = classmethod(fromString)


def matchesHost(self, hostname):
"""
Expand Down Expand Up @@ -270,6 +269,7 @@ def __init__(self, hostSalt, hostHash, keyType, publicKey, comment):
super(HashedEntry, self).__init__(keyType, publicKey, comment)


@classmethod
def fromString(cls, string):
"""
Load a hashed entry from a string representing a line in a known_hosts
Expand Down Expand Up @@ -301,8 +301,6 @@ def fromString(cls, string):
keyType, key, comment)
return self

fromString = classmethod(fromString)


def matchesHost(self, hostname):
"""
Expand Down Expand Up @@ -543,6 +541,7 @@ def save(self):
self._clobber = False


@classmethod
def fromPath(cls, path):
"""
Create a new L{KnownHostsFile}, potentially reading existing known
Expand All @@ -560,8 +559,6 @@ def fromPath(cls, path):
knownHosts._clobber = False
return knownHosts

fromPath = classmethod(fromPath)



class ConsoleUI(object):
Expand Down
6 changes: 3 additions & 3 deletions src/twisted/conch/ssh/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Key(object):
@ivar keyObject: DEPRECATED. The C{Crypto.PublicKey} object
that operations are performed with.
"""
@classmethod
def fromFile(cls, filename, type=None, passphrase=None):
"""
Load a key from a file.
Expand All @@ -90,9 +91,9 @@ def fromFile(cls, filename, type=None, passphrase=None):
"""
with open(filename, 'rb') as f:
return cls.fromString(f.read(), type, passphrase)
fromFile = classmethod(fromFile)


@classmethod
def fromString(cls, data, type=None, passphrase=None):
"""
Return a Key object corresponding to the string data.
Expand Down Expand Up @@ -128,7 +129,6 @@ def fromString(cls, data, type=None, passphrase=None):
return method(data)
else:
return method(data, passphrase)
fromString = classmethod(fromString)


@classmethod
Expand Down Expand Up @@ -486,6 +486,7 @@ def _fromString_AGENTV3(cls, data):
raise BadKeyError("unknown key type %s" % (keyType,))


@classmethod
def _guessStringType(cls, data):
"""
Guess the type of key in data. The types map to _fromString_*
Expand All @@ -512,7 +513,6 @@ def _guessStringType(cls, data):
return 'agentv3'
else:
return 'blob'
_guessStringType = classmethod(_guessStringType)


@classmethod
Expand Down

0 comments on commit 98c8912

Please sign in to comment.