def expand_braces(pattern):
    """Find the rightmost, innermost set of braces and, if it contains a
    comma-separated list, expand its contents recursively (any of its items
    may itself be a list enclosed in braces).

    Return the full list of expanded strings.
    """
    res = set()

    # Used instead of s.strip('{}') because strip is greedy.
    # We want to remove only ONE leading { and ONE trailing }, if both exist
    def remove_outer_braces(s):
        if s[0] == '{' and s[-1] == '}':
            return s[1:-1]
        return s

    match = EXPAND_BRACES_RE.search(pattern)
    if match is not None:
        sub = match.group(1)
        v1, v2 = match.span(1)
        if "," in sub:
            for pat in sub.strip('{}').split(','):
                subpattern = pattern[:v1] + pat + pattern[v2:]
                res.update(expand_braces(subpattern))
        else:
            subpattern = pattern[:v1] + remove_outer_braces(sub) + pattern[v2:]
            res.update(expand_braces(subpattern))
    else:
        res.add(pattern.replace('\\}', '}'))

    return list(res)
Find the rightmost, innermost set of braces and, if it contains a
    comma-separated list, expand its contents recursively (any of its items
    may itself be a list enclosed in braces).

    Return the full list of expanded strings.
    
graphite_api/finders/__init__.py