def unquoted(s):
    """ Given a string, return an unquoted string as per RFC 3501, section 9."""
    if isinstance(s, str):
        if (s[0], s[-1]) == ('"', '"'):
            return s[1:-1].replace('\\"', '"').replace('\\\\', '\\')
        return s
    else:
        if (s[0], s[-1]) == (b'"', b'"'):
            return s[1:-1].replace(b'\\"', '"').replace(b'\\\\', b'\\')
    return s