def get_filepath(self, content, basename=None): parts = [] if basename: filename = os.path.split(basename)[1] parts.append(os.path.splitext(filename)[0]) parts.extend([get_hexdigest(content, 12), self.type]) return os.path.join(self.output_dir, self.output_prefix, '.'.join(parts))
def test_filename_in_debug_mode(self): # In debug mode, compressor should look for files using staticfiles # finders only, and not look into the global static directory, where # files can be outdated css_filename = os.path.join(settings.COMPRESS_ROOT, "css", "one.css") # Store the hash of the original file's content with open(css_filename) as f: css_content = f.read() hashed = get_hexdigest(css_content, 12) # Now modify the file in the STATIC_ROOT test_css_content = "p { font-family: 'test' }" with open(css_filename, "a") as css: css.write("\n") css.write(test_css_content) # We should generate a link with the hash of the original content, not # the modified one expected = '<link rel="stylesheet" href="/static/CACHE/css/%s.css" type="text/css" />' % hashed compressor = CssCompressor(self.css) compressor.storage = DefaultStorage() output = compressor.output() self.assertEqual(expected, output) with open(os.path.join(settings.COMPRESS_ROOT, "CACHE", "css", "%s.css" % hashed), "r") as f: result = f.read() self.assertTrue(test_css_content not in result)
def get_filepath(self, content, basename=None): """ Returns file path for an output file based on contents. Returned path is relative to compressor storage's base url, for example "CACHE/css/58a8c0714e59.css". When `basename` argument is provided then file name (without extension) will be used as a part of returned file name, for example: get_filepath(content, "my_file.css") -> 'CACHE/css/my_file.58a8c0714e59.css' """ parts = [] if basename: filename = os.path.split(basename)[1] parts.append(os.path.splitext(filename)[0]) parts.extend([get_hexdigest(content, 12), self.type]) return os.path.join(self.output_dir, self.output_prefix, ".".join(parts))
def get_filepath(self, content, basename=None): """ Returns file path for an output file based on contents. Returned path is relative to compressor storage's base url, for example "CACHE/css/58a8c0714e59.css". When `basename` argument is provided then file name (without extension) will be used as a part of returned file name, for example: get_filepath(content, "my_file.css") -> 'CACHE/css/my_file.58a8c0714e59.css' """ parts = [] if basename: filename = os.path.split(basename)[1] parts.append(os.path.splitext(filename)[0]) parts.extend([get_hexdigest(content, 12), self.type]) return os.path.join(self.output_dir, self.output_prefix, '.'.join(parts))
def add_suffix(self, url): filename = self.guess_filename(url) suffix = None if filename: if settings.COMPRESS_CSS_HASHING_METHOD == "mtime": suffix = get_hashed_mtime(filename) elif settings.COMPRESS_CSS_HASHING_METHOD == "hash": hash_file = open(filename) try: suffix = get_hexdigest(hash_file.read(), 12) finally: hash_file.close() else: raise FilterError('COMPRESS_CSS_HASHING_METHOD is configured ' 'with an unknown method (%s).') if suffix is None: return url if url.startswith(('http://', 'https://', '/')): if "?" in url: url = "%s&%s" % (url, suffix) else: url = "%s?%s" % (url, suffix) return url
def cachekey(self): key = get_hexdigest(''.join( [self.content] + self.mtimes).encode(self.charset), 12) return "django_compressor.%s.%s" % (socket.gethostname(), key)
def hash(self, content): return get_hexdigest(content)[:12]
def cachekey(self): cachestr = "".join(chain([self.content], self.mtimes)).encode(self.charset) return "django_compressor.%s.%s" % (socket.gethostname(), get_hexdigest(cachestr)[:12])
def cachekey(self): key = get_hexdigest( ''.join([self.content] + self.mtimes).encode(self.charset), 12) return "django_compressor.%s.%s" % (socket.gethostname(), key)
def cachekey(self): return get_hexdigest( ''.join([self.content] + self.mtimes).encode(self.charset), 12)
def hash(self): return get_hexdigest(self.concat)[:12]
def cachekey(self): return get_hexdigest("".join([self.content] + self.mtimes).encode(self.charset), 12)
def get_filepath(self, content): filename = "%s.%s" % (get_hexdigest(content, 12), self.type) return os.path.join(self.output_dir, self.output_prefix, filename)
def get_hash(self, filename, length=12): mtime = str(cache.get_mtime(filename)) return cache.get_hexdigest(mtime + filename, length=length)
def filepath(self, content): return os.path.join( settings.COMPRESS_OUTPUT_DIR.strip(os.sep), self.output_prefix, "%s.%s" % (get_hexdigest(content, 12), self.type), )
def hash(self): return get_hexdigest(self.combined)[:12]
def filepath(self, content): return os.path.join(settings.COMPRESS_OUTPUT_DIR.strip(os.sep), self.output_prefix, "%s.%s" % (get_hexdigest(content, 12), self.type))
def cachekey(self): cachestr = "".join( chain([self.content], self.mtimes)).encode(self.charset) return "django_compressor.%s.%s" % (socket.gethostname(), get_hexdigest(cachestr)[:12])
def test_css_hash(self): self.assertEqual('c618e6846d04', get_hexdigest(self.css, 12))