Skip to content

Commit 7f965d7

Browse files
committed
BF+NF: fix missing import; raise specific errors
Raise a specific error when parsing a gifti file that does not conform to the gifti spec.
1 parent d05f135 commit 7f965d7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

nibabel/gifti/parse_gifti_fast.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import warnings
1414
import zlib
1515
from ..externals.six import StringIO
16+
from xml.parsers.expat import ExpatError
1617

1718
import numpy as np
1819

@@ -25,6 +26,10 @@
2526
from ..xmlutils import XmlParser
2627

2728

29+
class GiftiParseError(ExpatError):
30+
""" Gifti-specific parsing error """
31+
32+
2833
def read_data_block(encoding, endian, ordering, datatype, shape, data):
2934
""" Tries to unzip, decode, parse the funny string data """
3035
ord = array_index_order_codes.npcode[ordering]
@@ -130,12 +135,12 @@ def StartElementHandler(self, name, attrs):
130135

131136
elif name == 'Name':
132137
if self.nvpair is None:
133-
raise ExpatError
138+
raise GiftiParseError
134139
self.write_to = 'Name'
135140

136141
elif name == 'Value':
137142
if self.nvpair is None:
138-
raise ExpatError
143+
raise GiftiParseError
139144
self.write_to = 'Value'
140145

141146
elif name == 'LabelTable':
@@ -193,17 +198,17 @@ def StartElementHandler(self, name, attrs):
193198

194199
elif name == 'DataSpace':
195200
if self.coordsys is None:
196-
raise ExpatError
201+
raise GiftiParseError
197202
self.write_to = 'DataSpace'
198203

199204
elif name == 'TransformedSpace':
200205
if self.coordsys is None:
201-
raise ExpatError
206+
raise GiftiParseError
202207
self.write_to = 'TransformedSpace'
203208

204209
elif name == 'MatrixData':
205210
if self.coordsys is None:
206-
raise ExpatError
211+
raise GiftiParseError
207212
self.write_to = 'MatrixData'
208213

209214
elif name == 'Data':

0 commit comments

Comments
 (0)