def _shell_wrap(command, shell_escape, shell=True, sudo_prefix=None):
    """
    Conditionally wrap given command in env.shell (while honoring sudo.)
    """
    # Honor env.shell, while allowing the 'shell' kwarg to override it (at
    # least in terms of turning it off.)
    if shell and not env.use_shell:
        shell = False
    # Sudo plus space, or empty string
    if sudo_prefix is None:
        sudo_prefix = ""
    else:
        sudo_prefix += " "
    # If we're shell wrapping, prefix shell and space. Next, escape the command
    # if requested, and then quote it. Otherwise, empty string.
    if shell:
        shell = env.shell + " "
        if shell_escape:
            command = _shell_escape(command)
        command = '"%s"' % command
    else:
        shell = ""
    # Resulting string should now have correct formatting
    return sudo_prefix + shell + command
dataset/ETHPy150Open fabric/fabric/fabric/operations.py/_shell_wrap/original