From ceb946a262d33356a840809ca3934e2968b42410 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Wed, 11 May 2011 13:07:53 +0200 Subject: [PATCH] Minor nitpicking and style changes. --- compressor/base.py | 16 +++++++--------- compressor/filters/css_default.py | 4 ++-- compressor/utils/staticfiles.py | 16 ++++++++-------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/compressor/base.py b/compressor/base.py index f47fd83..9712d0b 100644 --- a/compressor/base.py +++ b/compressor/base.py @@ -47,8 +47,7 @@ class Compressor(object): " compressed" % (url, base_url)) basename = url.replace(base_url, "", 1) # drop the querystring, which is used for non-compressed cache-busting. - basename = basename.split("?", 1)[0] - return basename + return basename.split("?", 1)[0] def get_filename(self, basename): # first try to find it with staticfiles (in debug mode) @@ -79,7 +78,7 @@ class Compressor(object): @cached_property def mtimes(self): return [str(get_mtime(value)) - for kind, value, _, _ in self.split_contents() + for kind, value, basename, elem in self.split_contents() if kind == 'file'] @cached_property @@ -92,9 +91,9 @@ class Compressor(object): def hunks(self): for kind, value, basename, elem in self.split_contents(): if kind == "hunk": - yield unicode(self.filter( - value, basename=basename, method="input", elem=elem, - kind=kind)) + content = self.filter(value, "input", + elem=elem, kind=kind, basename=basename) + yield unicode(content) elif kind == "file": content = "" fd = open(value, 'rb') @@ -105,9 +104,8 @@ class Compressor(object): "IOError while processing '%s': %s" % (value, e)) finally: fd.close() - content = self.filter(content, - method="input", filename=value, basename=basename, - elem=elem, kind=kind) + content = self.filter(content, "input", + filename=value, basename=basename, elem=elem, kind=kind) attribs = self.parser.elem_attribs(elem) charset = attribs.get("charset", self.charset) yield unicode(content, charset) diff --git a/compressor/filters/css_default.py b/compressor/filters/css_default.py index 5a3cd3e..0aed1d7 100644 --- a/compressor/filters/css_default.py +++ b/compressor/filters/css_default.py @@ -15,8 +15,8 @@ class CssAbsoluteFilter(FilterBase): self.root = os.path.normcase(os.path.abspath(settings.COMPRESS_ROOT)) if filename is not None: filename = os.path.normcase(os.path.abspath(filename)) - if not (filename and filename.startswith(self.root)) and \ - not self.find(basename): + if (not (filename and filename.startswith(self.root)) and + not self.find(basename)): return self.content self.path = basename.replace(os.sep, '/') self.path = self.path.lstrip('/') diff --git a/compressor/utils/staticfiles.py b/compressor/utils/staticfiles.py index b8517d8..1bf8f71 100644 --- a/compressor/utils/staticfiles.py +++ b/compressor/utils/staticfiles.py @@ -3,8 +3,8 @@ from __future__ import absolute_import from django.conf import settings as django_settings from django.core.exceptions import ImproperlyConfigured -INSTALLED = "staticfiles" in django_settings.INSTALLED_APPS or \ - "django.contrib.staticfiles" in django_settings.INSTALLED_APPS +INSTALLED = ("staticfiles" in django_settings.INSTALLED_APPS or + "django.contrib.staticfiles" in django_settings.INSTALLED_APPS) finders = None settings = None @@ -21,9 +21,9 @@ if INSTALLED: # Old (pre 1.0) and incompatible version of staticfiles INSTALLED = False - if INSTALLED and "compressor.finders.CompressorFinder" \ - not in settings.STATICFILES_FINDERS: - raise ImproperlyConfigured( - "When using Django Compressor together with staticfiles, " - "please add 'compressor.finders.CompressorFinder' to the " - "STATICFILES_FINDERS setting.") + if (INSTALLED and "compressor.finders.CompressorFinder" + not in settings.STATICFILES_FINDERS): + raise ImproperlyConfigured( + "When using Django Compressor together with staticfiles, " + "please add 'compressor.finders.CompressorFinder' to the " + "STATICFILES_FINDERS setting.")