create an NBTFormatError and raise it where appropriate instead of IOError
This commit is contained in:
parent
0136424d67
commit
111be952d4
6
nbt.py
6
nbt.py
@ -28,6 +28,8 @@ from contextlib import closing
|
|||||||
from numpy import array, zeros, uint8, fromstring
|
from numpy import array, zeros, uint8, fromstring
|
||||||
TAGfmt = ">b"
|
TAGfmt = ">b"
|
||||||
|
|
||||||
|
class NBTFormatError(RuntimeError): pass
|
||||||
|
|
||||||
class TAG_Value(object):
|
class TAG_Value(object):
|
||||||
"""Simple values. Subclasses override fmt to change the type and size.
|
"""Simple values. Subclasses override fmt to change the type and size.
|
||||||
Subclasses may set dataType instead of overriding setValue for automatic data type coercion"""
|
Subclasses may set dataType instead of overriding setValue for automatic data type coercion"""
|
||||||
@ -433,12 +435,12 @@ def load(filename="", buf=None):
|
|||||||
data = buf;
|
data = buf;
|
||||||
#if buf != None: data = buf
|
#if buf != None: data = buf
|
||||||
if not len(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;
|
data_cursor = 0;
|
||||||
tag_type = data[data_cursor];
|
tag_type = data[data_cursor];
|
||||||
if tag_type != 10:
|
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 += 1;
|
||||||
|
|
||||||
data_cursor, tag = load_named(data, data_cursor, tag_type)
|
data_cursor, tag = load_named(data, data_cursor, tag_type)
|
||||||
|
Reference in New Issue
Block a user