11
11
The Gifti specification was (at time of writing) available as a PDF download
12
12
from http://www.nitrc.org/projects/gifti/
13
13
"""
14
+ from __future__ import annotations
14
15
15
16
import base64
16
17
import sys
17
18
import warnings
19
+ from typing import Type
18
20
19
21
import numpy as np
20
22
@@ -577,7 +579,7 @@ class GiftiImage(xml.XmlSerializable, SerializableImage):
577
579
# The parser will in due course be a GiftiImageParser, but we can't set
578
580
# that now, because it would result in a circular import. We set it after
579
581
# the class has been defined, at the end of the class definition.
580
- parser = None
582
+ parser : Type [ xml . XmlParser ]
581
583
582
584
def __init__ (
583
585
self ,
@@ -832,17 +834,18 @@ def _to_xml_element(self):
832
834
GIFTI .append (dar ._to_xml_element ())
833
835
return GIFTI
834
836
835
- def to_xml (self , enc = 'utf-8' ):
837
+ def to_xml (self , enc = 'utf-8' ) -> bytes :
836
838
"""Return XML corresponding to image content"""
837
839
header = b"""<?xml version="1.0" encoding="UTF-8"?>
838
840
<!DOCTYPE GIFTI SYSTEM "http://www.nitrc.org/frs/download.php/115/gifti.dtd">
839
841
"""
840
842
return header + super ().to_xml (enc )
841
843
842
844
# Avoid the indirection of going through to_file_map
843
- to_bytes = to_xml
845
+ def to_bytes (self , enc = 'utf-8' ):
846
+ return self .to_xml (enc = enc )
844
847
845
- def to_file_map (self , file_map = None ):
848
+ def to_file_map (self , file_map = None , enc = 'utf-8' ):
846
849
"""Save the current image to the specified file_map
847
850
848
851
Parameters
@@ -858,7 +861,7 @@ def to_file_map(self, file_map=None):
858
861
if file_map is None :
859
862
file_map = self .file_map
860
863
with file_map ['image' ].get_prepare_fileobj ('wb' ) as f :
861
- f .write (self .to_xml ())
864
+ f .write (self .to_xml (enc = enc ))
862
865
863
866
@classmethod
864
867
def from_file_map (klass , file_map , buffer_size = 35000000 , mmap = True ):
0 commit comments