Skip to content

Commit 7dcf585

Browse files
authored
Fix missing public transfer syntaxes (#1047)
1 parent e5cc3f8 commit 7dcf585

3 files changed

Lines changed: 35 additions & 23 deletions

File tree

pynetdicom/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22

33
import logging
44

5+
from pydicom._uid_dict import UID_dictionary
56
from pydicom.uid import UID
67

78
from ._version import __version__
89

910

11+
# fmt: off
12+
# Update pydicom's UID dictionary with any missing transfer syntaxes
13+
UID_dictionary.update(
14+
{
15+
'1.2.840.10008.1.2.4.110': ('JPEG XL Lossless', 'Transfer Syntax', '', '', 'JPEGXLLossless'),
16+
'1.2.840.10008.1.2.4.111': ('JPEG XL JPEG Recompression', 'Transfer Syntax', '', '', 'JPEGXLJPEGRecompression'),
17+
'1.2.840.10008.1.2.4.112': ('JPEG XL', 'Transfer Syntax', '', '', 'JPEGXL'),
18+
'1.2.840.10008.1.2.8.1': ('Deflated Image Frame Compression', 'Transfer Syntax', '', '', 'DeflatedImageFrameCompression'),
19+
}
20+
)
21+
# fmt: on
22+
1023
_version = __version__.split(".")[:3]
1124

1225
# UID prefix provided by https://www.medicalconnections.co.uk/Free_UID

pynetdicom/presentation.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,7 @@ class PresentationContextTuple(NamedTuple):
119119
(False, True): CONTEXT_REJECTED, # Invalid
120120
},
121121
}
122-
# Transfer Syntaxes not in pydicom v2.4
123-
_PYDICOM_ADDITIONS = [
124-
"1.2.840.10008.1.2.4.201", # HTJ2KLossless
125-
"1.2.840.10008.1.2.4.202", # HTJ2KLosslessRPCL
126-
"1.2.840.10008.1.2.4.203", # HTJ2K
127-
"1.2.840.10008.1.2.4.204", # JPIPHTJ2KReferenced
128-
"1.2.840.10008.1.2.4.205", # JPIPHTJ2KReferencedDeflate
129-
]
122+
130123

131124
class PresentationContext:
132125
"""A Presentation Context primitive.
@@ -269,24 +262,17 @@ def add_transfer_syntax(self, syntax: None | str | bytes | UID) -> None:
269262
LOGGER.error("'transfer_syntax' contains an invalid UID")
270263
raise ValueError("'transfer_syntax' contains an invalid UID")
271264

272-
if syntax and not syntax.is_valid:
273-
LOGGER.warning(f"The Transfer Syntax Name '{syntax}' is non-conformant")
274-
275-
# If the transfer syntax is rejected we may add an empty str
265+
# If the transfer syntax is rejected we may receive an empty str
276266
if syntax not in self._transfer_syntax and syntax != "":
277267
if not syntax.is_valid:
278268
LOGGER.warning(
279-
"A non-conformant UID has been added to 'transfer_syntax'"
269+
f"A non-conformant UID has been added to 'transfer_syntax': '{syntax}'"
280270
)
281271

282-
if (
283-
not syntax.is_private
284-
and not syntax.is_transfer_syntax
285-
and syntax not in _PYDICOM_ADDITIONS
286-
):
272+
if not syntax.is_private and not syntax.is_transfer_syntax:
287273
LOGGER.warning(
288-
"A UID has been added to 'transfer_syntax' that is not a "
289-
f"transfer syntax: '{syntax}'"
274+
"A UID has been added to 'transfer_syntax' that is not a known "
275+
f"public transfer syntax: '{syntax}'"
290276
)
291277

292278
self._transfer_syntax.append(syntax)

pynetdicom/tests/test_presentation.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pydicom.uid import UID
1111

1212
from pynetdicom import AE, _config
13-
from pynetdicom._globals import DEFAULT_TRANSFER_SYNTAXES
13+
from pynetdicom._globals import DEFAULT_TRANSFER_SYNTAXES, ALL_TRANSFER_SYNTAXES
1414
from pynetdicom.pdu_primitives import SCP_SCU_RoleSelectionNegotiation
1515
from pynetdicom.presentation import (
1616
build_context,
@@ -126,7 +126,7 @@ def test_add_transfer_syntax_nonconformant(self, caplog):
126126

127127
pc.add_transfer_syntax("1.2.840.10008.1.1")
128128
assert (
129-
"A UID has been added to 'transfer_syntax' that is not a "
129+
"A UID has been added to 'transfer_syntax' that is not a known public "
130130
"transfer syntax" in caplog.text
131131
)
132132

@@ -295,11 +295,12 @@ def test_abstract_syntax_nonconformant(self, caplog):
295295
msg = "Invalid 'abstract_syntax' value '1.4.1.' - UID is non-conformant"
296296
with pytest.raises(ValueError, match=msg):
297297
pc.abstract_syntax = UID("1.4.1.")
298+
298299
assert pc.abstract_syntax is None
299300

300301
_config.ENFORCE_UID_CONFORMANCE = False
301-
pc.abstract_syntax = UID("1.4.1.")
302302

303+
pc.abstract_syntax = UID("1.4.1.")
303304
assert pc.abstract_syntax == UID("1.4.1.")
304305
assert isinstance(pc.abstract_syntax, UID)
305306

@@ -433,6 +434,18 @@ def test_repr(self):
433434
cx = build_context("1.2.840.10008.1.1")
434435
assert "Verification SOP Class" == repr(cx)
435436

437+
def test_transfer_syntaxes_dont_warn(self, caplog):
438+
"""Test that all transfer syntaxes are known to pydicom"""
439+
caplog.set_level(logging.WARNING, logger="pynetdicom.presentation")
440+
for ts in ALL_TRANSFER_SYNTAXES:
441+
cx = build_context("1.2.3", ts)
442+
443+
for ts in DEFAULT_TRANSFER_SYNTAXES:
444+
cx = build_context("1.2.3", ts)
445+
446+
assert caplog.text == ""
447+
448+
436449

437450
class TestNegotiateAsAcceptor:
438451
"""Tests negotiation_as_acceptor."""

0 commit comments

Comments
 (0)