Commit 735dcee0 by Stephan Wienczny

Fix Python 3 compatibility

Python 3 compatibility has been lost. Readd it.

finders.py: use chain to concatenate dictionaries instead of + operator.
glob.py: use list compresension instead of filter and lambda.
utils.py: use urllib.parse.quote instead urllib.quote if available.
parent 79fd14ed
from itertools import chain
from django.contrib.staticfiles.finders import BaseFinder, AppDirectoriesFinder, FileSystemFinder, find from django.contrib.staticfiles.finders import BaseFinder, AppDirectoriesFinder, FileSystemFinder, find
from django.utils._os import safe_join from django.utils._os import safe_join
from pipeline.conf import settings from pipeline.conf import settings
class PipelineFinder(BaseFinder): class PipelineFinder(BaseFinder):
def find(self, path, all=False): def find(self, path, all=False):
""" """
Looks for files in PIPELINE_CSS and PIPELINE_JS Looks for files in PIPELINE_CSS and PIPELINE_JS
""" """
matches = [] matches = []
for elem in settings.PIPELINE_CSS.values() + settings.PIPELINE_JS.values(): for elem in chain(settings.PIPELINE_CSS.values(), settings.PIPELINE_JS.values()):
if elem['output_filename'] == path: if elem['output_filename'] == path:
match = safe_join(settings.PIPELINE_ROOT, path) match = safe_join(settings.PIPELINE_ROOT, path)
if not all: if not all:
......
...@@ -63,7 +63,7 @@ def glob1(dirname, pattern): ...@@ -63,7 +63,7 @@ def glob1(dirname, pattern):
# and storage implementations are really exotic. # and storage implementations are really exotic.
return [] return []
if pattern[0] != '.': if pattern[0] != '.':
names = filter(lambda x: x[0] != '.', names) names = [x for x in names if x[0] != '.']
return fnmatch.filter(names, pattern) return fnmatch.filter(names, pattern)
......
...@@ -2,7 +2,11 @@ from __future__ import unicode_literals ...@@ -2,7 +2,11 @@ from __future__ import unicode_literals
import mimetypes import mimetypes
import posixpath import posixpath
import urllib
try:
from urllib.parse import quote
except ImportError:
from urllib import quote
from django.utils import importlib from django.utils import importlib
from django.utils.encoding import smart_str from django.utils.encoding import smart_str
...@@ -23,7 +27,7 @@ def to_class(class_str): ...@@ -23,7 +27,7 @@ def to_class(class_str):
def filepath_to_uri(path): def filepath_to_uri(path):
if path is None: if path is None:
return path return path
return urllib.quote(smart_str(path).replace("\\", "/"), safe="/~!*()'#?") return quote(smart_str(path).replace("\\", "/"), safe="/~!*()'#?")
def guess_type(path, default=None): def guess_type(path, default=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment