Example #1
0
 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))
Example #2
0
 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)
Example #3
0
 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))
Example #4
0
    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))
Example #6
0
 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
Example #7
0
 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
Example #8
0
 def cachekey(self):
     key = get_hexdigest(''.join(
         [self.content] + self.mtimes).encode(self.charset), 12)
     return "django_compressor.%s.%s" % (socket.gethostname(), key)
Example #9
0
 def hash(self, content):
     return get_hexdigest(content)[:12]
Example #10
0
 def cachekey(self):
     cachestr = "".join(chain([self.content],
                              self.mtimes)).encode(self.charset)
     return "django_compressor.%s.%s" % (socket.gethostname(),
                                         get_hexdigest(cachestr)[:12])
Example #11
0
 def cachekey(self):
     key = get_hexdigest(
         ''.join([self.content] + self.mtimes).encode(self.charset), 12)
     return "django_compressor.%s.%s" % (socket.gethostname(), key)
Example #12
0
 def hash(self, content):
     return get_hexdigest(content)[:12]
Example #13
0
 def cachekey(self):
     return get_hexdigest(
         ''.join([self.content] + self.mtimes).encode(self.charset), 12)
Example #14
0
 def hash(self):
     return get_hexdigest(self.concat)[:12]
Example #15
0
 def cachekey(self):
     return get_hexdigest("".join([self.content] + self.mtimes).encode(self.charset), 12)
Example #16
0
 def hash(self):
     return get_hexdigest(self.concat)[:12]
Example #17
0
 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)
Example #18
0
 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)
Example #19
0
 def get_hash(self, filename, length=12):
     mtime = str(cache.get_mtime(filename))
     return cache.get_hexdigest(mtime + filename, length=length)
Example #20
0
 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),
     )
Example #21
0
 def hash(self):
     return get_hexdigest(self.combined)[:12]
Example #22
0
 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))
Example #23
0
 def cachekey(self):
     cachestr = "".join(
         chain([self.content], self.mtimes)).encode(self.charset)
     return "django_compressor.%s.%s" % (socket.gethostname(),
                                         get_hexdigest(cachestr)[:12])
Example #24
0
 def test_css_hash(self):
     self.assertEqual('c618e6846d04', get_hexdigest(self.css, 12))
Example #25
0
 def test_css_hash(self):
     self.assertEqual('c618e6846d04', get_hexdigest(self.css, 12))