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
fc61383f
Commit
fc61383f
authored
Apr 07, 1991
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support [...] ranges. Also [!...] for negated ranges, SYSV shell style.
parent
117dbcb2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
14 deletions
+50
-14
Lib/fnmatch.py
Lib/fnmatch.py
+50
-14
No files found.
Lib/fnmatch.py
View file @
fc61383f
# module 'fnmatch' -- filename matching with shell patterns
# XXX [] patterns are not supported (but recognized)
def
fnmatch
(
name
,
pat
):
if
'*'
in
pat
or
'?'
in
pat
or
'['
in
pat
:
return
fnmatch1
(
name
,
pat
)
return
name
=
pat
#
# Check for simple case: no special characters
#
if
not
(
'*'
in
pat
or
'?'
in
pat
or
'['
in
pat
):
return
name
=
pat
#
# Check for common cases: *suffix and prefix*
#
if
pat
[
0
]
=
'*'
:
p1
=
pat
[
1
:]
if
not
(
'*'
in
p1
or
'?'
in
p1
or
'['
in
p1
):
start
=
len
(
name
)
-
len
(
p1
)
return
start
>=
0
and
name
[
start
:]
=
p1
elif
pat
[
-
1
:]
=
'*'
:
p1
=
pat
[:
-
1
]
if
not
(
'*'
in
p1
or
'?'
in
p1
or
'['
in
p1
):
return
name
[:
len
(
p1
)]
=
p1
#
# General case
#
return
fnmatch1
(
name
,
pat
)
def
fnmatch1
(
name
,
pat
):
for
i
in
range
(
len
(
pat
)):
c
=
pat
[
i
]
if
c
=
'*'
:
restpat
=
pat
[
i
+
1
:]
if
'*'
in
restpat
or
'?'
in
restpat
or
'['
in
restpat
:
for
i
in
range
(
i
,
len
(
name
)):
if
fnmatch1
(
name
[
i
:],
restpat
):
return
1
return
0
else
:
return
name
[
len
(
name
)
-
len
(
restpat
):]
=
restpat
p1
=
pat
[
i
+
1
:]
if
not
(
'*'
in
p1
or
'?'
in
p1
or
'['
in
p1
)
:
start
=
len
(
name
)
-
len
(
p1
)
return
start
>=
0
and
name
[
start
:]
=
p1
for
i
in
range
(
i
,
len
(
name
)
+
1
):
if
fnmatch1
(
name
[
i
:],
p1
):
return
1
return
0
elif
c
=
'?'
:
if
len
(
name
)
<=
i
:
return
0
elif
c
=
'['
:
return
0
# XXX
c
,
rest
=
name
[
i
],
name
[
i
+
1
:]
i
,
n
=
i
+
1
,
len
(
pat
)
-
1
match
=
0
exclude
=
0
if
i
<
n
and
pat
[
i
]
=
'!'
:
exclude
=
1
i
=
i
+
1
while
i
<
n
:
if
pat
[
i
]
=
c
:
match
=
1
i
=
i
+
1
if
i
>=
n
or
pat
[
i
]
=
']'
:
break
if
pat
[
i
]
=
'-'
:
i
=
i
+
1
if
i
>=
n
or
pat
[
i
]
=
']'
:
break
match
=
(
pat
[
i
-
2
]
<=
c
<=
pat
[
i
])
i
=
i
+
1
if
match
=
exclude
:
return
0
return
fnmatch1
(
rest
,
pat
[
i
+
1
:])
else
:
if
name
[
i
:
i
+
1
]
<>
c
:
return
0
...
...
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