Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../usr/lib64/python3....
File: fnmatch.py
"""Filename matching with shell patterns.
[0] Fix | Delete
[1] Fix | Delete
fnmatch(FILENAME, PATTERN) matches according to the local convention.
[2] Fix | Delete
fnmatchcase(FILENAME, PATTERN) always takes case in account.
[3] Fix | Delete
[4] Fix | Delete
The functions operate by translating the pattern into a regular
[5] Fix | Delete
expression. They cache the compiled regular expressions for speed.
[6] Fix | Delete
[7] Fix | Delete
The function translate(PATTERN) returns a regular expression
[8] Fix | Delete
corresponding to PATTERN. (It does not compile it.)
[9] Fix | Delete
"""
[10] Fix | Delete
import os
[11] Fix | Delete
import posixpath
[12] Fix | Delete
import re
[13] Fix | Delete
import functools
[14] Fix | Delete
[15] Fix | Delete
__all__ = ["filter", "fnmatch", "fnmatchcase", "translate"]
[16] Fix | Delete
[17] Fix | Delete
def fnmatch(name, pat):
[18] Fix | Delete
"""Test whether FILENAME matches PATTERN.
[19] Fix | Delete
[20] Fix | Delete
Patterns are Unix shell style:
[21] Fix | Delete
[22] Fix | Delete
* matches everything
[23] Fix | Delete
? matches any single character
[24] Fix | Delete
[seq] matches any character in seq
[25] Fix | Delete
[!seq] matches any char not in seq
[26] Fix | Delete
[27] Fix | Delete
An initial period in FILENAME is not special.
[28] Fix | Delete
Both FILENAME and PATTERN are first case-normalized
[29] Fix | Delete
if the operating system requires it.
[30] Fix | Delete
If you don't want this, use fnmatchcase(FILENAME, PATTERN).
[31] Fix | Delete
"""
[32] Fix | Delete
name = os.path.normcase(name)
[33] Fix | Delete
pat = os.path.normcase(pat)
[34] Fix | Delete
return fnmatchcase(name, pat)
[35] Fix | Delete
[36] Fix | Delete
@functools.lru_cache(maxsize=256, typed=True)
[37] Fix | Delete
def _compile_pattern(pat):
[38] Fix | Delete
if isinstance(pat, bytes):
[39] Fix | Delete
pat_str = str(pat, 'ISO-8859-1')
[40] Fix | Delete
res_str = translate(pat_str)
[41] Fix | Delete
res = bytes(res_str, 'ISO-8859-1')
[42] Fix | Delete
else:
[43] Fix | Delete
res = translate(pat)
[44] Fix | Delete
return re.compile(res).match
[45] Fix | Delete
[46] Fix | Delete
def filter(names, pat):
[47] Fix | Delete
"""Return the subset of the list NAMES that match PAT."""
[48] Fix | Delete
result = []
[49] Fix | Delete
pat = os.path.normcase(pat)
[50] Fix | Delete
match = _compile_pattern(pat)
[51] Fix | Delete
if os.path is posixpath:
[52] Fix | Delete
# normcase on posix is NOP. Optimize it away from the loop.
[53] Fix | Delete
for name in names:
[54] Fix | Delete
if match(name):
[55] Fix | Delete
result.append(name)
[56] Fix | Delete
else:
[57] Fix | Delete
for name in names:
[58] Fix | Delete
if match(os.path.normcase(name)):
[59] Fix | Delete
result.append(name)
[60] Fix | Delete
return result
[61] Fix | Delete
[62] Fix | Delete
def fnmatchcase(name, pat):
[63] Fix | Delete
"""Test whether FILENAME matches PATTERN, including case.
[64] Fix | Delete
[65] Fix | Delete
This is a version of fnmatch() which doesn't case-normalize
[66] Fix | Delete
its arguments.
[67] Fix | Delete
"""
[68] Fix | Delete
match = _compile_pattern(pat)
[69] Fix | Delete
return match(name) is not None
[70] Fix | Delete
[71] Fix | Delete
[72] Fix | Delete
def translate(pat):
[73] Fix | Delete
"""Translate a shell PATTERN to a regular expression.
[74] Fix | Delete
[75] Fix | Delete
There is no way to quote meta-characters.
[76] Fix | Delete
"""
[77] Fix | Delete
[78] Fix | Delete
i, n = 0, len(pat)
[79] Fix | Delete
res = ''
[80] Fix | Delete
while i < n:
[81] Fix | Delete
c = pat[i]
[82] Fix | Delete
i = i+1
[83] Fix | Delete
if c == '*':
[84] Fix | Delete
res = res + '.*'
[85] Fix | Delete
elif c == '?':
[86] Fix | Delete
res = res + '.'
[87] Fix | Delete
elif c == '[':
[88] Fix | Delete
j = i
[89] Fix | Delete
if j < n and pat[j] == '!':
[90] Fix | Delete
j = j+1
[91] Fix | Delete
if j < n and pat[j] == ']':
[92] Fix | Delete
j = j+1
[93] Fix | Delete
while j < n and pat[j] != ']':
[94] Fix | Delete
j = j+1
[95] Fix | Delete
if j >= n:
[96] Fix | Delete
res = res + '\\['
[97] Fix | Delete
else:
[98] Fix | Delete
stuff = pat[i:j].replace('\\','\\\\')
[99] Fix | Delete
i = j+1
[100] Fix | Delete
if stuff[0] == '!':
[101] Fix | Delete
stuff = '^' + stuff[1:]
[102] Fix | Delete
elif stuff[0] == '^':
[103] Fix | Delete
stuff = '\\' + stuff
[104] Fix | Delete
res = '%s[%s]' % (res, stuff)
[105] Fix | Delete
else:
[106] Fix | Delete
res = res + re.escape(c)
[107] Fix | Delete
return r'(?s:%s)\Z' % res
[108] Fix | Delete
[109] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function