From aefbb723553a67cdd223594dae0dc4f666defb40 Mon Sep 17 00:00:00 2001 From: Kai Schlamp Date: Tue, 15 Oct 2024 19:20:35 +0000 Subject: [PATCH] Use set_original_encoding --- pynetdicom/dsutils.py | 5 +++-- pynetdicom/events.py | 2 ++ pynetdicom/tests/test_assoc.py | 21 ++++++--------------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/pynetdicom/dsutils.py b/pynetdicom/dsutils.py index e19b03256..6b630b87b 100644 --- a/pynetdicom/dsutils.py +++ b/pynetdicom/dsutils.py @@ -61,6 +61,9 @@ def create_file_meta( file_meta.ImplementationClassUID = implementation_uid file_meta.ImplementationVersionName = implementation_version + # File Meta Information is always encoded as Explicit VR Little Endian + file_meta.set_original_encoding(False, True) + return file_meta @@ -264,8 +267,6 @@ def pretty_element(elem: DataElement) -> str: value = "\\".join([str(ii) for ii in elem.value]) value = f"[{value}]" elif elem.VR == "SQ": - # Sequence elements always have a VM of 1 - assert elem.VM == 1 length = len(elem.value) if length == 1: value = f"(Sequence with {length} item)" diff --git a/pynetdicom/events.py b/pynetdicom/events.py index 4832c7a95..2cc26af63 100644 --- a/pynetdicom/events.py +++ b/pynetdicom/events.py @@ -868,6 +868,8 @@ def _get_dataset(self, attr: str, exc_msg: str) -> Dataset: t_syntax.is_deflated, ) + ds.set_original_encoding(t_syntax.is_implicit_VR, t_syntax.is_little_endian) + # Store the decoded dataset in case its accessed again self._decoded = ds else: diff --git a/pynetdicom/tests/test_assoc.py b/pynetdicom/tests/test_assoc.py index acd8e78c3..b9c797e6f 100644 --- a/pynetdicom/tests/test_assoc.py +++ b/pynetdicom/tests/test_assoc.py @@ -1879,23 +1879,16 @@ def handle_store(event): assoc = ae.associate("localhost", 11112) assert assoc.is_established - ds = Dataset() - ds.SOPClassUID = CTImageStorage - ds.SOPInstanceUID = generate_uid() - file_meta = FileMetaDataset() - file_meta.TransferSyntaxUID = ExplicitVRLittleEndian - ds.file_meta = file_meta + ds = dcmread(DATASET_PATH) + assert ds.original_encoding == (False, True) + assert ds.file_meta.TransferSyntaxUID == ExplicitVRLittleEndian with caplog.at_level(logging.WARNING, logger="pynetdicom"): - with pytest.warns(DeprecationWarning): - ds.is_implicit_VR = True - ds.is_little_endian = True + ds.set_original_encoding(True, True) status = assoc.send_c_store(ds) assert status.Status == 0x0000 - with pytest.warns(DeprecationWarning): - ds.is_implicit_VR = False - ds.is_little_endian = False + ds.set_original_encoding(False, False) status = assoc.send_c_store(ds) assert status.Status == 0x0000 @@ -1910,9 +1903,7 @@ def handle_store(event): "Little Endian' - using 'Explicit VR Big Endian' instead" ) in caplog.text - with pytest.warns(DeprecationWarning): - ds.is_implicit_VR = False - ds.is_little_endian = True + ds.set_original_encoding(False, True) ds.file_meta.TransferSyntaxUID = ImplicitVRLittleEndian msg = ( "'dataset' is encoded as explicit VR little endian but the file "