1313
1414
1515class StormConfig (SSHConfig ):
16+ def __init__ (self , * a , ** kw ):
17+ super (StormConfig , self ).__init__ (* a , ** kw )
18+ self .lower_to_original = {}
19+
1620 def parse (self , file_obj ):
1721 """
1822 Read an OpenSSH config from the given file object.
@@ -49,19 +53,21 @@ def parse(self, file_obj):
4953 if line .lower ().strip ().startswith ('proxycommand' ):
5054 proxy_re = re .compile (r"^(proxycommand)\s*=*\s*(.*)" , re .I )
5155 match = proxy_re .match (line )
52- key , value = match .group (1 ). lower () , match .group (2 )
56+ key , value = match .group (1 ), match .group (2 )
5357 else :
5458 key , value = line .split ('=' , 1 )
55- key = key .strip (). lower ()
59+ key = key .strip ()
5660 else :
5761 # find first whitespace, and split there
5862 i = 0
5963 while (i < len (line )) and not line [i ].isspace ():
6064 i += 1
6165 if i == len (line ):
6266 raise Exception ('Unparsable line: %r' % line )
63- key = line [:i ]. lower ()
67+ key = line [:i ]
6468 value = line [i :].lstrip ()
69+ self .lower_to_original [key .lower ()] = key
70+ key = key .lower ()
6571 if key == 'host' :
6672 self ._config .append (host )
6773 value = value .split ()
@@ -92,6 +98,7 @@ def __init__(self, ssh_config_file=None):
9298 ssh_config_file = self .get_default_ssh_config_file ()
9399
94100 self .defaults = {}
101+ self .lower_to_original = {}
95102
96103 self .ssh_config_file = ssh_config_file
97104
@@ -111,6 +118,7 @@ def load(self):
111118
112119 with open (self .ssh_config_file ) as fd :
113120 config .parse (fd )
121+ self .lower_to_original = config .lower_to_original
114122
115123 for entry in config .__dict__ .get ("_config" ):
116124 if entry .get ("host" ) == ["*" ]:
@@ -218,12 +226,12 @@ def dump(self):
218226 sub_content = ""
219227 for value_ in value :
220228 sub_content += " {0} {1}\n " .format (
221- key , value_
229+ self . lower_to_original . get ( key ) or key , value_
222230 )
223231 host_item_content += sub_content
224232 else :
225233 host_item_content += " {0} {1}\n " .format (
226- key , value
234+ self . lower_to_original . get ( key ) or key , value
227235 )
228236 file_content += host_item_content
229237
0 commit comments