2015-06-13 18:20:05 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import os.path
|
|
|
|
import re
|
|
|
|
|
|
|
|
from django.utils import six
|
|
|
|
|
|
|
|
# backport of Python 3.4's glob.escape
|
|
|
|
|
2015-06-15 21:43:35 +08:00
|
|
|
if six.PY3:
|
2015-06-13 18:20:05 +08:00
|
|
|
from glob import escape as glob_escape
|
2015-06-15 21:43:35 +08:00
|
|
|
else:
|
2015-06-13 18:20:05 +08:00
|
|
|
_magic_check = re.compile('([*?[])')
|
|
|
|
|
2015-06-15 21:43:35 +08:00
|
|
|
def glob_escape(pathname):
|
|
|
|
"""
|
|
|
|
Escape all special characters.
|
|
|
|
"""
|
|
|
|
drive, pathname = os.path.splitdrive(pathname)
|
|
|
|
pathname = _magic_check.sub(r'[\1]', pathname)
|
|
|
|
return drive + pathname
|