Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(672)

Unified Diff: Lib/fnmatch.py

Issue 3055: combined patches from http://bugs.python.org/issue3187 (Closed) Base URL: http://svn.python.org/view/*checkout*/python/branches/py3k/
Patch Set: One more tweak (fold some long lines) Created 16 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/genericpath.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Lib/fnmatch.py
===================================================================
--- Lib/fnmatch.py (revision 66736)
+++ Lib/fnmatch.py (working copy)
@@ -37,15 +37,24 @@
pat = os.path.normcase(pat)
return fnmatchcase(name, pat)
+def _compile_pattern(pat):
+ regex = _cache.get(pat)
+ if regex is None:
+ if isinstance(pat, bytes):
+ pat_str = str(pat, 'ISO-8859-1')
+ res_str = translate(pat_str)
+ res = bytes(res_str, 'ISO-8859-1')
+ else:
+ res = translate(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
- result=[]
- pat=os.path.normcase(pat)
- if not pat in _cache:
- res = translate(pat)
- _cache[pat] = re.compile(res)
- match=_cache[pat].match
+ result = []
+ pat = os.path.normcase(pat)
+ match = _compile_pattern(pat)
if os.path is posixpath:
# normcase on posix is NOP. Optimize it away from the loop.
for name in names:
@@ -64,10 +73,8 @@
its arguments.
"""
- if not pat in _cache:
- res = translate(pat)
- _cache[pat] = re.compile(res)
- return _cache[pat].match(name) is not None
+ match = _compile_pattern(pat)
+ return match(name) is not None
def translate(pat):
"""Translate a shell PATTERN to a regular expression.
« no previous file with comments | « no previous file | Lib/genericpath.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b