@@ -555,6 +555,8 @@ class Nifti1DicomExtension(Nifti1Extension[DicomDataset]):
555555 """
556556
557557 code = 2
558+ _is_implict_VR : bool = False
559+ _is_little_endian : bool = True
558560
559561 def __init__ (
560562 self ,
@@ -586,27 +588,25 @@ def __init__(
586588 code should always be 2 for DICOM.
587589 """
588590
589- self ._is_little_endian = parent_hdr is None or parent_hdr .endianness == '<'
591+ if code != 2 :
592+ raise ValueError (f'code must be 2 for DICOM. Got { code } .' )
593+
594+ if content is None :
595+ content = pdcm .Dataset ()
596+
597+ if parent_hdr is not None :
598+ self ._is_little_endian = parent_hdr .endianness == '<'
590599
591- bytes_content : bytes
592600 if isinstance (content , pdcm .dataset .Dataset ):
593- self ._is_implicit_VR = False
594- self ._object = content
595- bytes_content = self ._mangle (content )
601+ super ().__init__ (code , object = content )
596602 elif isinstance (content , bytes ): # Got a byte string - unmangle it
597603 self ._is_implicit_VR = self ._guess_implicit_VR (content )
598- self ._object = self ._unmangle (content )
599- bytes_content = content
600- elif content is None : # initialize a new dicom dataset
601- self ._is_implicit_VR = False
602- self ._object = pdcm .dataset .Dataset ()
603- bytes_content = self ._mangle (self ._object )
604+ super ().__init__ (code , content = content )
604605 else :
605606 raise TypeError (
606607 f'content must be either a bytestring or a pydicom Dataset. '
607608 f'Got { content .__class__ } '
608609 )
609- super ().__init__ (code , bytes_content )
610610
611611 @staticmethod
612612 def _guess_implicit_VR (content ) -> bool :
0 commit comments