Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4d74dff6
Commit
4d74dff6
authored
Jun 06, 2001
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #409973: Speedup glob.glob, add fnmatch.filter.
parent
7ea4ae9a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
7 deletions
+26
-7
Lib/fnmatch.py
Lib/fnmatch.py
+20
-0
Lib/glob.py
Lib/glob.py
+6
-7
No files found.
Lib/fnmatch.py
View file @
4d74dff6
...
...
@@ -37,6 +37,26 @@ def fnmatch(name, pat):
pat
=
os
.
path
.
normcase
(
pat
)
return
fnmatchcase
(
name
,
pat
)
def
filter
(
names
,
pat
):
"""Return the subset of the list NAMES that match PAT"""
import
os
,
posixpath
result
=
[]
pat
=
os
.
path
.
normcase
(
pat
)
if
not
_cache
.
has_key
(
pat
):
res
=
translate
(
pat
)
_cache
[
pat
]
=
re
.
compile
(
res
)
match
=
_cache
[
pat
].
match
if
os
.
path
is
posixpath
:
# normcase on posix is NOP. Optimize it away from the loop.
for
name
in
names
:
if
match
(
name
):
result
.
append
(
name
)
else
:
for
name
in
names
:
if
match
(
os
.
path
.
normcase
(
name
)):
result
.
append
(
name
)
return
result
def
fnmatchcase
(
name
,
pat
):
"""Test whether FILENAME matches PATTERN, including case.
...
...
Lib/glob.py
View file @
4d74dff6
...
...
@@ -18,7 +18,9 @@ def glob(pathname):
else
:
return
[]
dirname
,
basename
=
os
.
path
.
split
(
pathname
)
if
has_magic
(
dirname
):
if
not
dirname
:
return
glob1
(
os
.
curdir
,
basename
)
elif
has_magic
(
dirname
):
list
=
glob
(
dirname
)
else
:
list
=
[
dirname
]
...
...
@@ -43,12 +45,9 @@ def glob1(dirname, pattern):
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
if
pattern
[
0
]
!=
'.'
:
names
=
filter
(
lambda
x
:
x
[
0
]
!=
'.'
,
names
)
return
fnmatch
.
filter
(
names
,
pattern
)
magic_check
=
re
.
compile
(
'[*?[]'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment