]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Never return a non-existing pathname.
authorGuido van Rossum <guido@python.org>
Sun, 12 Jan 1992 23:32:11 +0000 (23:32 +0000)
committerGuido van Rossum <guido@python.org>
Sun, 12 Jan 1992 23:32:11 +0000 (23:32 +0000)
Rewrote has_magic using a regular expression match.

Lib/glob.py

index 354af390a780ed961d70334b0f6b068816a9cd4c..bacaf183e1f6bd0fa681c292d9f21c0124f2a3aa 100644 (file)
@@ -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)
@@ -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