@@ -247,8 +247,9 @@ def __setattr__(self, name, value):
247
247
def __str__ (self ):
248
248
out = []
249
249
out .append ('[%s]' % self ._section )
250
- for optBind in self ._config .optBinds ():
251
- out .append ('%s: %s' % (optBind .first , optBind .second .getValueString ()))
250
+ if self ._config :
251
+ for optBind in self ._config .optBinds ():
252
+ out .append ('%s: %s' % (optBind .first , optBind .second .getValueString ()))
252
253
return '\n ' .join (out )
253
254
254
255
def _get_option (self , name ):
@@ -278,6 +279,8 @@ def _populate(self, parser, section, filename, priority=PRIO_DEFAULT):
278
279
value = None
279
280
280
281
try :
282
+ if not self ._config :
283
+ raise RuntimeError ()
281
284
self ._config .optBinds ().at (name ).newString (priority , value )
282
285
except RuntimeError :
283
286
opt = self ._get_option (name )
@@ -308,12 +311,13 @@ def dump(self):
308
311
"""
309
312
output = ['[%s]' % self ._section ]
310
313
311
- for optBind in self ._config .optBinds ():
312
- # if not opt._is_runtimeonly():
313
- try :
314
- output .append ('%s = %s' % (optBind .first , optBind .second .getValueString ()))
315
- except RuntimeError :
316
- pass
314
+ if self ._config :
315
+ for optBind in self ._config .optBinds ():
316
+ # if not opt._is_runtimeonly():
317
+ try :
318
+ output .append ('%s = %s' % (optBind .first , optBind .second .getValueString ()))
319
+ except RuntimeError :
320
+ pass
317
321
318
322
return '\n ' .join (output ) + '\n '
319
323
@@ -336,12 +340,14 @@ def _write(self, fileobj, section=None, always=()):
336
340
# Updated the ConfigParser with the changed values
337
341
cfg_options = self ._parser .options (section )
338
342
339
- for optBind in self ._config .optBinds ():
340
- # if (not option._is_runtimeonly() and
341
- if (always is None or optBind .first in always or
342
- optBind .second .getPriority () >= PRIO_DEFAULT or
343
- optBind .first in cfg_options ):
344
- self ._parser .set (section , optBind .first , optBind .second .getValueString ())
343
+ if self ._config :
344
+ for optBind in self ._config .optBinds ():
345
+ # if (not option._is_runtimeonly() and
346
+ if (always is None or optBind .first in always or
347
+ optBind .second .getPriority () >= PRIO_DEFAULT or
348
+ optBind .first in cfg_options ):
349
+ self ._parser .set (section , optBind .first , optBind .second .getValueString ())
350
+
345
351
# write the updated ConfigParser to the fileobj.
346
352
self ._parser .write (fileobj )
347
353
0 commit comments