More constants.

This commit is contained in:
Jannis Leidel
2011-05-13 11:51:17 +02:00
parent 6b3401dc63
commit 463ca0336d

View File

@@ -14,6 +14,7 @@ from compressor.utils.decorators import cached_property
# Some constants for nicer handling.
SOURCE_HUNK, SOURCE_FILE = 1, 2
METHOD_INPUT, METHOD_OUTPUT = 'input', 'output'
class Compressor(object):
@@ -83,7 +84,7 @@ class Compressor(object):
def mtimes(self):
return [str(get_mtime(value))
for kind, value, basename, elem in self.split_contents()
if kind == 'file']
if kind == SOURCE_FILE]
@cached_property
def cachekey(self):
@@ -95,7 +96,7 @@ class Compressor(object):
def hunks(self):
for kind, value, basename, elem in self.split_contents():
if kind == SOURCE_HUNK:
content = self.filter(value, "input",
content = self.filter(value, METHOD_INPUT,
elem=elem, kind=kind, basename=basename)
yield unicode(content)
elif kind == SOURCE_FILE:
@@ -108,7 +109,7 @@ class Compressor(object):
"IOError while processing '%s': %s" % (value, e))
finally:
fd.close()
content = self.filter(content, "input",
content = self.filter(content, METHOD_INPUT,
filename=value, basename=basename, elem=elem, kind=kind)
attribs = self.parser.elem_attribs(elem)
charset = attribs.get("charset", self.charset)
@@ -138,7 +139,7 @@ class Compressor(object):
def filter(self, content, method, **kwargs):
# run compiler
if method == "input":
if method == METHOD_INPUT:
content = self.precompile(content, **kwargs)
for filter_cls in self.cached_filters:
@@ -153,10 +154,10 @@ class Compressor(object):
@cached_property
def combined(self):
return self.filter(self.concat, method="output")
def hash(self, content):
return get_hexdigest(content)[:12]
return self.filter(self.concat, method=METHOD_OUTPUT)
def filepath(self, content):
return os.path.join(settings.COMPRESS_OUTPUT_DIR.strip(os.sep),