Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

NBT: TAG_List now accepts item assignment using slices.

e.g. `list_tag[:] = [nbt.TAG_Double(3), nbt.TAG_Double(5)]`

Also, changed the names of a few method args to be more consistent between implementations.
  • Loading branch information...
commit 3e4a9b8ef6e7210dc66d6e12df68abc158e1e02b 1 parent 30cfb1d
David Vierra codewarrior0 authored
Showing with 25 additions and 17 deletions.
  1. +13 −9 _nbt.pyx
  2. +12 −8 nbt.py
22 _nbt.pyx
View
@@ -273,12 +273,16 @@ cdef class _TAG_List(TAG_Value):
raise TypeError("Invalid type %s for TAG_List(%s)" % (value.__class__, tag_classes[self.list_type]))
# --- collection methods ---
- def __getitem__(self, key):
- return self.value[key]
+ def __getitem__(self, index):
+ return self.value[index]
- def __setitem__(self, key, val):
- self.check_tag(val)
- self.value[key] = val
+ def __setitem__(self, index, value):
+ if isinstance(index, slice):
+ for tag in value:
+ self.check_tag(tag)
+ else:
+ self.check_tag(value)
+ self.value[index] = value
def __iter__(self):
return iter(self.value)
@@ -286,13 +290,13 @@ cdef class _TAG_List(TAG_Value):
def __len__(self):
return len(self.value)
- def insert(self, idx, val):
+ def insert(self, index, tag):
if len(self.value) == 0:
- self.list_type = val.tagID
+ self.list_type = tag.tagID
else:
- self.check_tag(val)
+ self.check_tag(tag)
- self.value.insert(idx, val)
+ self.value.insert(index, tag)
def __delitem__(self, key):
del self.value[key]
20 nbt.py
View
@@ -456,22 +456,26 @@ def check_tag(self, value):
def __iter__(self):
return iter(self.value)
- def __contains__(self, key):
- return key in self.value
+ def __contains__(self, tag):
+ return tag in self.value
- def __getitem__(self, i):
- return self.value[i]
+ def __getitem__(self, index):
+ return self.value[index]
def __len__(self):
return len(self.value)
def __setitem__(self, index, value):
- self.check_tag(value)
- value.name = ""
+ if isinstance(index, slice):
+ for tag in value:
+ self.check_tag(tag)
+ else:
+ self.check_tag(value)
+
self.value[index] = value
- def __delitem__(self, i):
- del self.value[i]
+ def __delitem__(self, index):
+ del self.value[index]
def insert(self, index, value):
if len(self) == 0:
Please sign in to comment.
Something went wrong with that request. Please try again.