summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYan Kalchevskiy <yan.kalchevskiy@gmail.com>2014-11-11 00:12:08 +0300
committerJeff Forcier <jeff@bitprophet.org>2014-12-17 15:09:06 -0800
commitdc1e3d0f787fd042d5eeb1f7ac0dd60c0aabbd1f (patch)
tree50ce049cd86c0a7deb8cf4ea9e1234dce9d14be9
parent1ad893aa91512cfa4fc3b0309ca9be62f6afd627 (diff)
Improve parsing method of hosts in ssh_config.
There is a module in standard library for such parsing -- shlex.
-rw-r--r--paramiko/config.py25
1 files changed, 5 insertions, 20 deletions
diff --git a/paramiko/config.py b/paramiko/config.py
index 85fdddd3..91943ffb 100644
--- a/paramiko/config.py
+++ b/paramiko/config.py
@@ -24,6 +24,7 @@ Configuration file (aka ``ssh_config``) support.
import fnmatch
import os
import re
+import shlex
import socket
SSH_PORT = 22
@@ -54,7 +55,6 @@ class SSHConfig (object):
:param file file_obj: a file-like object to read the config file from
"""
-
host = {"host": ['*'], "config": {}}
for line in file_obj:
line = line.rstrip('\r\n').lstrip()
@@ -222,25 +222,10 @@ class SSHConfig (object):
"""
Return a list of host_names from host value.
"""
- i, length = 0, len(host)
- hosts = []
- while i < length:
- if host[i] == '"':
- end = host.find('"', i + 1)
- if end < 0:
- raise Exception("Unparsable host %s" % host)
- hosts.append(host[i + 1:end])
- i = end + 1
- elif not host[i].isspace():
- end = i + 1
- while end < length and not host[end].isspace() and host[end] != '"':
- end += 1
- hosts.append(host[i:end])
- i = end
- else:
- i += 1
-
- return hosts
+ try:
+ return shlex.split(host)
+ except ValueError:
+ raise Exception("Unparsable host %s" % host)
class LazyFqdn(object):