Pep8 fixes

This commit is contained in:
Olle Lundberg 2012-10-16 15:00:02 +02:00
parent 85551dffd6
commit 42d77483e8
1 changed files with 10 additions and 10 deletions

View File

@ -26,7 +26,6 @@ import os
import re import re
import socket import socket
SSH_PORT = 22 SSH_PORT = 22
proxy_re = re.compile(r"^(proxycommand)\s*=*\s*(.*)", re.I) proxy_re = re.compile(r"^(proxycommand)\s*=*\s*(.*)", re.I)
@ -85,7 +84,6 @@ class SSHConfig (object):
""" """
self._config = [] self._config = []
def parse(self, file_obj): def parse(self, file_obj):
""" """
Read an OpenSSH config from the given file object. Read an OpenSSH config from the given file object.
@ -93,7 +91,7 @@ class SSHConfig (object):
@param file_obj: a file-like object to read the config file from @param file_obj: a file-like object to read the config file from
@type file_obj: file @type file_obj: file
""" """
host = {"host":['*'],"config":{}} host = {"host": ['*'], "config": {}}
for line in file_obj: for line in file_obj:
line = line.rstrip('\n').lstrip() line = line.rstrip('\n').lstrip()
if (line == '') or (line[0] == '#'): if (line == '') or (line[0] == '#'):
@ -119,7 +117,7 @@ class SSHConfig (object):
if key == 'host': if key == 'host':
self._config.append(host) self._config.append(host)
value = value.split() value = value.split()
host = {key:value,'config':{}} host = {key: value, 'config': {}}
#identityfile is a special case, since it is allowed to be #identityfile is a special case, since it is allowed to be
# specified multiple times and they should be tried in order # specified multiple times and they should be tried in order
# of specification. # of specification.
@ -129,7 +127,7 @@ class SSHConfig (object):
else: else:
host['config']['identityfile'] = [value] host['config']['identityfile'] = [value]
elif key not in host['config']: elif key not in host['config']:
host['config'].update({key:value}) host['config'].update({key: value})
self._config.append(host) self._config.append(host)
def lookup(self, hostname): def lookup(self, hostname):
@ -152,8 +150,8 @@ class SSHConfig (object):
@type hostname: str @type hostname: str
""" """
matches = [ config for config in self._config if matches = [config for config in self._config if
self._allowed(hostname,config['host']) ] self._allowed(hostname, config['host'])]
ret = {} ret = {}
for match in matches: for match in matches:
@ -193,7 +191,7 @@ class SSHConfig (object):
""" """
if 'hostname' in config: if 'hostname' in config:
config['hostname'] = config['hostname'].replace('%h',hostname) config['hostname'] = config['hostname'].replace('%h', hostname)
else: else:
config['hostname'] = hostname config['hostname'] = hostname
@ -235,12 +233,14 @@ class SSHConfig (object):
('%r', remoteuser), ('%r', remoteuser),
], ],
} }
for k in config: for k in config:
if k in replacements: if k in replacements:
for find, replace in replacements[k]: for find, replace in replacements[k]:
if isinstance(config[k],list): if isinstance(config[k], list):
for item in range(len(config[k])): for item in range(len(config[k])):
config[k][item] = config[k][item].replace(find, str(replace)) config[k][item] = config[k][item].\
replace(find, str(replace))
else: else:
config[k] = config[k].replace(find, str(replace)) config[k] = config[k].replace(find, str(replace))
return config return config