From d74bf073434ee558923824856cfad1a0c39bff8e Mon Sep 17 00:00:00 2001 From: David Vierra Date: Sun, 24 Jul 2011 00:21:44 -1000 Subject: [PATCH] TAG_Compound automatically wraps lists, tuples, and strings --- nbt.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nbt.py b/nbt.py index 50fd22e..0de2363 100644 --- a/nbt.py +++ b/nbt.py @@ -343,6 +343,13 @@ class TAG_Compound(TAG_Value, collections.MutableMapping): def __setitem__(self, k, v): + """Automatically wraps lists and tuples in a TAG_List, and wraps strings + and unicodes in a TAG_String.""" + if isinstance(v, (list, tuple)): + v = TAG_List(v) + elif isinstance(v, basestring): + v = TAG_String(v) + if not (v.__class__ in tag_handlers.values()): raise TypeError("Invalid type %s for TAG_Compound" % (v.__class__)) """remove any items already named "k". """ olditems = filter(lambda x:x.name == k, self.value)