Example #1
0
def _decode_personname(components, encodings):
    """Return a list of decoded person name components.

    Parameters
    ----------
    components : list of byte string
        The list of the up to three encoded person name components
    encodings : list of str
        The Python encodings uses to decode `components`.

    Returns
    -------
    text type
        The unicode string representing the person name.
        If the decoding of some component parts is not possible using the
        given encodings, they are decoded with the first encoding using
        replacement characters for bytes that cannot be decoded.
    """
    from pydicom.charset import decode_string

    if isinstance(components[0], compat.text_type):
        comps = components
    else:
        comps = [
            decode_string(comp, encodings, PN_DELIMS) for comp in components
        ]
    # Remove empty elements from the end to avoid trailing '='
    while len(comps) and not comps[-1]:
        comps.pop()
    return tuple(comps)
Example #2
0
def convert_single_string(byte_string, encodings=None):
    """Read and return a single string
       (backslash character does not split)"""
    encodings = encodings or [default_encoding]
    value = decode_string(byte_string, encodings, TEXT_VR_DELIMS)
    if value and value.endswith(' '):
        value = value[:-1]
    return value
Example #3
0
def _decode_personname(components, encodings):
    """Return a list of decoded person name components."""
    from pydicom.charset import decode_string

    if isinstance(components[0], compat.text_type):
        comps = components
    else:
        comps = [decode_string(comp, encodings) for comp in components]
    # Remove empty elements from the end to avoid trailing '='
    while len(comps) and not comps[-1]:
        comps.pop()
    return comps
Example #4
0
def convert_single_string(byte_string, encodings=None):
    """Return decoded text, ignoring backslashes.

    Parameters
    ----------
    byte_string : bytes or str
        The encoded text.
    encodings : list of str, optional
        A list of the character encoding schemes used to encode the text.

    Returns
    -------
    str or list of str
        The decoded text.
    """
    encodings = encodings or [default_encoding]
    value = decode_string(byte_string, encodings, TEXT_VR_DELIMS)
    while value and (value.endswith(' ') or value.endswith('\0')):
        value = value[:-1]
    return value