django1/django/utils/glob.py

22 lines
476 B
Python
Raw Normal View History

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:
from glob import escape as glob_escape
2015-06-15 21:43:35 +08:00
else:
_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