Example #1
0
    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())
Example #2
0
def _dump_uuid(obj: UUID) -> str:
    return _dump_str(str(obj))
Example #3
0
def _dump_enum(obj: Enum) -> str:
    return _dump_str(obj.value)
Example #4
0
def _dump_hasstr(obj: HasStr) -> str:
    return _dump_str(str(obj))
Example #5
0
 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)