99from __future__ import division , print_function , absolute_import
1010
1111import sys
12- import xml .etree .ElementTree as xml
1312
1413import numpy as np
1514
15+ from .. import xmlutils as xml
1616from ..nifti1 import data_type_codes , xform_codes , intent_codes
1717from .util import (array_index_order_codes , gifti_encoding_codes ,
1818 gifti_endian_codes , KIND2FMT )
2323import base64
2424
2525
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 ):
3927 """ A list of GiftiNVPairs in stored in
4028 the list self.data """
4129 def __init__ (self , nvpair = None ):
@@ -87,7 +75,7 @@ def __init__(self, name='', value=''):
8775 self .value = value
8876
8977
90- class GiftiLabelTable (XmlSerializable ):
78+ class GiftiLabelTable (xml . XmlSerializable ):
9179
9280 def __init__ (self ):
9381 self .labels = []
@@ -113,7 +101,7 @@ def print_summary(self):
113101 print (self .get_labels_as_dict ())
114102
115103
116- class GiftiLabel (XmlSerializable ):
104+ class GiftiLabel (xml . XmlSerializable ):
117105 key = int
118106 label = str
119107 # rgba
@@ -166,7 +154,7 @@ def _arr2txt(arr, elem_fmt):
166154 return '\n ' .join (fmt % tuple (row ) for row in arr )
167155
168156
169- class GiftiCoordSystem (XmlSerializable ):
157+ class GiftiCoordSystem (xml . XmlSerializable ):
170158 dataspace = int
171159 xformspace = int
172160 xform = np .ndarray # 4x4 numpy array
@@ -199,7 +187,7 @@ def print_summary(self):
199187
200188def _data_tag_element (dataarray , encoding , datatype , ordering ):
201189 """ Creates the data tag depending on the required encoding,
202- returns as bytes """
190+ returns as XML element """
203191 import zlib
204192 ord = array_index_order_codes .npcode [ordering ]
205193 enclabel = gifti_encoding_codes .label [encoding ]
@@ -225,7 +213,7 @@ def data_tag(dataarray, encoding, datatype, ordering):
225213 return xml .tostring (data , 'utf-8' )
226214
227215
228- class GiftiDataArray (XmlSerializable ):
216+ class GiftiDataArray (xml . XmlSerializable ):
229217
230218 # These are for documentation only; we don't use these class variables
231219 intent = int
@@ -362,7 +350,7 @@ def metadata(self):
362350 return self .meta .metadata
363351
364352
365- class GiftiImage (XmlSerializable ):
353+ class GiftiImage (xml . XmlSerializable ):
366354
367355 def __init__ (self , meta = None , labeltable = None , darrays = None ,
368356 version = "1.0" ):
@@ -506,4 +494,4 @@ def to_xml(self, enc='utf-8'):
506494 """ Return XML corresponding to image content """
507495 return b"""<?xml version="1.0" encoding="UTF-8"?>
508496<!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