9
9
from __future__ import division , print_function , absolute_import
10
10
11
11
import sys
12
- import xml .etree .ElementTree as xml
13
12
14
13
import numpy as np
15
14
15
+ from .. import xmlutils as xml
16
16
from ..nifti1 import data_type_codes , xform_codes , intent_codes
17
17
from .util import (array_index_order_codes , gifti_encoding_codes ,
18
18
gifti_endian_codes , KIND2FMT )
23
23
import base64
24
24
25
25
26
- class XmlSerializable (object ):
27
- """ Basic interface for serializing an object to xml"""
28
- def _to_xml_element (self ):
29
- """ Output should be a xml.etree.ElementTree.Element"""
30
- raise NotImplementedError ()
31
-
32
- def to_xml (self , enc = 'utf-8' ):
33
- """ Output should be an xml string with the given encoding.
34
- (default: utf-8)"""
35
- return xml .tostring (self ._to_xml_element (), enc )
36
-
37
-
38
- class GiftiMetaData (XmlSerializable ):
26
+ class GiftiMetaData (xml .XmlSerializable ):
39
27
""" A list of GiftiNVPairs in stored in
40
28
the list self.data """
41
29
def __init__ (self , nvpair = None ):
@@ -87,7 +75,7 @@ def __init__(self, name='', value=''):
87
75
self .value = value
88
76
89
77
90
- class GiftiLabelTable (XmlSerializable ):
78
+ class GiftiLabelTable (xml . XmlSerializable ):
91
79
92
80
def __init__ (self ):
93
81
self .labels = []
@@ -113,7 +101,7 @@ def print_summary(self):
113
101
print (self .get_labels_as_dict ())
114
102
115
103
116
- class GiftiLabel (XmlSerializable ):
104
+ class GiftiLabel (xml . XmlSerializable ):
117
105
key = int
118
106
label = str
119
107
# rgba
@@ -166,7 +154,7 @@ def _arr2txt(arr, elem_fmt):
166
154
return '\n ' .join (fmt % tuple (row ) for row in arr )
167
155
168
156
169
- class GiftiCoordSystem (XmlSerializable ):
157
+ class GiftiCoordSystem (xml . XmlSerializable ):
170
158
dataspace = int
171
159
xformspace = int
172
160
xform = np .ndarray # 4x4 numpy array
@@ -199,7 +187,7 @@ def print_summary(self):
199
187
200
188
def _data_tag_element (dataarray , encoding , datatype , ordering ):
201
189
""" Creates the data tag depending on the required encoding,
202
- returns as bytes """
190
+ returns as XML element """
203
191
import zlib
204
192
ord = array_index_order_codes .npcode [ordering ]
205
193
enclabel = gifti_encoding_codes .label [encoding ]
@@ -225,7 +213,7 @@ def data_tag(dataarray, encoding, datatype, ordering):
225
213
return xml .tostring (data , 'utf-8' )
226
214
227
215
228
- class GiftiDataArray (XmlSerializable ):
216
+ class GiftiDataArray (xml . XmlSerializable ):
229
217
230
218
# These are for documentation only; we don't use these class variables
231
219
intent = int
@@ -362,7 +350,7 @@ def metadata(self):
362
350
return self .meta .metadata
363
351
364
352
365
- class GiftiImage (XmlSerializable ):
353
+ class GiftiImage (xml . XmlSerializable ):
366
354
367
355
def __init__ (self , meta = None , labeltable = None , darrays = None ,
368
356
version = "1.0" ):
@@ -506,4 +494,4 @@ def to_xml(self, enc='utf-8'):
506
494
""" Return XML corresponding to image content """
507
495
return b"""<?xml version="1.0" encoding="UTF-8"?>
508
496
<!DOCTYPE GIFTI SYSTEM "http://www.nitrc.org/frs/download.php/115/gifti.dtd">
509
- """ + XmlSerializable .to_xml (self , enc )
497
+ """ + xml . XmlSerializable .to_xml (self , enc )
0 commit comments