Quotes a string if it is not already quoted

def shell_quote(s):
    'Quotes a string if it is not already quoted'
    return s if isinstance(s, ShellQuoted) \
        else ShellQuoted("'" + str(s).replace("'", "'\\''") + "'")