diff options
author | Yan Kalchevskiy <yan.kalchevskiy@gmail.com> | 2014-01-22 16:30:20 +0700 |
---|---|---|
committer | Yan Kalchevksiy <yan.kalchevskiy@gmail.com> | 2014-04-22 10:56:08 +0700 |
commit | 59b7cc7a0296090f5b7a58226e74d4b293d00103 (patch) | |
tree | 3d71c651ae2ed392d22eda0319582b0790470c72 | |
parent | 8a836942d545ffa44ed139099dfea4f96d336add (diff) |
Simplify handling of the configuration file.
-rw-r--r-- | paramiko/config.py | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/paramiko/config.py b/paramiko/config.py index 28dc5231..dce472ee 100644 --- a/paramiko/config.py +++ b/paramiko/config.py @@ -27,7 +27,6 @@ import re import socket SSH_PORT = 22 -proxy_re = re.compile(r"^(proxycommand)\s*=*\s*(.*)", re.I) class SSHConfig (object): @@ -41,6 +40,8 @@ class SSHConfig (object): .. versionadded:: 1.6 """ + SETTINGS_REGEX = re.compile(r'(\w+)(?:\s*=\s*|\s+)(.+)') + def __init__(self): """ Create a new OpenSSH config object. @@ -79,23 +80,12 @@ class SSHConfig (object): line = line.rstrip('\n').lstrip() if (line == '') or (line[0] == '#'): continue - if '=' in line: - # Ensure ProxyCommand gets properly split - if line.lower().strip().startswith('proxycommand'): - match = proxy_re.match(line) - key, value = match.group(1).lower(), match.group(2) - else: - key, value = line.split('=', 1) - key = key.strip().lower() - else: - # find first whitespace, and split there - i = 0 - while (i < len(line)) and not line[i].isspace(): - i += 1 - if i == len(line): - raise Exception('Unparsable line: %r' % line) - key = line[:i].lower() - value = line[i:].lstrip() + + match = re.match(self.SETTINGS_REGEX, line) + if not match: + raise Exception("Unparsable line %s" % line) + key = match.group(1).lower() + value = match.group(2) if key == 'host': self._config.append(host) |