def dump_sections(self, o, sup): retstr = "" pre = "" if sup: pre = sup + "." for section, value in o.items(): section = str(section) qsection = section if not re.match(r'^[A-Za-z0-9_-]+$', section): qsection = _dump_str(section) if value is not None: if isinstance(value, dict): toadd, _ = self.dump_sections(value, pre + qsection) retstr += toadd else: retstr += (pre + qsection + " = " + str(self.dump_value(value)) + '\n') return (retstr, self._dict())
def _dump_uuid(obj: UUID) -> str: return _dump_str(str(obj))
def _dump_enum(obj: Enum) -> str: return _dump_str(obj.value)
def _dump_hasstr(obj: HasStr) -> str: return _dump_str(str(obj))
def _make_key(cls, path): return ".".join([ _ if cls._BARE_KEY_REGEX.match(_) else _dump_str(_) for _ in path ])
def _dump_str_prefer_multiline(v): multilines = v.split('\n') if len(multilines) > 1: return unicode('"""\n' + v.replace('"""', '\\"""').strip() + '\n"""') else: return _dump_str(v)