This commit is contained in:
@@ -17,7 +17,7 @@ from compressor.filters import CompilerFilter
|
|||||||
from compressor.storage import default_storage, compressor_file_storage
|
from compressor.storage import default_storage, compressor_file_storage
|
||||||
from compressor.signals import post_compress
|
from compressor.signals import post_compress
|
||||||
from compressor.utils import get_class, staticfiles
|
from compressor.utils import get_class, staticfiles
|
||||||
from compressor.utils.decorators import cached_property, memoize
|
from compressor.utils.decorators import cached_property
|
||||||
|
|
||||||
# Some constants for nicer handling.
|
# Some constants for nicer handling.
|
||||||
SOURCE_HUNK, SOURCE_FILE = 'inline', 'file'
|
SOURCE_HUNK, SOURCE_FILE = 'inline', 'file'
|
||||||
@@ -119,7 +119,6 @@ class Compressor(object):
|
|||||||
return get_hexdigest(''.join(
|
return get_hexdigest(''.join(
|
||||||
[self.content] + self.mtimes).encode(self.charset), 12)
|
[self.content] + self.mtimes).encode(self.charset), 12)
|
||||||
|
|
||||||
@memoize
|
|
||||||
def hunks(self, mode='file', forced=False):
|
def hunks(self, mode='file', forced=False):
|
||||||
"""
|
"""
|
||||||
The heart of content parsing, iterates of the
|
The heart of content parsing, iterates of the
|
||||||
@@ -157,7 +156,6 @@ class Compressor(object):
|
|||||||
else:
|
else:
|
||||||
yield mode, self.parser.elem_str(elem)
|
yield mode, self.parser.elem_str(elem)
|
||||||
|
|
||||||
@memoize
|
|
||||||
def filtered_output(self, content):
|
def filtered_output(self, content):
|
||||||
"""
|
"""
|
||||||
Passes the concatenated content to the 'output' methods
|
Passes the concatenated content to the 'output' methods
|
||||||
@@ -165,7 +163,6 @@ class Compressor(object):
|
|||||||
"""
|
"""
|
||||||
return self.filter(content, method=METHOD_OUTPUT)
|
return self.filter(content, method=METHOD_OUTPUT)
|
||||||
|
|
||||||
@memoize
|
|
||||||
def filtered_input(self, mode='file', forced=False):
|
def filtered_input(self, mode='file', forced=False):
|
||||||
"""
|
"""
|
||||||
Passes each hunk (file or code) to the 'input' methods
|
Passes each hunk (file or code) to the 'input' methods
|
||||||
@@ -267,6 +264,7 @@ class Compressor(object):
|
|||||||
final_context.update(self.context)
|
final_context.update(self.context)
|
||||||
final_context.update(context)
|
final_context.update(context)
|
||||||
final_context.update(self.extra_context)
|
final_context.update(self.extra_context)
|
||||||
post_compress.send(sender='django-compressor', type=self.type, mode=mode, context=final_context)
|
post_compress.send(sender='django-compressor', type=self.type,
|
||||||
|
mode=mode, context=final_context)
|
||||||
return render_to_string("compressor/%s_%s.html" %
|
return render_to_string("compressor/%s_%s.html" %
|
||||||
(self.type, mode), final_context)
|
(self.type, mode), final_context)
|
||||||
|
|||||||
@@ -1,31 +1,3 @@
|
|||||||
import functools
|
|
||||||
|
|
||||||
class memoize(object):
|
|
||||||
|
|
||||||
def __init__ (self, func):
|
|
||||||
self.func = func
|
|
||||||
|
|
||||||
def __call__ (self, *args, **kwargs):
|
|
||||||
if (args, str(kwargs)) in self.__dict__:
|
|
||||||
value = self.__dict__[args, str(kwargs)]
|
|
||||||
else:
|
|
||||||
value = self.func(*args, **kwargs)
|
|
||||||
self.__dict__[args, str(kwargs)] = value
|
|
||||||
return value
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
"""
|
|
||||||
Return the function's docstring.
|
|
||||||
"""
|
|
||||||
return self.func.__doc__ or ''
|
|
||||||
|
|
||||||
def __get__(self, obj, objtype):
|
|
||||||
"""
|
|
||||||
Support instance methods.
|
|
||||||
"""
|
|
||||||
return functools.partial(self.__call__, obj)
|
|
||||||
|
|
||||||
|
|
||||||
class cached_property(object):
|
class cached_property(object):
|
||||||
"""Property descriptor that caches the return value
|
"""Property descriptor that caches the return value
|
||||||
of the get function.
|
of the get function.
|
||||||
|
|||||||
Reference in New Issue
Block a user