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

Skip to content

Commit cc14320

Browse files
committed
Make fnmatch be more PEP 8 compliant.
Partially closes issue 9356. Thanks to Brian Brazil for the patch.
1 parent 8cb3619 commit cc14320

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

Lib/fnmatch.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@
99
The function translate(PATTERN) returns a regular expression
1010
corresponding to PATTERN. (It does not compile it.)
1111
"""
12-
12+
import os
13+
import posixpath
1314
import re
1415

1516
__all__ = ["filter", "fnmatch", "fnmatchcase", "purge", "translate"]
1617

1718
_cache = {} # Maps text patterns to compiled regexen.
1819
_cacheb = {} # Ditto for bytes patterns.
19-
_MAXCACHE = 100 # Maximum size of caches
20+
_MAXCACHE = 100 # Maximum size of caches.
21+
2022

2123
def purge():
22-
"""Clear the pattern cache"""
24+
"""Clear the pattern cache."""
2325
_cache.clear()
2426
_cacheb.clear()
2527

28+
2629
def fnmatch(name, pat):
2730
"""Test whether FILENAME matches PATTERN.
2831
@@ -38,12 +41,11 @@ def fnmatch(name, pat):
3841
if the operating system requires it.
3942
If you don't want this, use fnmatchcase(FILENAME, PATTERN).
4043
"""
41-
42-
import os
4344
name = os.path.normcase(name)
4445
pat = os.path.normcase(pat)
4546
return fnmatchcase(name, pat)
4647

48+
4749
def _compile_pattern(pat):
4850
cache = _cacheb if isinstance(pat, bytes) else _cache
4951
regex = cache.get(pat)
@@ -59,9 +61,9 @@ def _compile_pattern(pat):
5961
cache[pat] = regex = re.compile(res)
6062
return regex.match
6163

64+
6265
def filter(names, pat):
63-
"""Return the subset of the list NAMES that match PAT"""
64-
import os,posixpath
66+
"""Return the subset of the list NAMES that match PAT."""
6567
result = []
6668
pat = os.path.normcase(pat)
6769
match = _compile_pattern(pat)
@@ -76,16 +78,17 @@ def filter(names, pat):
7678
result.append(name)
7779
return result
7880

81+
7982
def fnmatchcase(name, pat):
8083
"""Test whether FILENAME matches PATTERN, including case.
8184
8285
This is a version of fnmatch() which doesn't case-normalize
8386
its arguments.
8487
"""
85-
8688
match = _compile_pattern(pat)
8789
return match(name) is not None
8890

91+
8992
def translate(pat):
9093
"""Translate a shell PATTERN to a regular expression.
9194

0 commit comments

Comments
 (0)