'takes a remote path and performs tilde expansion on the remote host'

def _remote_expand_user(self, path, sudoable=True):

    if (not path.startswith('~')):
        return path
    split_path = path.split(os.path.sep, 1)
    expand_path = split_path[0]
    if (sudoable and (expand_path == '~') and self._play_context.become and self._play_context.become_user):
        expand_path = ('~%s' % self._play_context.become_user)
    cmd = self._connection._shell.expand_user(expand_path)
    data = self._low_level_execute_command(cmd, sudoable=False)
    try:
        initial_fragment = data['stdout'].strip().splitlines()[(-1)]
    except IndexError:
        initial_fragment = None
    if (not initial_fragment):
        return path
    if (len(split_path) > 1):
        return self._connection._shell.join_path(initial_fragment, *split_path[1:])
    else:
        return initial_fragment
