|
14 | 14 | from pathlib import Path
|
15 | 15 | from typing import (
|
16 | 16 | Any,
|
| 17 | + Callable, |
17 | 18 | Dict,
|
18 | 19 | Iterator,
|
19 | 20 | Iterable,
|
|
28 | 29 | import numpy as np
|
29 | 30 | from PIL import Image
|
30 | 31 | from PIL.ImageCms import ImageCmsProfile, createProfile
|
| 32 | +from pydicom import config as pydicom_config |
31 | 33 | from pydicom.datadict import dictionary_VR, keyword_for_tag, tag_for_keyword
|
32 | 34 | from pydicom.dataset import Dataset, FileMetaDataset
|
33 | 35 | from pydicom.encaps import encapsulate, get_frame_offsets
|
|
66 | 68 | _END_MARKERS = {_JPEG_EOI_MARKER, _JPEG2000_EOC_MARKER}
|
67 | 69 |
|
68 | 70 |
|
| 71 | +def _enforce_standard_conformance(fn: Callable) -> Callable: |
| 72 | + """Enforce standard conformance during a function call. |
| 73 | +
|
| 74 | + Parameters |
| 75 | + ---------- |
| 76 | + fn: Callable |
| 77 | + Function that should be wrapped |
| 78 | +
|
| 79 | + Returns |
| 80 | + ------- |
| 81 | + Callable |
| 82 | + Wrapped function |
| 83 | +
|
| 84 | + """ |
| 85 | + def wrapper(*args, **kwargs): |
| 86 | + default_reading_mode = int( |
| 87 | + pydicom_config.settings.reading_validation_mode |
| 88 | + ) |
| 89 | + default_writing_mode = int( |
| 90 | + pydicom_config.settings.writing_validation_mode |
| 91 | + ) |
| 92 | + pydicom_config.settings.reading_validation_mode = pydicom_config.RAISE |
| 93 | + pydicom_config.settings.writing_validation_mode = pydicom_config.RAISE |
| 94 | + result = fn(*args, **kwargs) |
| 95 | + pydicom_config.settings.reading_validation_mode = default_reading_mode |
| 96 | + pydicom_config.settings.writing_validation_mode = default_writing_mode |
| 97 | + return result |
| 98 | + |
| 99 | + return wrapper |
| 100 | + |
| 101 | + |
69 | 102 | def _get_bot(fp: DicomFileLike, number_of_frames: int) -> List[int]:
|
70 | 103 | """Read or build the Basic Offset Table (BOT).
|
71 | 104 |
|
@@ -964,6 +997,7 @@ def _drop_db(self):
|
964 | 997 | cursor.execute('DROP TABLE IF EXISTS studies')
|
965 | 998 | cursor.close()
|
966 | 999 |
|
| 1000 | + @_enforce_standard_conformance |
967 | 1001 | def _update_db(self):
|
968 | 1002 | """Update database."""
|
969 | 1003 | all_attributes = (
|
|
0 commit comments