[issue13929] fnmatch to support escape characters

Terry J. Reedy report at bugs.python.org
Sat Feb 4 10:48:53 CET 2012


Terry J. Reedy <tjreedy at udel.edu> added the comment:

If indeed fnmatch does not match current shells, then I would agree that it should. It looks to me so easy to add that I though it must be a deliberate decision to exclude. In translate:
...
        elif c == '\':
            if i < n-1:
                c2 = pat[i+1]
                <specify what to do for \c2 for all cases of c2>
            else:
                <specify what to do for pattern ending in '\'>
        else:  
            res = res + re.escape(c)
# the last two lines are current code, which is why '\' in patterns does not escape anything in the translated re.

Changing the meaning of '\' from ordinary character to escape char will break any code that depends on its current ordinariness.
>>> fn.fnmatch(r'\x', r'\?')
True # for x any 'ordinary' char, but not is '\?' means "match '?'.

This was another reason I closed, although I forgot to mention it. I suppose a new parameter 'escape = False' could be added to all 4 exposed functions to preserve back compatibility. Anyway, I have reopened for further discussion and specification.

----------
resolution: rejected -> 
status: closed -> open

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13929>
_______________________________________


More information about the Python-bugs-list mailing list