@@ -444,7 +444,10 @@ def loads(data, conf=True):
444444 kname , kval = re .match (key_regex , to_eval ).group (1 , 2 )
445445 if "#" not in kname :
446446 k = Key (kname , kval )
447- lopen [0 ].add (k )
447+ if lopen and isinstance (lopen [0 ], (Container , Server )):
448+ lopen [0 ].add (k )
449+ else :
450+ f .add (k ) if conf else f .append (k )
448451 if re .match (r'(^(?!#)([^#]*[}]{1}\s*)$)|(\s*{$)' , line_outside_quotes ):
449452 closenum = len (re .findall ('}' , line_outside_quotes ))
450453 while closenum > 0 :
@@ -454,7 +457,7 @@ def loads(data, conf=True):
454457 elif isinstance (lopen [0 ], Container ):
455458 c = lopen [0 ]
456459 lopen .pop (0 )
457- if lopen :
460+ if lopen and isinstance ( lopen [ 0 ], ( Container , Server )) :
458461 lopen [0 ].add (c )
459462 else :
460463 f .add (c ) if conf else f .append (c )
@@ -463,7 +466,7 @@ def loads(data, conf=True):
463466 cmt_regex = r'.*#\s*(.*)(?![^\'\"]*[\'\"])'
464467 c = Comment (re .match (cmt_regex , line ).group (1 ),
465468 inline = not re .match (r'^\s*#.*' , line ))
466- if len (lopen ):
469+ if lopen and isinstance (lopen [ 0 ], ( Container , Server ) ):
467470 lopen [0 ].add (c )
468471 else :
469472 f .add (c ) if conf else f .append (c )
0 commit comments