MCPcopy Create free account
hub / github.com/etingof/apacheconfig / _dumpdict

Method _dumpdict

apacheconfig/loader.py:409–459  ·  view source on GitHub ↗
(self, obj, indent=0, continue_tag=False)

Source from the content-addressed store, hash-verified

407 self._ast_cache = {}
408
409 def _dumpdict(self, obj, indent=0, continue_tag=False):
410 if not isinstance(obj, dict):
411 raise error.ApacheConfigError('Unknown object type "%r" to dump'
412 % obj)
413
414 text = ''
415 spacing = ' ' * indent
416
417 for key, val in obj.items():
418 if isinstance(val, six.text_type):
419 if val.isalnum():
420 text += '%s%s %s\n' % (spacing, key, val)
421 else:
422 text += '%s%s "%s"\n' % (spacing, key, val)
423
424 elif isinstance(val, list):
425 for dup in val:
426 if isinstance(dup, six.text_type):
427 if dup.isalnum():
428 text += '%s%s %s\n' % (spacing, key, dup)
429 else:
430 text += '%s%s "%s"\n' % (spacing, key, dup)
431 else:
432 if self._options.get('namedblocks', True):
433 text += ('%s<%s>\n%s%s</%s>\n'
434 % (spacing, key,
435 self._dumpdict(dup, indent + 2),
436 spacing, key))
437 else:
438 text += ('%s<%s %s%s</%s>\n'
439 % (spacing, key,
440 self._dumpdict(dup, indent + 2,
441 continue_tag=True),
442 spacing, key))
443
444 else:
445 if self._options.get('namedblocks', True):
446 text += ('%s<%s>\n%s%s</%s>\n'
447 % (spacing, key, self._dumpdict(val, indent + 2),
448 spacing, key))
449 else:
450 if continue_tag:
451 text += ('%s>\n%s'
452 % (key, self._dumpdict(val, indent + 2)))
453 else:
454 text += ('%s<%s %s%s</%s>\n'
455 % (spacing, key,
456 self._dumpdict(val, indent + 2,
457 continue_tag=True),
458 spacing, key))
459 return text
460
461 def dumps(self, dct):
462 """Dumps the configuration in `dct` to a unicode string.

Callers 1

dumpsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected