def non_printable_chars_to_hex(source):
    """
    Converts input string into hex for all non printable chars, printable chars remain unchanged.
    :param source: input string.
    :return: output string witch exchanged chars.
    """
    import string
    output = ''
    for char in source:
        if char not in string.printable or char in ['\n', '\r']:
            output += '\\x{:02x}'.format(ord(char))
        else:
            output += char
    return output
