Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e4b2de

Browse files
committed
changes for the Mac
1 parent f808012 commit 7e4b2de

5 files changed

Lines changed: 111 additions & 11 deletions

File tree

Lib/find.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import fnmatch
2+
import os
3+
4+
_debug = 0
5+
6+
_prune = ['(*)']
7+
8+
def find(pattern, dir = os.curdir):
9+
list = []
10+
names = os.listdir(dir)
11+
names.sort()
12+
for name in names:
13+
if name in (os.curdir, os.pardir):
14+
continue
15+
fullname = os.path.join(dir, name)
16+
if fnmatch.fnmatch(name, pattern):
17+
list.append(fullname)
18+
if os.path.isdir(fullname) and not os.path.islink(fullname):
19+
for p in _prune:
20+
if fnmatch.fnmatch(name, p):
21+
if _debug: print "skip", `fullname`
22+
break
23+
else:
24+
if _debug: print "descend into", `fullname`
25+
list = list + find(pattern, fullname)
26+
return list

Lib/fnmatch.py

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,59 @@
1-
# module 'fnmatch' -- filename matching with shell patterns
2-
# This version translates the pattern to a regular expression
3-
# and moreover caches the expressions.
1+
"""Filename matching with shell patterns.
42
5-
import os
6-
import regex
3+
fnmatch(FILENAME, PATTERN) matches according to the local convention.
4+
fnmatchcase(FILENAME, PATTERN) always takes case in account.
75
8-
cache = {}
6+
The functions operate by translating the pattern into a regular
7+
expression. They cache the compiled regular expressions for speed.
8+
9+
The function translate(PATTERN) returns a regular expression
10+
corresponding to PATTERN. (It does not compile it.)
11+
"""
12+
13+
_cache = {}
914

1015
def fnmatch(name, pat):
16+
"""Test whether FILENAME matches PATTERN.
17+
18+
Patterns are Unix shell style:
19+
20+
* matches everything
21+
? matches any single character
22+
[seq] matches any character in seq
23+
[!seq] matches any char not in seq
24+
25+
An initial period in FILENAME is not special.
26+
Both FILENAME and PATTERN are first case-normalized
27+
if the operating system requires it.
28+
If you don't want this, use fnmatchcase(FILENAME, PATTERN).
29+
"""
30+
31+
import os
1132
name = os.path.normcase(name)
1233
pat = os.path.normcase(pat)
13-
if not cache.has_key(pat):
34+
return fnmatchcase(name, pat)
35+
36+
def fnmatchcase(name, pat):
37+
"""Test wheter FILENAME matches PATTERN, including case.
38+
39+
This is a version of fnmatch() which doesn't case-normalize
40+
its arguments.
41+
"""
42+
43+
if not _cache.has_key(pat):
1444
res = translate(pat)
45+
import regex
1546
save_syntax = regex.set_syntax(0)
16-
cache[pat] = regex.compile(res)
47+
_cache[pat] = regex.compile(res)
1748
save_syntax = regex.set_syntax(save_syntax)
18-
return cache[pat].match(name) == len(name)
49+
return _cache[pat].match(name) == len(name)
1950

2051
def translate(pat):
52+
"""Translate a shell PATTERN to a regular expression.
53+
54+
There is no way to quote meta-characters.
55+
"""
56+
2157
i, n = 0, len(pat)
2258
res = ''
2359
while i < n:

Lib/lib-old/find.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import fnmatch
2+
import os
3+
4+
_debug = 0
5+
6+
_prune = ['(*)']
7+
8+
def find(pattern, dir = os.curdir):
9+
list = []
10+
names = os.listdir(dir)
11+
names.sort()
12+
for name in names:
13+
if name in (os.curdir, os.pardir):
14+
continue
15+
fullname = os.path.join(dir, name)
16+
if fnmatch.fnmatch(name, pattern):
17+
list.append(fullname)
18+
if os.path.isdir(fullname) and not os.path.islink(fullname):
19+
for p in _prune:
20+
if fnmatch.fnmatch(name, p):
21+
if _debug: print "skip", `fullname`
22+
break
23+
else:
24+
if _debug: print "descend into", `fullname`
25+
list = list + find(pattern, fullname)
26+
return list

Lib/macpath.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ def isdir(s):
100100
return S_ISDIR(st[ST_MODE])
101101

102102

103+
# Return true if the pathname refers to a symbolic link.
104+
# (Always false on the Mac, until we understand Aliases.)
105+
106+
def islink(s):
107+
return 0
108+
109+
103110
# Return true if the pathname refers to an existing regular file.
104111

105112
def isfile(s):

Lib/py_compile.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ def compile(file, cfile = None):
1414
import os, marshal, __builtin__
1515
f = open(file)
1616
codestring = f.read()
17-
timestamp = os.fstat(f.fileno())[8]
1817
f.close()
18+
timestamp = os.stat(file)[8]
1919
codeobject = __builtin__.compile(codestring, file, 'exec')
2020
if not cfile:
2121
cfile = file + 'c'
22-
fc = open(cfile, 'w')
22+
fc = open(cfile, 'wb')
2323
wr_long(fc, MAGIC)
2424
wr_long(fc, timestamp)
2525
marshal.dump(codeobject, fc)
26+
fc.close()
27+
if os.name == 'mac':
28+
import MacOS
29+
MacOS.SetFileType(cfile, 'PYC ', 'PYTH')
30+
MacOS.SetFileType(file, 'TEXT', 'PYTH')

0 commit comments

Comments
 (0)