diff --git a/compressor/parser/__init__.py b/compressor/parser/__init__.py index ba45d25..bc8c18c 100644 --- a/compressor/parser/__init__.py +++ b/compressor/parser/__init__.py @@ -2,18 +2,19 @@ from django.utils.functional import LazyObject from django.utils.importlib import import_module # support legacy parser module usage -from compressor.parser.base import ParserBase +from compressor.parser.base import ParserBase # noqa from compressor.parser.lxml import LxmlParser from compressor.parser.default_htmlparser import DefaultHtmlParser as HtmlParser -from compressor.parser.beautifulsoup import BeautifulSoupParser -from compressor.parser.html5lib import Html5LibParser +from compressor.parser.beautifulsoup import BeautifulSoupParser # noqa +from compressor.parser.html5lib import Html5LibParser # noqa class AutoSelectParser(LazyObject): options = ( - ('lxml.html', LxmlParser), # lxml, extremely fast - ('HTMLParser', HtmlParser), # fast and part of the Python stdlib + ('lxml.html', LxmlParser), # lxml, extremely fast + ('HTMLParser', HtmlParser), # fast and part of the Python stdlib ) + def __init__(self, content): self._wrapped = None self._setup(content) diff --git a/compressor/parser/default_htmlparser.py b/compressor/parser/default_htmlparser.py index ff82408..6e3928e 100644 --- a/compressor/parser/default_htmlparser.py +++ b/compressor/parser/default_htmlparser.py @@ -3,6 +3,7 @@ from django.utils.encoding import smart_unicode from compressor.exceptions import ParserError from compressor.parser import ParserBase + class DefaultHtmlParser(ParserBase, HTMLParser): def __init__(self, content): diff --git a/compressor/templatetags/compress.py b/compressor/templatetags/compress.py index 978c191..9c9b46b 100644 --- a/compressor/templatetags/compress.py +++ b/compressor/templatetags/compress.py @@ -109,7 +109,7 @@ class CompressorMixin(object): if cache_key: cache_set(cache_key, rendered_output) return rendered_output - except Exception, e: + except Exception: if settings.DEBUG or forced: raise diff --git a/compressor/tests/precompiler.py b/compressor/tests/precompiler.py index e62a4b4..4c01964 100644 --- a/compressor/tests/precompiler.py +++ b/compressor/tests/precompiler.py @@ -3,6 +3,7 @@ from __future__ import with_statement import optparse import sys + def main(): p = optparse.OptionParser() p.add_option('-f', '--file', action="store", diff --git a/compressor/tests/test_base.py b/compressor/tests/test_base.py index 5982c05..7a76f58 100644 --- a/compressor/tests/test_base.py +++ b/compressor/tests/test_base.py @@ -158,22 +158,22 @@ class CssMediaTestCase(TestCase): self.assertEqual(media, [l.get('media', None) for l in links]) def test_passthough_when_compress_disabled(self): - original_precompilers = settings.COMPRESS_PRECOMPILERS + original_precompilers = settings.COMPRESS_PRECOMPILERS settings.COMPRESS_ENABLED = False settings.COMPRESS_PRECOMPILERS = ( - ('text/foobar', 'python %s {infile} {outfile}' % os.path.join(test_dir, 'precompiler.py')), - ) + ('text/foobar', 'python %s {infile} {outfile}' % os.path.join(test_dir, 'precompiler.py')), + ) css = """\ """ css_node = CssCompressor(css) - output = BeautifulSoup(css_node.output()).findAll(['link','style']) - self.assertEqual([u'/media/css/one.css', u'/media/css/two.css', None], + output = BeautifulSoup(css_node.output()).findAll(['link', 'style']) + self.assertEqual([u'/media/css/one.css', u'/media/css/two.css', None], [l.get('href', None) for l in output]) - self.assertEqual([u'screen', u'screen', u'screen'], + self.assertEqual([u'screen', u'screen', u'screen'], [l.get('media', None) for l in output]) - settings.COMPRESS_PRECOMPILERS = original_precompilers + settings.COMPRESS_PRECOMPILERS = original_precompilers class VerboseTestCase(CompressorTestCase): diff --git a/compressor/tests/test_offline.py b/compressor/tests/test_offline.py index 8c324a2..eec888a 100644 --- a/compressor/tests/test_offline.py +++ b/compressor/tests/test_offline.py @@ -117,7 +117,8 @@ class OfflineGenerationStaticTemplateTagTestCase(OfflineTestCaseMixin, TestCase) expected_hash = "dfa2bb387fa8" # This test uses {% static %} which was introduced in django 1.4 OfflineGenerationStaticTemplateTagTestCase = skipIf( - django.VERSION[1] < 4, 'Django 1.4 not found') (OfflineGenerationStaticTemplateTagTestCase) + django.VERSION[1] < 4, 'Django 1.4 not found' +)(OfflineGenerationStaticTemplateTagTestCase) class OfflineGenerationTestCaseWithContext(OfflineTestCaseMixin, TestCase): diff --git a/compressor/tests/test_parsers.py b/compressor/tests/test_parsers.py index a418fc4..6d0e658 100644 --- a/compressor/tests/test_parsers.py +++ b/compressor/tests/test_parsers.py @@ -84,4 +84,3 @@ BeautifulSoupParserTests = skipIf( class HtmlParserTests(ParserTestCase, CompressorTestCase): parser_cls = 'compressor.parser.HtmlParser' - diff --git a/compressor/tests/test_signals.py b/compressor/tests/test_signals.py index c9801d7..529d0b0 100644 --- a/compressor/tests/test_signals.py +++ b/compressor/tests/test_signals.py @@ -59,6 +59,7 @@ class PostCompressSignalTestCase(TestCase): """ css_node = CssCompressor(css) + def listener(sender, **kwargs): pass callback = Mock(wraps=listener) diff --git a/compressor/tests/test_templatetags.py b/compressor/tests/test_templatetags.py index 01165b1..bafc521 100644 --- a/compressor/tests/test_templatetags.py +++ b/compressor/tests/test_templatetags.py @@ -106,8 +106,10 @@ class TemplatetagTestCase(TestCase): {% endcompress %} """ + class MockDebugRequest(object): GET = {settings.COMPRESS_DEBUG_TOGGLE: 'true'} + context = dict(self.context, request=MockDebugRequest()) out = u""" """ @@ -118,6 +120,7 @@ class TemplatetagTestCase(TestCase): {% endcompress %} """ + def listener(sender, **kwargs): pass callback = Mock(wraps=listener) @@ -219,7 +222,7 @@ class PrecompilerTemplatetagTestCase(TestCase): out = '\n'.join([ script(src="/media/CACHE/js/one.95cfb869eead.js"), script(scripttype="", src="/media/js/one.js"), - script(src="/media/CACHE/js/one.81a2cd965815.js"),]) + script(src="/media/CACHE/js/one.81a2cd965815.js")]) self.assertEqual(out, render(template, self.context)) finally: @@ -264,6 +267,7 @@ class PrecompilerTemplatetagTestCase(TestCase): finally: settings.COMPRESS_ENABLED = self.old_enabled + def script(content="", src="", scripttype="text/javascript"): """ returns a unicode text html script element. diff --git a/compressor/utils/__init__.py b/compressor/utils/__init__.py index 9212134..8aec054 100644 --- a/compressor/utils/__init__.py +++ b/compressor/utils/__init__.py @@ -70,6 +70,7 @@ def get_pathext(default_pathext=None): default_pathext = os.pathsep.join(['.COM', '.EXE', '.BAT', '.CMD']) return os.environ.get('PATHEXT', default_pathext) + def find_command(cmd, paths=None, pathext=None): """ Searches the PATH for the given command and returns its path diff --git a/compressor/utils/staticfiles.py b/compressor/utils/staticfiles.py index 838d976..169d427 100644 --- a/compressor/utils/staticfiles.py +++ b/compressor/utils/staticfiles.py @@ -12,7 +12,7 @@ if INSTALLED: from django.contrib.staticfiles import finders else: try: - from staticfiles import finders + from staticfiles import finders # noqa except ImportError: # Old (pre 1.0) and incompatible version of staticfiles INSTALLED = False @@ -24,4 +24,4 @@ if INSTALLED: "please add 'compressor.finders.CompressorFinder' to the " "STATICFILES_FINDERS setting.") else: - finders = None + finders = None # noqa diff --git a/compressor/utils/stringformat.py b/compressor/utils/stringformat.py index 9c797b6..f5f5eb5 100644 --- a/compressor/utils/stringformat.py +++ b/compressor/utils/stringformat.py @@ -8,17 +8,6 @@ Author: Florent Xicluna import re -if hasattr(str, 'partition'): - def partition(s, sep): - return s.partition(sep) -else: # Python 2.4 - def partition(s, sep): - try: - left, right = s.split(sep, 1) - except ValueError: - return s, '', '' - return left, sep, right - _format_str_re = re.compile( r'((?