1111The Gifti specification was (at time of writing) available as a PDF download
1212from http://www.nitrc.org/projects/gifti/
1313"""
14+ from __future__ import annotations
1415
1516import base64
1617import sys
1718import warnings
19+ from typing import Type
1820
1921import numpy as np
2022
@@ -577,7 +579,7 @@ class GiftiImage(xml.XmlSerializable, SerializableImage):
577579 # The parser will in due course be a GiftiImageParser, but we can't set
578580 # that now, because it would result in a circular import. We set it after
579581 # the class has been defined, at the end of the class definition.
580- parser = None
582+ parser : Type [ xml . XmlParser ]
581583
582584 def __init__ (
583585 self ,
@@ -832,17 +834,18 @@ def _to_xml_element(self):
832834 GIFTI .append (dar ._to_xml_element ())
833835 return GIFTI
834836
835- def to_xml (self , enc = 'utf-8' ):
837+ def to_xml (self , enc = 'utf-8' ) -> bytes :
836838 """Return XML corresponding to image content"""
837839 header = b"""<?xml version="1.0" encoding="UTF-8"?>
838840<!DOCTYPE GIFTI SYSTEM "http://www.nitrc.org/frs/download.php/115/gifti.dtd">
839841"""
840842 return header + super ().to_xml (enc )
841843
842844 # 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 )
844847
845- def to_file_map (self , file_map = None ):
848+ def to_file_map (self , file_map = None , enc = 'utf-8' ):
846849 """Save the current image to the specified file_map
847850
848851 Parameters
@@ -858,7 +861,7 @@ def to_file_map(self, file_map=None):
858861 if file_map is None :
859862 file_map = self .file_map
860863 with file_map ['image' ].get_prepare_fileobj ('wb' ) as f :
861- f .write (self .to_xml ())
864+ f .write (self .to_xml (enc = enc ))
862865
863866 @classmethod
864867 def from_file_map (klass , file_map , buffer_size = 35000000 , mmap = True ):
0 commit comments