Fixed PEP8 issues.

This commit is contained in:
Jannis Leidel
2011-10-07 17:46:40 +02:00
parent b2b8708920
commit 37440d6cd3
3 changed files with 14 additions and 11 deletions

View File

@@ -36,7 +36,8 @@ def get_cachekey(*args, **kwargs):
global _cachekey_func
if _cachekey_func is None:
try:
mod_name, func_name = get_mod_func(settings.COMPRESS_CACHE_KEY_FUNCTION)
mod_name, func_name = get_mod_func(
settings.COMPRESS_CACHE_KEY_FUNCTION)
_cachekey_func = getattr(import_module(mod_name), func_name)
except (AttributeError, ImportError), e:
raise ImportError("Couldn't import cache key function %s: %s" %
@@ -47,9 +48,11 @@ def get_cachekey(*args, **kwargs):
def get_mtime_cachekey(filename):
return get_cachekey("mtime.%s" % get_hexdigest(filename))
def get_offline_hexdigest(source):
return get_hexdigest([smart_str(getattr(s, 's', s)) for s in source])
def get_offline_cachekey(source):
return get_cachekey("offline.%s" % get_offline_hexdigest(source))
@@ -58,6 +61,7 @@ def get_offline_manifest_filename():
output_dir = settings.COMPRESS_OUTPUT_DIR.strip('/')
return os.path.join(output_dir, 'manifest.json')
def get_offline_manifest():
filename = get_offline_manifest_filename()
if default_storage.exists(filename):
@@ -65,11 +69,13 @@ def get_offline_manifest():
else:
return {}
def write_offline_manifest(manifest):
filename = get_offline_manifest_filename()
default_storage.save(filename,
ContentFile(simplejson.dumps(manifest, indent=2)))
def get_templatetag_cachekey(compressor, mode, kind):
return get_cachekey(
"templatetag.%s.%s.%s" % (compressor.cachekey, mode, kind))

View File

@@ -13,7 +13,6 @@ from django.core.management.base import NoArgsCommand, CommandError
from django.template import Context, Template, TemplateDoesNotExist, TemplateSyntaxError
from django.utils.datastructures import SortedDict
from django.utils.importlib import import_module
from django.template.loader import get_template
from django.template.loader_tags import ExtendsNode, BlockNode, BLOCK_CONTEXT_KEY
try:
@@ -21,7 +20,7 @@ try:
except ImportError:
CachedLoader = None
from compressor.cache import cache, get_offline_hexdigest, write_offline_manifest
from compressor.cache import get_offline_hexdigest, write_offline_manifest
from compressor.conf import settings
from compressor.exceptions import OfflineGenerationError
from compressor.templatetags.compress import CompressorNode
@@ -256,4 +255,3 @@ class Command(NoArgsCommand):
"Offline compressiong is disabled. Set "
"COMPRESS_OFFLINE or use the --force to override.")
self.compress(sys.stdout, **options)

View File

@@ -1,9 +1,8 @@
from django import template
from django.core.exceptions import ImproperlyConfigured
from compressor.cache import (cache, cache_get, cache_set,
get_offline_hexdigest, get_offline_manifest,
get_templatetag_cachekey)
from compressor.cache import (cache_get, cache_set, get_offline_hexdigest,
get_offline_manifest, get_templatetag_cachekey)
from compressor.conf import settings
from compressor.exceptions import OfflineGenerationError
from compressor.utils import get_class
@@ -14,6 +13,7 @@ OUTPUT_FILE = 'file'
OUTPUT_INLINE = 'inline'
OUTPUT_MODES = (OUTPUT_FILE, OUTPUT_INLINE)
class CompressorNode(template.Node):
def __init__(self, nodelist, kind=None, mode=OUTPUT_FILE, name=None):
@@ -23,7 +23,7 @@ class CompressorNode(template.Node):
self.name = name
def compressor_cls(self, *args, **kwargs):
compressors = {
compressors = {
"css": settings.COMPRESS_CSS_COMPRESSOR,
"js": settings.COMPRESS_JS_COMPRESSOR,
}
@@ -55,7 +55,6 @@ class CompressorNode(template.Node):
else:
raise OfflineGenerationError('You have offline compression enabled but key "%s" is missing from offline manifest. You may need to run "python manage.py compress".' % key)
def render_cached(self, compressor, forced):
"""
If enabled checks the cache for the given compressor's cache key
@@ -74,7 +73,7 @@ class CompressorNode(template.Node):
return self.nodelist.render(context)
# Prepare the compressor
context.update({'name': self.name})
context.update({'name': self.name})
compressor = self.compressor_cls(content=self.nodelist.render(context),
context=context)
@@ -82,7 +81,7 @@ class CompressorNode(template.Node):
cached_offline = self.render_offline(compressor, forced)
if cached_offline:
return cached_offline
# Check cache
cache_key, cache_content = self.render_cached(compressor, forced)
if cache_content is not None: