[issue13929] fnmatch to support escape characters

2012-10-15 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Issue8402 has discussion and patch(es).

--
nosy: +serhiy.storchaka
resolution:  -> duplicate
status: open -> closed
superseder:  -> Add a way to escape metacharacters in glob/fnmatch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13929] fnmatch to support escape characters

2012-02-04 Thread Terry J. Reedy

Terry J. Reedy  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]

else:

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13929] fnmatch to support escape characters

2012-02-04 Thread Éric Araujo

Éric Araujo  added the comment:

> [fnmatch] explicitly disclaims the feature you request: "Be aware there is no 
> way to quote
> meta-characters."

This reads like a warning to me, i.e. a potential future feature, not a design 
choice.

> What you are asking for in something in between the unix language and re. If 
> one re
> feature is added, why not another?

When we use glob patterns in our shells, the shell language lets us escape what 
would otherwise be special characters.  Python would be nicer to let us do the 
same.

--
nosy: +eric.araujo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13929] fnmatch to support escape characters

2012-02-03 Thread Terry J. Reedy

Terry J. Reedy  added the comment:

The doc chapters are entitled "fnmatch — Unix filename pattern matching" and 
"glob — Unix style pathname pattern expansion". The first explicitly disclaims 
the feature you request: "Be aware there is no way to quote meta-characters.", 
suggests using re for anything beyond fnmatch, and shows to use .translate to 
make a start in doing so. For your example:

>>> re.match(r".*\[Ver\.2\].*",  "Document[Ver.2].doc")
<_sre.SRE_Match object at 0x0331AF38>

Indeed, fnmatch works by using translate() and re.match. What you are asking 
for in something in between the unix language and re. If one re feature is 
added, why not another?

So the scope of these modules is clearly circumscribed. I suspect their intent 
was to make it easy to translate unix shell scripts into Python. 
What you are asking for in something in between. If you want to pursue this, 
post on python-list or python-ideas to garner more support. But I anticipate 
rejection as not needed and contrary to intent.

Not obvious from the doc is that an unmatch '[' or ']' is escaped:
>>> name = "Document[Ver.2.doc"
>>> pattern = "*[Ver.2*"
>>> fnmatch.fnmatch(name, pattern)
True
>>> name = "DocumentVer.2].doc"
>>> pattern = "*Ver.2]*"
>>> fnmatch.fnmatch(name, pattern)
True
I presume this matches the *nix behavior, but don't know.

--
nosy: +terry.reedy
resolution:  -> rejected
status: open -> closed
versions:  -Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13929] fnmatch to support escape characters

2012-02-02 Thread Israel Fruchter

New submission from Israel Fruchter :

fnmatch to support escape characters:
like that:

>>> name = "Document[Ver.2].doc"
>>> pattern = "*\[Ver.2\]*"
>>> fnmatch.fnmatch(name, pattern)
True

that's also fix glob module:
>>> pattern = "ipconfig /\?"
>>> glob.glob(pattern)
"ipconfig /?"

--
components: Library (Lib)
messages: 152495
nosy: fruch
priority: normal
severity: normal
status: open
title: fnmatch to support escape characters
type: enhancement
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com