From 304d719750b4e1243076e51d756a2e2144088915 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Fri, 13 May 2011 12:06:07 +0200 Subject: [PATCH] Use MD5 instead of SHA1 to reduce the computational impact. --- .gitignore | 2 +- compressor/cache.py | 4 ++-- compressor/tests/tests.py | 32 ++++++++++++++++---------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 3780c1e..4efafd4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ build compressor/tests/media/CACHE compressor/tests/media/custom -compressor/tests/media/js/3f33b9146e12.js +compressor/tests/media/js/066cd253eada.js dist MANIFEST *.pyc diff --git a/compressor/cache.py b/compressor/cache.py index e53f4b8..ebd5689 100644 --- a/compressor/cache.py +++ b/compressor/cache.py @@ -3,13 +3,13 @@ import socket from django.core.cache import get_cache from django.utils.encoding import smart_str -from django.utils.hashcompat import sha_constructor +from django.utils.hashcompat import md5_constructor from compressor.conf import settings def get_hexdigest(plaintext, length=None): - digest = sha_constructor(smart_str(plaintext)).hexdigest() + digest = md5_constructor(smart_str(plaintext)).hexdigest() if length: return digest[:length] return digest diff --git a/compressor/tests/tests.py b/compressor/tests/tests.py index 76ff392..9acabe9 100644 --- a/compressor/tests/tests.py +++ b/compressor/tests/tests.py @@ -91,10 +91,10 @@ class CompressorTestCase(TestCase): self.assert_(is_cachekey.match(self.css_node.cachekey), "cachekey is returning something that doesn't look like r'django_compressor\.%s\.\w{12}'" % host_name) def test_css_hash(self): - self.assertEqual('666f3aa8eacd', get_hexdigest(self.css, 12)) + self.assertEqual('c618e6846d04', get_hexdigest(self.css, 12)) def test_css_return_if_on(self): - output = u'' + output = u'' self.assertEqual(output, self.css_node.output().strip()) def test_js_split(self): @@ -129,20 +129,20 @@ class CompressorTestCase(TestCase): settings.COMPRESS_PRECOMPILERS = precompilers def test_js_return_if_on(self): - output = u'' + output = u'' self.assertEqual(output, self.js_node.output()) def test_custom_output_dir(self): try: old_output_dir = settings.COMPRESS_OUTPUT_DIR settings.COMPRESS_OUTPUT_DIR = 'custom' - output = u'' + output = u'' self.assertEqual(output, JsCompressor(self.js).output()) settings.COMPRESS_OUTPUT_DIR = '' - output = u'' + output = u'' self.assertEqual(output, JsCompressor(self.js).output()) settings.COMPRESS_OUTPUT_DIR = '/custom/nested/' - output = u'' + output = u'' self.assertEqual(output, JsCompressor(self.js).output()) finally: settings.COMPRESS_OUTPUT_DIR = old_output_dir @@ -340,7 +340,7 @@ class TemplatetagTestCase(TestCase): {% endcompress %} """ context = { 'MEDIA_URL': settings.COMPRESS_URL } - out = u'' + out = u'' self.assertEqual(out, render(template, context)) def test_nonascii_css_tag(self): @@ -350,7 +350,7 @@ class TemplatetagTestCase(TestCase): {% endcompress %} """ context = { 'MEDIA_URL': settings.COMPRESS_URL } - out = '' + out = '' self.assertEqual(out, render(template, context)) def test_js_tag(self): @@ -360,7 +360,7 @@ class TemplatetagTestCase(TestCase): {% endcompress %} """ context = { 'MEDIA_URL': settings.COMPRESS_URL } - out = u'' + out = u'' self.assertEqual(out, render(template, context)) def test_nonascii_js_tag(self): @@ -370,7 +370,7 @@ class TemplatetagTestCase(TestCase): {% endcompress %} """ context = { 'MEDIA_URL': settings.COMPRESS_URL } - out = u'' + out = u'' self.assertEqual(out, render(template, context)) def test_nonascii_latin1_js_tag(self): @@ -380,7 +380,7 @@ class TemplatetagTestCase(TestCase): {% endcompress %} """ context = { 'MEDIA_URL': settings.COMPRESS_URL } - out = u'' + out = u'' self.assertEqual(out, render(template, context)) def test_compress_tag_with_illegal_arguments(self): @@ -419,7 +419,7 @@ class StorageTestCase(TestCase): {% endcompress %} """ context = { 'MEDIA_URL': settings.COMPRESS_URL } - out = u'' + out = u'' self.assertEqual(out, render(template, context)) @@ -452,8 +452,8 @@ class OfflineGenerationTestCase(TestCase): count, result = CompressCommand().compress() self.assertEqual(2, count) self.assertEqual([ - u'\n', - u'', + u'\n', + u'', ], result) def test_offline_with_context(self): @@ -464,8 +464,8 @@ class OfflineGenerationTestCase(TestCase): count, result = CompressCommand().compress() self.assertEqual(2, count) self.assertEqual([ - u'\n', - u'', + u'\n', + u'', ], result) settings.COMPRESS_OFFLINE_CONTEXT = self._old_offline_context