diff --git a/compressor/filters/cssmin/cssmin.py b/compressor/filters/cssmin/cssmin.py index 1668355..b79fc6d 100644 --- a/compressor/filters/cssmin/cssmin.py +++ b/compressor/filters/cssmin/cssmin.py @@ -248,4 +248,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/compressor/finders.py b/compressor/finders.py index 33d9485..36edf93 100644 --- a/compressor/finders.py +++ b/compressor/finders.py @@ -1,6 +1,7 @@ from compressor.utils import staticfiles from compressor.storage import CompressorFileStorage + class CompressorFinder(staticfiles.finders.BaseStorageFinder): """ A staticfiles finder that looks in COMPRESS_ROOT diff --git a/compressor/management/commands/compress.py b/compressor/management/commands/compress.py index b293a42..8f921dc 100644 --- a/compressor/management/commands/compress.py +++ b/compressor/management/commands/compress.py @@ -36,6 +36,7 @@ class Command(NoArgsCommand): "can lead to infinite recursion if a link points to a parent " "directory of itself.", dest='follow_links'), ) + def get_loaders(self): from django.template.loader import template_source_loaders if template_source_loaders is None: @@ -113,11 +114,11 @@ class Command(NoArgsCommand): settings.FILE_CHARSET)) finally: template_file.close() - except IOError: # unreadable file -> ignore + except IOError: # unreadable file -> ignore if verbosity > 0: log.write("Unreadable template at: %s\n" % template_name) continue - except TemplateSyntaxError: # broken template -> ignore + except TemplateSyntaxError: # broken template -> ignore if verbosity > 0: log.write("Invalid template at: %s\n" % template_name) continue @@ -159,7 +160,7 @@ class Command(NoArgsCommand): def walk_nodes(self, node): for node in getattr(node, "nodelist", []): if (isinstance(node, CompressorNode) or - node.__class__.__name__ == "CompressorNode"): # for 1.1.X + node.__class__.__name__ == "CompressorNode"): # for 1.1.X yield node else: for node in self.walk_nodes(node): @@ -180,7 +181,7 @@ class Command(NoArgsCommand): """ ext_list = [] for ext in extensions: - ext_list.extend(ext.replace(' ','').split(',')) + ext_list.extend(ext.replace(' ', '').split(',')) for i, ext in enumerate(ext_list): if not ext.startswith('.'): ext_list[i] = '.%s' % ext_list[i] diff --git a/compressor/management/commands/mtime_cache.py b/compressor/management/commands/mtime_cache.py index 8dd0b95..88deab0 100644 --- a/compressor/management/commands/mtime_cache.py +++ b/compressor/management/commands/mtime_cache.py @@ -8,6 +8,7 @@ from compressor.cache import cache, get_mtime, get_mtime_cachekey from compressor.conf import settings from compressor.utils import walk + class Command(NoArgsCommand): help = "Add or remove all mtime values from the cache" option_list = NoArgsCommand.option_list + ( diff --git a/compressor/templatetags/compress.py b/compressor/templatetags/compress.py index 734bfd4..44793a4 100644 --- a/compressor/templatetags/compress.py +++ b/compressor/templatetags/compress.py @@ -7,6 +7,8 @@ from compressor.cache import cache, get_offline_cachekey from compressor.conf import settings from compressor.utils import get_class +register = template.Library() + OUTPUT_FILE = 'file' OUTPUT_INLINE = 'inline' OUTPUT_MODES = (OUTPUT_FILE, OUTPUT_INLINE) @@ -15,9 +17,8 @@ COMPRESSORS = { "js": settings.COMPRESS_JS_COMPRESSOR, } -register = template.Library() - class CompressorNode(template.Node): + def __init__(self, nodelist, kind=None, mode=OUTPUT_FILE): self.nodelist = nodelist self.kind = kind @@ -105,6 +106,7 @@ class CompressorNode(template.Node): # 5. Or don't do anything in production return self.nodelist.render(context) + @register.tag def compress(parser, token): """ diff --git a/compressor/utils/__init__.py b/compressor/utils/__init__.py index 766943c..b221a7e 100644 --- a/compressor/utils/__init__.py +++ b/compressor/utils/__init__.py @@ -1,20 +1,38 @@ # -*- coding: utf-8 -*- import os +import sys from shlex import split as cmd_split from compressor.exceptions import FilterError -try: - any = any - -except NameError: - +if sys.version_info < (2, 5): + # Add any http://docs.python.org/library/functions.html?#any to Python < 2.5 def any(seq): for item in seq: if item: return True return False +else: + any = any + + +if sys.version_info < (2, 6): + def walk(root, topdown=True, onerror=None, followlinks=False): + """ + A version of os.walk that can follow symlinks for Python < 2.6 + """ + for dirpath, dirnames, filenames in os.walk(root, topdown, onerror): + yield (dirpath, dirnames, filenames) + if followlinks: + for d in dirnames: + p = os.path.join(dirpath, d) + if os.path.islink(p): + for link_dirpath, link_dirnames, link_filenames in walk(p): + yield (link_dirpath, link_dirnames, link_filenames) +else: + from os import walk + def get_class(class_string, exception=FilterError): """ @@ -45,20 +63,6 @@ def get_mod_func(callback): return callback[:dot], callback[dot + 1:] -def walk(root, topdown=True, onerror=None, followlinks=False): - """ - A version of os.walk that can follow symlinks for Python < 2.6 - """ - for dirpath, dirnames, filenames in os.walk(root, topdown, onerror): - yield (dirpath, dirnames, filenames) - if followlinks: - for d in dirnames: - p = os.path.join(dirpath, d) - if os.path.islink(p): - for link_dirpath, link_dirnames, link_filenames in walk(p): - yield (link_dirpath, link_dirnames, link_filenames) - - def get_pathext(default_pathext=None): """ Returns the path extensions from environment or a default diff --git a/compressor/utils/stringformat.py b/compressor/utils/stringformat.py index 40c4f82..9c797b6 100644 --- a/compressor/utils/stringformat.py +++ b/compressor/utils/stringformat.py @@ -275,4 +275,4 @@ def selftest(): print 'Test successful' if __name__ == '__main__': - selftest() \ No newline at end of file + selftest()