This repository has been archived on 2024-06-13. You can view files and clone it, but cannot push or open issues or pull requests.
pymclevel/nbt_util.py
David Vierra a83821cd13 Clean up NBT modules.
Simplify the load and save interfaces. Replace the (data, data_cursor) tuples with a load_ctx object. Add an option to skip decoding tag names to unicode, improving speed and memory use if tag names are assumed to be ASCII. Make nbt.py and _nbt.pyx more consistent with each other. Use a similar method to import from _nbt.pyx as is seen in the standard library. Move pretty-print code to its own file and share it between implementations.
2012-10-10 23:28:27 -10:00

28 lines
801 B
Python

import nbt
def nested_string(tag, indent_string=" ", indent=0):
result = ""
if tag.tagID == nbt.TAG_COMPOUND:
result += 'TAG_Compound({\n'
indent += 1
for key, value in tag.iteritems():
result += indent_string * indent + '"%s": %s,\n' % (key, nested_string(value, indent_string, indent))
indent -= 1
result += indent_string * indent + '})'
elif tag.tagID == nbt.TAG_LIST:
result += 'TAG_List([\n'
indent += 1
for index, value in enumerate(tag):
result += indent_string * indent + nested_string(value, indent_string, indent) + ",\n"
indent -= 1
result += indent_string * indent + '])'
else:
result += "%s(%r)" % (tag.__class__.__name__, tag.value)
return result