[master/f21 v3] Fix # handling in SimpleConfigFile (#1045687)
Brian C. Lane
bcl at redhat.com
Wed Oct 15 15:05:36 UTC 2014
On Wed, Oct 15, 2014 at 08:39:05AM -0400, Anne Mulhern wrote:
> > s = line.strip()
> > - if '#' in s:
> > - s = s[:s.find('#')] # remove from comment to EOL
> > - s = s.strip() # and any unnecessary whitespace
> > + # Look for a # outside any quotes
> > + comment = ""
> > + comment_index = find_comment(s)
> > + if comment_index is not None:
> > + comment = s[comment_index:]
> > + s = s[:comment_index] # remove from comment to EOL
> > + s = s.strip() # and any unnecessary whitespace
>
> You should lose the conditional strip() above.
>
> > +
> > key, eq, val = s.partition('=')
> > + key = key.strip()
>
> But add:
> val = val.strip()
>
> here, unless leading whitespace is significant in val, which seems unlikely.
Fixed locally.
>
> > if self.read_unquote:
> > val = unquote(val)
> > if key != '' and eq == '=':
> > - return (upperASCII(key), val)
> > + return (upperASCII(key), val, comment)
> > else:
> > - return (None, None)
> > + return (None, None, comment)
> >
> > def _kvpair(self, key, comment=""):
> > value = self.info[key]
> > if self.write_quote or self.always_quote:
> > value = quote(value, self.always_quote)
> > + if comment:
> > + comment = " " + comment
> > return key + '=' + value + comment + "\n"
>
> Above three lines could be:
> padding = " " if comment else ""
> return key + "=" + value + padding + comment + "\n"
Thanks, but it is clear enough as it stands.
--
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)
More information about the anaconda-patches
mailing list