def to_u(val, encoding='utf-8'):
    if isinstance(val, text_type):
        return val
    elif isinstance(val, numeric_types):
        return text_type(val)

    return val.decode(encoding)
Note: This function is based on paramiko's exec_command()
dataset/ETHPy150Open ducksboard/libsaas/libsaas/port.py/to_u--crossover with--dataset/ETHPy150Open StackStorm/st2/st2actions/st2actions/runners/ssh/paramiko_ssh.py/ParamikoSSHClient.run