summaryrefslogtreecommitdiffstats
path: root/lib/jython/Lib/glob.py
diff options
context:
space:
mode:
authorjhugunin <jhugunin>2003-01-03 23:19:47 +0000
committerjhugunin <jhugunin>2003-01-03 23:19:47 +0000
commit8ec8f0c0c6c68d9b13c3bc3416c3234eddd48379 (patch)
tree8a2e07ba2a0048aae570053e019e02bd093f175f /lib/jython/Lib/glob.py
parentf685f979a4d3eb3844f74850deece1da265bc975 (diff)
downloadaspectj-8ec8f0c0c6c68d9b13c3bc3416c3234eddd48379.tar.gz
aspectj-8ec8f0c0c6c68d9b13c3bc3416c3234eddd48379.zip
making jython-2.1 available for scripting
Diffstat (limited to 'lib/jython/Lib/glob.py')
-rw-r--r--lib/jython/Lib/glob.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/jython/Lib/glob.py b/lib/jython/Lib/glob.py
new file mode 100644
index 000000000..3ddbd78c2
--- /dev/null
+++ b/lib/jython/Lib/glob.py
@@ -0,0 +1,57 @@
+"""Filename globbing utility."""
+
+import os
+import fnmatch
+import re
+
+__all__ = ["glob"]
+
+def glob(pathname):
+ """Return a list of paths matching a pathname pattern.
+
+ The pattern may contain simple shell-style wildcards a la fnmatch.
+
+ """
+ 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)
+ else:
+ list = [dirname]
+ if not has_magic(basename):
+ result = []
+ for dirname in list:
+ if basename or os.path.isdir(dirname):
+ name = os.path.join(dirname, basename)
+ if os.path.exists(name):
+ result.append(name)
+ else:
+ result = []
+ for dirname in list:
+ sublist = glob1(dirname, basename)
+ for name in sublist:
+ result.append(os.path.join(dirname, name))
+ return result
+
+def glob1(dirname, pattern):
+ if not dirname: dirname = os.curdir
+ try:
+ names = os.listdir(dirname)
+ except os.error:
+ return []
+ result = []
+ for name in names:
+ if name[0] != '.' or pattern[0] == '.':
+ if fnmatch.fnmatch(name, pattern):
+ result.append(name)
+ return result
+
+
+magic_check = re.compile('[*?[]')
+
+def has_magic(s):
+ return magic_check.search(s) is not None