示例#1
0
def convert_single_string(
    byte_string: bytes,
    encodings: Optional[List[str]] = None,
    vr: str = None,
) -> str:
    """Return decoded text, ignoring backslashes and trailing spaces.

    Parameters
    ----------
    byte_string : bytes
        The encoded string.
    encodings : list of str, optional
        A list of the character encoding schemes used to encode the text.
    vr : str
        The value representation of the element. Needed for validation.

    Returns
    -------
    str
        The decoded text.
    """
    if vr is not None:
        validate_value(vr, byte_string,
                       config.settings.reading_validation_mode)
    encodings = encodings or [default_encoding]
    value = decode_bytes(byte_string, encodings, TEXT_VR_DELIMS)
    return value.rstrip('\0 ')
示例#2
0
    def __new__(cls: Type["UID"],
                val: str,
                validation_mode: int = None) -> "UID":
        """Setup new instance of the class.

        Parameters
        ----------
        val : str or pydicom.uid.UID
            The UID string to use to create the UID object.
        validation_mode : int
            Defines if values are validated and how validation errors are
            handled.

        Returns
        -------
        pydicom.uid.UID
            The UID object.
        """
        if isinstance(val, str):
            if validation_mode is None:
                validation_mode = config.settings.reading_validation_mode
            validate_value("UI", val, validation_mode)
            return super().__new__(cls, val.strip())

        raise TypeError("A UID must be created from a string")
示例#3
0
 def check_invalid_vr(vr, value, check_warn=True):
     msg = fr"Invalid value for VR {vr}: *"
     if check_warn:
         with pytest.warns(UserWarning, match=msg):
             DataElement(0x00410001, vr, value, validation_mode=config.WARN)
         with pytest.warns(UserWarning, match=msg):
             validate_value(vr, value, config.WARN)
     with pytest.raises(ValueError, match=msg):
         DataElement(0x00410001, vr, value, validation_mode=config.RAISE)
     with pytest.raises(ValueError, match=msg):
         validate_value(vr, value, config.RAISE)
示例#4
0
 def check_valid_vr(vr, value):
     DataElement(0x00410001, vr, value, validation_mode=config.RAISE)
     validate_value(vr, value, config.RAISE)
示例#5
0
 def validate(self, value: Any) -> None:
     """Validate the current value against the DICOM standard.
     See :func:`~pydicom.valuerep.validate_value` for details.
     """
     validate_value(self.VR, value, self.validation_mode)
示例#6
0
def _encode_and_validate_string(vr: str, value: str,
                                encodings: Sequence[str]) -> bytes:
    encoded = encode_string(value, encodings)
    validate_value(vr, encoded, config.settings.writing_validation_mode)
    return encoded