def Glob2Regex(glob_pattern):
if not glob_pattern:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>regex_pattern = []<EOL>glob_pattern_index = <NUM_LIT:0><EOL>glob_pattern_length = len(glob_pattern)<EOL>while glob_pattern_index < glob_pattern_length:<EOL><INDENT>character = glob_pattern[glob_pattern_index]<EOL>glob_pattern_index += <NUM_LIT:1><EOL>if character == '<STR_LIT:*>':<EOL><INDENT>regex_pattern.append('<STR_LIT>')<EOL><DEDENT>elif character == '<STR_LIT:?>':<EOL><INDENT>regex_pattern.append('<STR_LIT:.>')<EOL><DEDENT>elif character != '<STR_LIT:[>':<EOL><INDENT>regex_character = re.escape(character)<EOL>regex_pattern.append(regex_character)<EOL><DEDENT>else:<EOL><INDENT>glob_group_index = glob_pattern_index<EOL>if (glob_group_index < glob_pattern_length and<EOL>glob_pattern[glob_group_index] == '<STR_LIT:!>'):<EOL><INDENT>glob_group_index += <NUM_LIT:1><EOL><DEDENT>if (glob_group_index < glob_pattern_length and<EOL>glob_pattern[glob_group_index] == '<STR_LIT:]>'):<EOL><INDENT>glob_group_index += <NUM_LIT:1><EOL><DEDENT>while (glob_group_index < glob_pattern_length and<EOL>glob_pattern[glob_group_index] != '<STR_LIT:]>'):<EOL><INDENT>glob_group_index += <NUM_LIT:1><EOL><DEDENT>if glob_group_index >= glob_pattern_length:<EOL><INDENT>regex_pattern.append('<STR_LIT>')<EOL>continue<EOL><DEDENT>glob_group = glob_pattern[glob_pattern_index:glob_group_index]<EOL>glob_pattern_index = glob_group_index + <NUM_LIT:1><EOL>glob_group = glob_group.replace('<STR_LIT:\\>', '<STR_LIT>')<EOL>if py2to3.PY_3_7_AND_LATER:<EOL><INDENT>glob_group = glob_group.replace('<STR_LIT:|>', '<STR_LIT>')<EOL><DEDENT>regex_pattern.append('<STR_LIT:[>')<EOL>if glob_group[<NUM_LIT:0>] == '<STR_LIT:!>':<EOL><INDENT>regex_pattern.append('<STR_LIT>')<EOL>glob_group = glob_group[<NUM_LIT:1>:]<EOL><DEDENT>elif glob_group[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>regex_pattern.append('<STR_LIT:\\>')<EOL><DEDENT>regex_pattern.append(glob_group)<EOL>regex_pattern.append('<STR_LIT:]>')<EOL><DEDENT><DEDENT>return '<STR_LIT>'.join(regex_pattern)<EOL>
Converts a glob pattern to a regular expression.

    This function supports basic glob patterns that consist of:
    *       matches everything
    ?       matches any single character
    [seq]   matches any character in sequence
    [!seq]  matches any character not in sequence

    Args:
      glob_pattern (str): glob pattern.

    Returns:
      str: regular expression pattern.

    Raises:
      ValueError: if the glob pattern cannot be converted.