def unquote(s):
    """Remove any enclosing quotes for S."""
    if isinstance(s, str) and len(s) > 1:
        if s[0] in ('"', "'") and s[-1] == s[0]:
            q = s[0]
            if len(s) >= 6 and s[0:3].count(q) == 3 and s[-3:].count(q) == 3:
                count = 3
            else:
                count = 1
            s = s[count:-count]
    return s
