Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
cc143201
Kaydet (Commit)
cc143201
authored
Tem 23, 2010
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make fnmatch be more PEP 8 compliant.
Partially closes issue 9356. Thanks to Brian Brazil for the patch.
üst
8cb3619f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
8 deletions
+11
-8
fnmatch.py
Lib/fnmatch.py
+11
-8
No files found.
Lib/fnmatch.py
Dosyayı görüntüle @
cc143201
...
...
@@ -9,20 +9,23 @@ 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.)
"""
import
os
import
posixpath
import
re
__all__
=
[
"filter"
,
"fnmatch"
,
"fnmatchcase"
,
"purge"
,
"translate"
]
_cache
=
{}
# Maps text patterns to compiled regexen.
_cacheb
=
{}
# Ditto for bytes patterns.
_MAXCACHE
=
100
# Maximum size of caches
_MAXCACHE
=
100
# Maximum size of caches.
def
purge
():
"""Clear the pattern cache"""
"""Clear the pattern cache
.
"""
_cache
.
clear
()
_cacheb
.
clear
()
def
fnmatch
(
name
,
pat
):
"""Test whether FILENAME matches PATTERN.
...
...
@@ -38,12 +41,11 @@ def fnmatch(name, pat):
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
)
return
fnmatchcase
(
name
,
pat
)
def
_compile_pattern
(
pat
):
cache
=
_cacheb
if
isinstance
(
pat
,
bytes
)
else
_cache
regex
=
cache
.
get
(
pat
)
...
...
@@ -59,9 +61,9 @@ def _compile_pattern(pat):
cache
[
pat
]
=
regex
=
re
.
compile
(
res
)
return
regex
.
match
def
filter
(
names
,
pat
):
"""Return the subset of the list NAMES that match PAT"""
import
os
,
posixpath
"""Return the subset of the list NAMES that match PAT."""
result
=
[]
pat
=
os
.
path
.
normcase
(
pat
)
match
=
_compile_pattern
(
pat
)
...
...
@@ -76,16 +78,17 @@ def filter(names, pat):
result
.
append
(
name
)
return
result
def
fnmatchcase
(
name
,
pat
):
"""Test whether FILENAME matches PATTERN, including case.
This is a version of fnmatch() which doesn't case-normalize
its arguments.
"""
match
=
_compile_pattern
(
pat
)
return
match
(
name
)
is
not
None
def
translate
(
pat
):
"""Translate a shell PATTERN to a regular expression.
...
...
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