Kaydet (Commit) c2ef5c2d authored tarafından Guido van Rossum's avatar Guido van Rossum

Never return a non-existing pathname.

Rewrote has_magic using a regular expression match.
üst 05e5219f
...@@ -2,10 +2,15 @@ ...@@ -2,10 +2,15 @@
import os import os
import fnmatch import fnmatch
import regex
def glob(pathname): 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) dirname, basename = os.path.split(pathname)
if has_magic(dirname): if has_magic(dirname):
list = glob(dirname) list = glob(dirname)
...@@ -34,9 +39,13 @@ def glob1(dirname, pattern): ...@@ -34,9 +39,13 @@ def glob1(dirname, pattern):
return [] return []
result = [] result = []
for name in names: for name in names:
if name[0] <> '.' or pattern[0] == '.': if name[0] != '.' or pattern[0] == '.':
if fnmatch.fnmatch(name, pattern): result.append(name) if fnmatch.fnmatch(name, pattern):
result.append(name)
return result return result
magic_check = regex.compile('[*?[]')
def has_magic(s): def has_magic(s):
return '*' in s or '?' in s or '[' in s return magic_check.search(s) >= 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment