def method_glob(self, space, w_pattern, flags=0, block=None): if space.is_kind_of(w_pattern, space.w_array): patterns_w = space.listview(w_pattern) else: patterns_w = [w_pattern] glob = Glob(space.fromcache(RegexpCache)) for w_pat in patterns_w: w_pat2 = space.convert_type(w_pat, space.w_string, "to_path", raise_error=False) if w_pat2 is space.w_nil: pattern = space.convert_type(w_pat, space.w_string, "to_str") pattern = space.str_w(w_pat2) if len(patterns_w) == 1: for pat in pattern.split("\0"): glob.glob(pat, flags) else: glob.glob(pattern.split("\0")[0], flags) if block: for match in glob.matches(): space.invoke_block(block, [space.newstr_fromstr(match)]) return space.w_nil else: return space.newarray([space.newstr_fromstr(s) for s in glob.matches()])
def method_glob(self, space, w_pattern, flags=0, block=None): if space.is_kind_of(w_pattern, space.w_array): patterns_w = space.listview(w_pattern) else: patterns_w = [w_pattern] glob = Glob(space.fromcache(RegexpCache)) for w_pat in patterns_w: if space.is_kind_of(w_pat, space.w_string): pattern = space.str_w(w_pat) else: pattern = space.str_w(space.convert_type(w_pat, space.w_string, "to_str")) if len(patterns_w) == 1: for pat in pattern.split("\0"): glob.glob(pat, flags) else: glob.glob(pattern, flags) if block: for match in glob.matches(): space.invoke_block(block, [space.newstr_fromstr(match)]) return space.w_nil else: return space.newarray([space.newstr_fromstr(s) for s in glob.matches()])
def glob(self, pattern, flags=0): glob = Glob(self.space.fromcache(RegexpCache)) glob.glob(pattern, flags) return glob.matches()