chiark / gitweb /
extract-profile.in: Allow empty sections.
[distorted-keys] / extract-profile.in
index c3a224b09bfbe60ea8f73ae30ae9466ac89e892b..918da8c884229df4e7f74fd19b0a2eaccecf3184 100755 (executable)
@@ -279,7 +279,7 @@ class Section (object, UD.DictMixin):
         left = dol + 1
         while left < n and (string[left].isalnum() or string[left] in '-_'):
           left += 1
-        prop = string[dol + 1:left].replace('-', '_')
+        prop = string[dol + 1:left]
 
       ## If we came up empty, report an error.
       if prop == '':
@@ -287,6 +287,7 @@ class Section (object, UD.DictMixin):
               "invalid placeholder (empty name) in `%s'" % string
 
       ## Extend the path: we're going to do a recursive expansion.
+      prop = prop.replace('-', '_')
       path.append(prop)
 
       ## Report a cycle if we found one.
@@ -375,6 +376,8 @@ def parse(filename, d):
         continue
       if line[0] == '[' and line[-1] == ']':
         sect = line[1:-1]
+        if sect not in d:
+          d[sect] = Section(sect)
         continue
 
       ## Parse an assignment.
@@ -392,12 +395,7 @@ def parse(filename, d):
         raise UserError, "%s:%d: bad name `%s'" % (filename, n, name)
 
       ## Store the assignment.
-      try:
-        d[sect][name] = value
-      except KeyError:
-        s = Section(sect)
-        d[sect] = s
-        s[name] = value
+      d[sect][name] = value
 
 ###--------------------------------------------------------------------------
 ### Main program.