Пример #1
0
def pprint(data, tag_lookup, indent=0):
    """Return a pretty formatted string of parsed DMAP data."""
    output = ""
    if isinstance(data, dict):
        for key, value in data.items():
            tag = tag_lookup(key)
            if isinstance(value, (dict, list)) and tag.type is not read_bplist:
                output += indent * " " + f"{key}: {tag}\n"
                output += pprint(value, tag_lookup, indent + 2)
            else:
                output += indent * " " + f"{key}: {value} {tag}\n"
    elif isinstance(data, list):
        for elem in data:
            output += pprint(elem, tag_lookup, indent)
    else:
        raise exceptions.InvalidDmapDataError(f"invalid dmap data: {data}")
    return output
Пример #2
0
def pprint(data, tag_lookup, indent=0):
    """Return a pretty formatted string of parsed DMAP data."""
    output = ''
    if isinstance(data, dict):
        for key, value in data.items():
            tag = tag_lookup(key)
            if isinstance(value, (dict, list)):
                output += '{0}{1}: {2}\n'.format(indent * ' ', key, tag)
                output += pprint(value, tag_lookup, indent + 2)
            else:
                output += '{0}{1}: {2} {3}\n'.format(indent * ' ', key,
                                                     str(value), tag)
    elif isinstance(data, list):
        for elem in data:
            output += pprint(elem, tag_lookup, indent)
    else:
        raise exceptions.InvalidDmapDataError('invalid dmap data: ' +
                                              str(data))
    return output
Пример #3
0
def pprint(data, tag_lookup, indent=0):
    """Return a pretty formatted string of parsed DMAP data."""
    output = ""
    if isinstance(data, dict):
        for key, value in data.items():
            tag = tag_lookup(key)
            if isinstance(value, (dict, list)) and tag.type is not read_bplist:
                output += "{0}{1}: {2}\n".format(indent * " ", key, tag)
                output += pprint(value, tag_lookup, indent + 2)
            else:
                output += "{0}{1}: {2} {3}\n".format(indent * " ", key,
                                                     str(value), tag)
    elif isinstance(data, list):
        for elem in data:
            output += pprint(elem, tag_lookup, indent)
    else:
        raise exceptions.InvalidDmapDataError("invalid dmap data: " +
                                              str(data))
    return output