Skip to content

Commit

Permalink
Fix whitespace to reduce twistedchecker warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigc committed Nov 11, 2016
1 parent bdf158b commit e19a572
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/twisted/conch/avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self):
self.channelLookup = {}
self.subsystemLookup = {}


def lookupChannel(self, channelType, windowSize, maxPacket, data):
klass = self.channelLookup.get(channelType, None)
if not klass:
Expand All @@ -26,13 +27,15 @@ def lookupChannel(self, channelType, windowSize, maxPacket, data):
remoteMaxPacket=maxPacket,
data=data, avatar=self)


def lookupSubsystem(self, subsystem, data):
log.msg(repr(self.subsystemLookup))
klass = self.subsystemLookup.get(subsystem, None)
if not klass:
return False
return klass(data, avatar=self)


def gotGlobalRequest(self, requestType, data):
# XXX should this use method dispatch?
requestType = nativeString(requestType.replace(b'-', b'_'))
Expand Down
8 changes: 7 additions & 1 deletion src/twisted/conch/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def requestAvatarId(self, credentials):
d.addErrback(self._ebRequestAvatarId)
return d


def _cbRequestAvatarId(self, validKey, credentials):
"""
Check whether the credentials themselves are valid, now that we know
Expand Down Expand Up @@ -238,6 +239,7 @@ def checkKey(self, credentials):
continue
return False


def _ebRequestAvatarId(self, f):
if not f.check(UnauthorizedLogin):
log.msg(f)
Expand All @@ -263,6 +265,7 @@ def __init__(self):
self.checkers = {}
self.successfulCredentials = {}


def get_credentialInterfaces(self):
return _keys(self.checkers)

Expand All @@ -274,6 +277,7 @@ def registerChecker(self, checker, *credentialInterfaces):
for credentialInterface in credentialInterfaces:
self.checkers[credentialInterface] = checker


def requestAvatarId(self, credentials):
"""
Part of the L{ICredentialsChecker} interface. Called by a portal with
Expand All @@ -295,6 +299,7 @@ def requestAvatarId(self, credentials):
return defer.fail(UnhandledCredentials("No checker for %s" % \
', '.join(map(reflect.qual, ifac))))


def _cbGoodAuthentication(self, avatarId, credentials):
"""
Called if a checker has verified the credentials. We call our
Expand All @@ -311,6 +316,7 @@ def _cbGoodAuthentication(self, avatarId, credentials):
else:
raise error.NotEnoughAuthentication()


def areDone(self, avatarId):
"""
Override to determine if the authentication is finished for a given
Expand Down Expand Up @@ -579,7 +585,7 @@ def _verifyKey(self, pubKey, credentials):
try:
if pubKey.verify(credentials.signature, credentials.sigData):
return credentials.username
except: # any error should be treated as a failed login
except: # Any error should be treated as a failed login
log.err()
raise UnauthorizedLogin('Error while verifying key')

Expand Down
2 changes: 2 additions & 0 deletions src/twisted/conch/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ def _opener(self):
@classmethod
def _knownHosts(cls):
"""
@return: A L{KnownHostsFile} instance pointed at the user's personal
I{known hosts} file.
@type: L{KnownHostsFile}
Expand Down Expand Up @@ -830,6 +831,7 @@ def __init__(self, connection):

def secureConnection(self):
"""
@return: A L{Deferred} that fires synchronously with the
already-established connection object.
"""
Expand Down
23 changes: 21 additions & 2 deletions src/twisted/conch/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def gotGlobalRequest(requestType, data):
The method is called with arguments of windowSize, maxPacket, data.
"""



class ISession(Interface):

