def add_suffix(self, url): filename = self.guess_filename(url) if not filename: return url if settings.COMPRESS_CSS_HASHING_METHOD is None: return url if not url.startswith(SCHEMES): return url suffix = None if settings.COMPRESS_CSS_HASHING_METHOD == "mtime": suffix = get_hashed_mtime(filename) elif settings.COMPRESS_CSS_HASHING_METHOD in ("hash", "content"): suffix = get_hashed_content(filename) else: raise FilterError('COMPRESS_CSS_HASHING_METHOD is configured ' 'with an unknown method (%s).' % settings.COMPRESS_CSS_HASHING_METHOD) fragment = None if "#" in url: url, fragment = url.rsplit("#", 1) if "?" in url: url = "%s&%s" % (url, suffix) else: url = "%s?%s" % (url, suffix) if fragment is not None: url = "%s#%s" % (url, fragment) return url
class YUICompressorFilter(FilterBase): def output(self, **kwargs): arguments = '' if self.type == 'js': arguments = settings.YUI_JS_ARGUMENTS if self.type == 'css': arguments = settings.YUI_CSS_ARGUMENTS command = '%s --type=%s %s' % (settings.YUI_BINARY, self.type, arguments) if self.verbose: command += ' --verbose' try: p = Popen(cmd_split(command), stdin=PIPE, stdout=PIPE, stderr=PIPE) filtered, err = p.communicate(self.content) except IOError, e: raise FilterError(e) if p.wait() != 0: if not err: err = 'Unable to apply YUI Compressor filter' raise FilterError(err) if self.verbose: print err return filtered
def output(self, **kwargs): command = '%s %s %s' % (BINARY, '-', ARGUMENTS) p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) p.stdin.write(self.content) p.stdin.close() filtered = p.stdout.read() p.stdout.close() err = p.stderr.read() p.stderr.close() if p.wait() != 0: if not err: err = 'Unable to apply CSSTidy filter' raise FilterError(err) if self.verbose: print err return filtered
def output(self, **kwargs): arguments = '' if self.type == 'js': arguments = JS_ARGUMENTS if self.type == 'css': arguments = CSS_ARGUMENTS command = '%s --type=%s %s' % (BINARY, self.type, arguments) if self.verbose: command += ' --verbose' p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) p.stdin.write(self.content) p.stdin.close() filtered = p.stdout.read() p.stdout.close() err = p.stderr.read() p.stderr.close() if p.wait() != 0: if not err: err = 'Unable to apply YUI Compressor filter' raise FilterError(err) if self.verbose: print err return filtered
def output(self, **kwargs): arguments = settings.CLOSURE_COMPILER_ARGUMENTS command = '%s %s' % (settings.CLOSURE_COMPILER_BINARY, arguments) try: p = Popen(cmd_split(command), stdout=PIPE, stdin=PIPE, stderr=PIPE) filtered, err = p.communicate(self.content) except IOError, e: raise FilterError(e)
def output(self, **kwargs): arguments = '' if self.type == 'js': arguments = settings.COMPRESS_YUI_JS_ARGUMENTS elif self.type == 'css': arguments = settings.COMPRESS_YUI_CSS_ARGUMENTS command = '%s --type=%s %s' % (settings.COMPRESS_YUI_BINARY, self.type, arguments) if self.verbose: command += ' --verbose' try: p = Popen(cmd_split(command), stdin=PIPE, stdout=PIPE, stderr=PIPE) filtered, err = p.communicate(self.content) except IOError, e: raise FilterError(e)
class ClosureCompilerFilter(FilterBase): def output(self, **kwargs): arguments = settings.CLOSURE_COMPILER_ARGUMENTS command = '%s %s' % (settings.CLOSURE_COMPILER_BINARY, arguments) try: p = Popen(cmd_split(command), stdout=PIPE, stdin=PIPE, stderr=PIPE) filtered, err = p.communicate(self.content) except IOError, e: raise FilterError(e) if p.wait() != 0: if not err: err = 'Unable to apply Closure Compiler filter' raise FilterError(err) if self.verbose: print err return filtered
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