create an NBTFormatError and raise it where appropriate instead of IOError

This commit is contained in:
David Vierra 2011-04-07 13:00:28 -10:00
parent 0136424d67
commit 111be952d4

6
nbt.py
View File

@ -28,6 +28,8 @@ from contextlib import closing
from numpy import array, zeros, uint8, fromstring
TAGfmt = ">b"
class NBTFormatError(RuntimeError): pass
class TAG_Value(object):
"""Simple values. Subclasses override fmt to change the type and size.
Subclasses may set dataType instead of overriding setValue for automatic data type coercion"""
@ -433,12 +435,12 @@ def load(filename="", buf=None):
data = buf;
#if buf != None: data = buf
if not len(buf):
raise IOError, "Asked to load root tag of zero length"
raise NBTFormatError, "Asked to load root tag of zero length"
data_cursor = 0;
tag_type = data[data_cursor];
if tag_type != 10:
raise IOError, 'Not an NBT file with a root TAG_Compound (found {0})'.format(tag_type);
raise NBTFormatError, 'Not an NBT file with a root TAG_Compound (found {0})'.format(tag_type);
data_cursor += 1;
data_cursor, tag = load_named(data, data_cursor, tag_type)