<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def expand_paths(path):
 """When given a path with brackets, expands it to return all permutations of the path with expanded brackets, similar to ant. ['../a/c', '../a/d', '../b/c', '../b/d'] ['../a/a.py', '../a/b.py', '../b/a.py', '../b/b.py'] ['../a/a', '../a/b', '../a/c', '../b/a', '../b/b', '../b/c', '../c/a', '../c/b', '../c/c'] ['test'] """

    pr = itertools.product
    parts = MAGIC_BRACKETS.findall(path)

    if not path:
        return

    if not parts:
        return [path]

    permutations = [[(p[0], i, 1) for i in p[1].split(',')] for p in parts]
    return [_replace_all(path, i) for i in pr(*permutations)]