Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testLimits(self):
"""MultiValue: Raise error if any item outside DICOM limits...."""
original_flag = config.enforce_valid_values
config.enforce_valid_values = True
self.assertRaises(OverflowError, MultiValue, IS, [1, -2 ** 31 - 1]) # Overflow error not raised for IS out of DICOM valid range
config.enforce_valid_values = original_flag
def tearDown(self):
config.enforce_valid_values = False
def setUp(self):
self.jpeg_lossy = read_file(jpeg_lossy_name)
self.color_3d_jpeg = read_file(color_3d_jpeg_baseline)
self.original_handlers = pydicom.config.image_handlers
pydicom.config.image_handlers = [gdcm_handler]
def setUp(self):
config.datetime_conversion = True
def setUp(self):
# Set up a dataset with commas in one item instead of backslash
config.enforce_valid_values = True
namespace = {}
exec(raw_hex_code, {}, namespace)
ds_bytes = hexutil.hex2bytes(namespace['impl_LE_deflen_std_hex'])
# Change "2\4\8\16" to "2,4,8,16"
ds_bytes = ds_bytes.replace(b"\x32\x5c\x34\x5c\x38\x5c\x31\x36",
b"\x32\x2c\x34\x2c\x38\x2c\x31\x36")
self.bytesio = BytesIO(ds_bytes)
def setUp(self):
config.DS_decimal(True)
byte_string : bytes or str
The encoded 'TM' element value.
is_little_endian : bool
``True`` if the value is encoded as little endian, ``False`` otherwise.
struct_format : str, optional
Not used.
Returns
-------
str or list of str or valuerep.TM or list of valuerep.TM
If
:attr:`~pydicom.config.datetime_conversion` is ``True`` then returns
either :class:`~pydicom.valuerep.TM` or a :class:`list` of ``TM``,
otherwise returns :class:`str` or ``list`` of ``str``.
"""
if config.datetime_conversion:
if not in_py2:
byte_string = byte_string.decode(default_encoding)
splitup = byte_string.split("\\")
if len(splitup) == 1:
return _TM_from_byte_string(splitup[0])
else:
return MultiValue(_TM_from_byte_string, splitup)
else:
return convert_string(byte_string, is_little_endian, struct_format)
endian_chr = "<"
else:
endian_chr = ">"
if is_implicit_VR:
element_struct = Struct(endian_chr + "HHL")
else: # Explicit VR
# tag, VR, 2-byte length (or 0 if special VRs)
element_struct = Struct(endian_chr + "HH2sH")
extra_length_struct = Struct(endian_chr + "L") # for special VRs
extra_length_unpack = extra_length_struct.unpack # for lookup speed
# Make local variables so have faster lookup
fp_read = fp.read
fp_tell = fp.tell
logger_debug = logger.debug
debugging = config.debugging
element_struct_unpack = element_struct.unpack
defer_size = size_in_bytes(defer_size)
tag_set = set()
if specific_tags is not None:
for tag in specific_tags:
if isinstance(tag, (str, compat.text_type)):
tag = Tag(tag_for_keyword(tag))
if isinstance(tag, BaseTag):
tag_set.add(tag)
tag_set.add(Tag(0x08, 0x05))
has_tag_set = len(tag_set) > 0
while True:
# Read tag, VR, length, get ready to read value
bytes_read = fp_read(8)
Parameters
----------
VR : str
The VR of the corresponding element.
raw : bool
If ``True``, returns the value for a :class:`RawDataElement`,
otherwise for a :class:`DataElement`
Returns
-------
str or bytes or None
The value a data element with `VR` is assigned on decoding
if it is empty.
"""
if config.use_none_as_empty_text_VR_value:
return None
if VR in ('AE', 'AS', 'CS', 'DA', 'DT', 'LO', 'LT',
'PN', 'SH', 'ST', 'TM', 'UC', 'UI', 'UR', 'UT'):
return b'' if raw else ''
return None
Returns
-------
DataElement
"""
# XXX buried here to avoid circular import
# filereader->Dataset->convert_value->filereader
# (for SQ parsing)
if in_py2:
encoding = encoding or default_encoding
from pydicom.values import convert_value
raw = raw_data_element
# If user has hooked into conversion of raw values, call his/her routine
if config.data_element_callback:
data_elem = config.data_element_callback
raw = data_elem(raw_data_element,
**config.data_element_callback_kwargs)
VR = raw.VR
if VR is None: # Can be if was implicit VR
try:
VR = dictionary_VR(raw.tag)
except KeyError:
# just read the bytes, no way to know what they mean
if raw.tag.is_private:
# for VR for private tags see PS3.5, 6.2.2
if raw.tag.is_private_creator:
VR = 'LO'
else:
VR = 'UN'
# group length tag implied in versions < 3.0