'Converts a glob pattern into a list of components.
Wildcards are also converted to regular expressions. The
components do not span directories, and are marked as a regex or a
literal component.
We also support recursion into directories using the ** notation.  For
example, /home/**2/foo.txt will find all files named foo.txt recursed 2
directories deep. If the directory depth is omitted, it defaults to 3.
Example:
/home/**/*.exe -> [{type: "LITERAL", path: "home"},
{type: "RECURSIVE"},
{type: "REGEX", path: ".*\\.exe\\Z(?ms)"}]]
Args:
pattern: A glob expression with wildcards.
Returns:
A list of Components.
Raises:
ValueError: If the glob is invalid.'

def _ConvertGlobIntoPathComponents(self, pattern):

    components = []
    recursion_count = 0
    for path_component in pattern.split(os.path.sep):
        if (not path_component):
            continue
        m = self.RECURSION_REGEX.search(path_component)
        if m:
            recursion_count += 1
            if (recursion_count > 1):
                raise ValueError('Pattern    cannot    have    more    than    one    recursion.')
            if (m.group(0) != path_component):
                raise ValueError("Can't    have    combined    recursive    search    and    regex.")
            depth = 3
            if m.group(1):
                depth = int(m.group(1))
            component = RecursiveComponent(depth=depth, follow_links=self.follow_links, mountpoints_blacklist=self.mountpoints_blacklist)
        elif self.GLOB_MAGIC_CHECK.search(path_component):
            component = RegexComponent(fnmatch.translate(path_component))
        else:
            component = LiteralComponent(path_component)
        components.append(component)
    return components
