--- /dev/null
+import fnmatch
+import os
+
+_debug = 0
+
+_prune = ['(*)']
+
+def find(pattern, dir = os.curdir):
+ list = []
+ names = os.listdir(dir)
+ names.sort()
+ for name in names:
+ if name in (os.curdir, os.pardir):
+ continue
+ fullname = os.path.join(dir, name)
+ if fnmatch.fnmatch(name, pattern):
+ list.append(fullname)
+ if os.path.isdir(fullname) and not os.path.islink(fullname):
+ for p in _prune:
+ if fnmatch.fnmatch(name, p):
+ if _debug: print "skip", `fullname`
+ break
+ else:
+ if _debug: print "descend into", `fullname`
+ list = list + find(pattern, fullname)
+ return list
-# module 'fnmatch' -- filename matching with shell patterns
-# This version translates the pattern to a regular expression
-# and moreover caches the expressions.
+"""Filename matching with shell patterns.
-import os
-import regex
+fnmatch(FILENAME, PATTERN) matches according to the local convention.
+fnmatchcase(FILENAME, PATTERN) always takes case in account.
-cache = {}
+The functions operate by translating the pattern into a regular
+expression. They cache the compiled regular expressions for speed.
+
+The function translate(PATTERN) returns a regular expression
+corresponding to PATTERN. (It does not compile it.)
+"""
+
+_cache = {}
def fnmatch(name, pat):
+ """Test whether FILENAME matches PATTERN.
+
+ Patterns are Unix shell style:
+
+ * matches everything
+ ? matches any single character
+ [seq] matches any character in seq
+ [!seq] matches any char not in seq
+
+ An initial period in FILENAME is not special.
+ Both FILENAME and PATTERN are first case-normalized
+ if the operating system requires it.
+ If you don't want this, use fnmatchcase(FILENAME, PATTERN).
+ """
+
+ import os
name = os.path.normcase(name)
pat = os.path.normcase(pat)
- if not cache.has_key(pat):
+ return fnmatchcase(name, pat)
+
+def fnmatchcase(name, pat):
+ """Test wheter FILENAME matches PATTERN, including case.
+
+ This is a version of fnmatch() which doesn't case-normalize
+ its arguments.
+ """
+
+ if not _cache.has_key(pat):
res = translate(pat)
+ import regex
save_syntax = regex.set_syntax(0)
- cache[pat] = regex.compile(res)
+ _cache[pat] = regex.compile(res)
save_syntax = regex.set_syntax(save_syntax)
- return cache[pat].match(name) == len(name)
+ return _cache[pat].match(name) == len(name)
def translate(pat):
+ """Translate a shell PATTERN to a regular expression.
+
+ There is no way to quote meta-characters.
+ """
+
i, n = 0, len(pat)
res = ''
while i < n:
--- /dev/null
+import fnmatch
+import os
+
+_debug = 0
+
+_prune = ['(*)']
+
+def find(pattern, dir = os.curdir):
+ list = []
+ names = os.listdir(dir)
+ names.sort()
+ for name in names:
+ if name in (os.curdir, os.pardir):
+ continue
+ fullname = os.path.join(dir, name)
+ if fnmatch.fnmatch(name, pattern):
+ list.append(fullname)
+ if os.path.isdir(fullname) and not os.path.islink(fullname):
+ for p in _prune:
+ if fnmatch.fnmatch(name, p):
+ if _debug: print "skip", `fullname`
+ break
+ else:
+ if _debug: print "descend into", `fullname`
+ list = list + find(pattern, fullname)
+ return list
return S_ISDIR(st[ST_MODE])
+# Return true if the pathname refers to a symbolic link.
+# (Always false on the Mac, until we understand Aliases.)
+
+def islink(s):
+ return 0
+
+
# Return true if the pathname refers to an existing regular file.
def isfile(s):
import os, marshal, __builtin__
f = open(file)
codestring = f.read()
- timestamp = os.fstat(f.fileno())[8]
f.close()
+ timestamp = os.stat(file)[8]
codeobject = __builtin__.compile(codestring, file, 'exec')
if not cfile:
cfile = file + 'c'
- fc = open(cfile, 'w')
+ fc = open(cfile, 'wb')
wr_long(fc, MAGIC)
wr_long(fc, timestamp)
marshal.dump(codeobject, fc)
+ fc.close()
+ if os.name == 'mac':
+ import MacOS
+ MacOS.SetFileType(cfile, 'PYC ', 'PYTH')
+ MacOS.SetFileType(file, 'TEXT', 'PYTH')