def getPty(term, windowSize, modes):
Expand Down Expand Up @@ -94,6 +96,7 @@ def closed():
"""



class ISFTPServer(Interface):
"""
SFTP subsystem for server-side communication.
Expand All @@ -108,6 +111,7 @@ class ISFTPServer(Interface):
and represents the logged-in user.
""")


def gotVersion(otherVersion, extData):
"""
Called when the client sends their version info.
Expand All @@ -123,6 +127,7 @@ def gotVersion(otherVersion, extData):
"""
return {}


def openFile(filename, flags, attrs):
"""
Called when the clients asks to open a file.
Expand Down Expand Up @@ -153,6 +158,7 @@ def openFile(filename, flags, attrs):
with the object.
"""


def removeFile(filename):
"""
Remove the given file.
Expand All @@ -163,6 +169,7 @@ def removeFile(filename):
@param filename: the name of the file as a string.
"""


def renameFile(oldpath, newpath):
"""
Rename the given file.
Expand All @@ -175,6 +182,7 @@ def renameFile(oldpath, newpath):
@param newpath: the new file name.
"""


def makeDirectory(path, attrs):
"""
Make a directory.
Expand All @@ -187,6 +195,7 @@ def makeDirectory(path, attrs):
Its meaning is the same as the attrs in the L{openFile} method.
"""


def removeDirectory(path):
"""
Remove a directory (non-recursively)
Expand All @@ -200,6 +209,7 @@ def removeDirectory(path):
@param path: the directory to remove.
"""


def openDirectory(path):
"""
Open a directory for scanning.
Expand Down Expand Up @@ -231,6 +241,7 @@ def openDirectory(path):
@param path: the directory to open.
"""


def getAttrs(path, followLinks):
"""
Return the attributes for the given path.
Expand All @@ -244,6 +255,7 @@ def getAttrs(path, followLinks):
return attributes for the specified path.
"""


def setAttrs(path, attrs):
"""
Set the attributes for the path.
Expand All @@ -256,6 +268,7 @@ def setAttrs(path, attrs):
L{openFile}.
"""


def readLink(path):
"""
Find the root of a set of symbolic links.
Expand All @@ -266,6 +279,7 @@ def readLink(path):
@param path: the path of the symlink to read.
"""


def makeLink(linkPath, targetPath):
"""
Create a symbolic link.
Expand All @@ -277,6 +291,7 @@ def makeLink(linkPath, targetPath):
@param targetPath: the path of the target of the link as a string.
"""


def realPath(path):
"""
Convert any path to an absolute path.
Expand All @@ -287,6 +302,7 @@ def realPath(path):
@param path: the path to convert as a string.
"""


def extendedRequest(extendedName, extendedData):
"""
This is the extension mechanism for SFTP. The other side can send us
Expand Down Expand Up @@ -338,6 +354,7 @@ def matchesHost(hostname):

def toString():
"""
@return: a serialized string representation of this entry, suitable for
inclusion in a known_hosts file. (Newline not included.)
Expand All @@ -360,6 +377,7 @@ def close():
Deferred that is called back when the close succeeds.
"""


def readChunk(offset, length):
"""
Read from the file.
Expand All @@ -375,6 +393,7 @@ def readChunk(offset, length):
this should read the requested number (up to the end of the file).
"""


def writeChunk(offset, data):
"""
Write to the file.
Expand All @@ -386,6 +405,7 @@ def writeChunk(offset, data):
@param data: a string that is the data to write.
"""


def getAttrs():
"""
Return the attributes for the file.
Expand All @@ -394,6 +414,7 @@ def getAttrs():
argument to L{openFile} or a L{Deferred} that is called back with same.
"""


def setAttrs(attrs):
"""
Set the attributes for the file.
Expand All @@ -404,5 +425,3 @@ def setAttrs(attrs):
@param attrs: a dictionary in the same format as the attrs argument to
L{openFile}.
"""


14 changes: 7 additions & 7 deletions src/twisted/conch/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from time import time, strftime, localtime
from twisted.python.compat import _PY3

# locale-independent month names to use instead of strftime's
# Locale-independent month names to use instead of strftime's
_MONTH_NAMES = dict(list(zip(
list(range(1, 13)),
"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split())))
Expand All @@ -30,19 +30,19 @@ def lsLine(name, s):
elif stat.S_ISLNK(ft): perms[0] = ord('l')
elif stat.S_ISSOCK(ft): perms[0] = ord('s')
else: perms[0] = ord('!')
# user
# User
if mode&stat.S_IRUSR:perms[1] = ord('r')
if mode&stat.S_IWUSR:perms[2] = ord('w')
if mode&stat.S_IXUSR:perms[3] = ord('x')
# group
# Group
if mode&stat.S_IRGRP:perms[4] = ord('r')
if mode&stat.S_IWGRP:perms[5] = ord('w')
if mode&stat.S_IXGRP:perms[6] = ord('x')
# other
# Other
if mode&stat.S_IROTH:perms[7] = ord('r')
if mode&stat.S_IWOTH:perms[8] = ord('w')
if mode&stat.S_IXOTH:perms[9] = ord('x')
# suid/sgid
# Suid/sgid
if mode&stat.S_ISUID:
if perms[3] == ord('x'): perms[3] = ord('s')
else: perms[3] = ord('S')
Expand All @@ -67,10 +67,10 @@ def lsLine(name, s):
str(s.st_size).rjust(8),
' ',
]
# need to specify the month manually, as strftime depends on locale
# Need to specify the month manually, as strftime depends on locale
ttup = localtime(s.st_mtime)
sixmonths = 60 * 60 * 24 * 7 * 26
if s.st_mtime + sixmonths < time(): # last edited more than 6mo ago
if s.st_mtime + sixmonths < time(): # Last edited more than 6mo ago
strtime = strftime("%%s %d %Y ", ttup)
else:
strtime = strftime("%%s %d %H:%M ", ttup)
Expand Down
Loading

0 comments on commit e19a572

Please sign in to comment.