Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve parsing method of hosts in ssh_config. #431

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions paramiko/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import fnmatch
import os
import re
import shlex
import socket

SSH_PORT = 22
Expand Down Expand Up @@ -54,7 +55,6 @@ def parse(self, file_obj):

: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()
Expand Down Expand Up @@ -222,25 +222,10 @@ def _get_hosts(self, host):
"""
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):
Expand Down