Skip to content

Commit f5fa1a4

Browse files
author
Ben Cipollini
committed
STY, DOC: linting, documentation.
1 parent 2ac9a9f commit f5fa1a4

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

nibabel/gifti/gifti.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class GiftiMetaData(xml.XmlSerializable):
2828
the list self.data """
2929
def __init__(self, nvpair=None):
3030
self.data = []
31-
if not nvpair is None:
31+
if nvpair is not None:
3232
self.data.append(nvpair)
3333

3434
@classmethod
@@ -295,7 +295,7 @@ def from_array(klass,
295295
cda.intent = intent_codes.code[intent]
296296
cda.encoding = gifti_encoding_codes.code[encoding]
297297
cda.endian = gifti_endian_codes.code[endian]
298-
if not coordsys is None:
298+
if coordsys is not None:
299299
cda.coordsys = coordsys
300300
cda.ind_ord = array_index_order_codes.code[ordering]
301301
cda.meta = GiftiMetaData.from_dict(meta)
@@ -370,7 +370,7 @@ def print_summary(self):
370370
print('Endian: ', gifti_endian_codes.specs[self.endian])
371371
print('ExternalFileName: ', self.ext_fname)
372372
print('ExternalFileOffset: ', self.ext_offset)
373-
if not self.coordsys is None:
373+
if self.coordsys is not None:
374374
print('----')
375375
print('Coordinate System:')
376376
print(self.coordsys.print_summary())

nibabel/gifti/parse_gifti_fast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,4 @@ def __init__(self, *args, **kwargs):
338338

339339
@np.deprecate_with_doc("Use GiftiImageParser.parse() instead.")
340340
def parse_gifti_file(fname=None, fptr=None, buffer_size=None):
341-
GiftiImageParser().parse(fname=fname, fptr=fptr, buffer_size=buffer_size)
341+
GiftiImageParser(buffer_size=buffer_size).parse(fname=fname, fptr=fptr)

nibabel/gifti/tests/test_parse_gifti_fast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ def test_parse_dataarrays():
317317
assert_equal(len(w), 1)
318318
assert_equal(img.numDA, 0)
319319

320-
def test_parse_deprecated():
321320

321+
def test_parse_deprecated():
322322

323323
# Test deprecation
324324
with clear_and_catch_warnings() as w:

nibabel/xmlbasedimages.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,33 @@ class XmlBasedHeader(FileBasedHeader, XmlSerializable):
3434

3535

3636
class XmlImageParser(object):
37-
""" Base class for defining how to parse xml-based images."""
37+
""" Base class for defining how to parse xml-based images.
38+
39+
Image-specific parsers should define:
40+
StartElementHandler
41+
EndElementHandler
42+
CharacterDataHandler
43+
"""
3844

3945
HANDLER_NAMES = ['StartElementHandler',
4046
'EndElementHandler',
4147
'CharacterDataHandler']
4248

4349
def __init__(self, encoding=None, buffer_size=35000000, verbose=0):
44-
self.encoding = encoding
50+
"""
51+
Parameters
52+
----------
53+
encoding : str
54+
string containing xml document
55+
56+
buffer_size: None or int, optional
57+
size of read buffer. None uses default buffer_size
58+
from xml.parsers.expat.
59+
60+
verbose : int, optional
61+
amount of output during parsing (0=silent, by default).
62+
"""
63+
self.encoding=encoding
4564
self.buffer_size = buffer_size
4665
self.verbose = verbose
4766
self.img = None
@@ -55,7 +74,7 @@ def _create_parser(self):
5574
parser.buffer_size = self.buffer_size
5675
return parser
5776

58-
def parse(self, string=None, fname=None, fptr=None, buffer_size=None):
77+
def parse(self, string=None, fname=None, fptr=None):
5978
"""
6079
Parameters
6180
----------
@@ -68,11 +87,6 @@ def parse(self, string=None, fname=None, fptr=None, buffer_size=None):
6887
fptr : file pointer
6988
open file pointer to an xml document
7089
71-
buffer_size: None or int, optional
72-
size of read buffer. None gives default of 35000000 unless on python <
73-
2.6, in which case it is read only in the parser. In that case values
74-
other than None cause a ValueError on execution
75-
7690
Returns
7791
-------
7892
img : XmlBasedImage
@@ -107,7 +121,16 @@ def CharacterDataHandler(self, data):
107121

108122

109123
class XmlBasedImage(FileBasedImage, XmlSerializable):
124+
"""Basic convenience wrapper around FileBasedImage and XmlSerializable.
125+
126+
Properties
127+
----------
128+
parser : XmlImageParser
129+
class name of the XML parser associated with this image type.
130+
"""
131+
110132
parser = XmlImageParser
133+
header = XmlBasedHeader
111134

112135
def to_file_map(self, file_map=None):
113136
""" Save the current image to the specified file_map

0 commit comments

Comments
 (0)