Skip to content

Commit

Permalink
Never return a non-existing pathname.
Browse files Browse the repository at this point in the history
Rewrote has_magic using a regular expression match.
  • Loading branch information
gvanrossum committed Jan 12, 1992
1 parent 05e5219 commit c2ef5c2
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Lib/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import os
import fnmatch
import regex


def glob(pathname):
if not has_magic(pathname): return [pathname]
if not has_magic(pathname):
if os.path.exists(pathname):
return [pathname]
else:
return []
dirname, basename = os.path.split(pathname)
if has_magic(dirname):
list = glob(dirname)
Expand Down Expand Up @@ -34,9 +39,13 @@ def glob1(dirname, pattern):
return []
result = []
for name in names:
if name[0] <> '.' or pattern[0] == '.':
if fnmatch.fnmatch(name, pattern): result.append(name)
if name[0] != '.' or pattern[0] == '.':
if fnmatch.fnmatch(name, pattern):
result.append(name)
return result


magic_check = regex.compile('[*?[]')

def has_magic(s):
return '*' in s or '?' in s or '[' in s
return magic_check.search(s) >= 0

0 comments on commit c2ef5c2

Please sign in to comment.