diff options
Diffstat (limited to 'django/utils/glob.py')
| -rw-r--r-- | django/utils/glob.py | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/django/utils/glob.py b/django/utils/glob.py index a3138b09dc..d3f9e08138 100644 --- a/django/utils/glob.py +++ b/django/utils/glob.py @@ -7,30 +7,15 @@ from django.utils import six # backport of Python 3.4's glob.escape -try: +if six.PY3: from glob import escape as glob_escape -except ImportError: +else: _magic_check = re.compile('([*?[])') - if six.PY3: - _magic_check_bytes = re.compile(b'([*?[])') - - def glob_escape(pathname): - """ - Escape all special characters. - """ - drive, pathname = os.path.splitdrive(pathname) - if isinstance(pathname, bytes): - pathname = _magic_check_bytes.sub(br'[\1]', pathname) - else: - pathname = _magic_check.sub(r'[\1]', pathname) - return drive + pathname - - else: - def glob_escape(pathname): - """ - Escape all special characters. - """ - drive, pathname = os.path.splitdrive(pathname) - pathname = _magic_check.sub(r'[\1]', pathname) - return drive + pathname + def glob_escape(pathname): + """ + Escape all special characters. + """ + drive, pathname = os.path.splitdrive(pathname) + pathname = _magic_check.sub(r'[\1]', pathname) + return drive + pathname |
