(self, name, content=None, filename=None)
| 140 | return hasher.hexdigest()[:12] |
| 141 | |
| 142 | def hashed_name(self, name, content=None, filename=None): |
| 143 | # `filename` is the name of file to hash if `content` isn't given. |
| 144 | # `name` is the base name to construct the new hashed filename from. |
| 145 | parsed_name = urlsplit(unquote(name)) |
| 146 | clean_name = parsed_name.path.strip() |
| 147 | filename = (filename and urlsplit(unquote(filename)).path.strip()) or clean_name |
| 148 | opened = content is None |
| 149 | if opened: |
| 150 | if not self.exists(filename): |
| 151 | raise ValueError( |
| 152 | "The file '%s' could not be found with %r." % (filename, self) |
| 153 | ) |
| 154 | try: |
| 155 | content = self.open(filename) |
| 156 | except OSError: |
| 157 | # Handle directory paths and fragments |
| 158 | return name |
| 159 | try: |
| 160 | file_hash = self.file_hash(clean_name, content) |
| 161 | finally: |
| 162 | if opened: |
| 163 | content.close() |
| 164 | path, filename = os.path.split(clean_name) |
| 165 | root, ext = os.path.splitext(filename) |
| 166 | file_hash = (".%s" % file_hash) if file_hash else "" |
| 167 | hashed_name = os.path.join(path, "%s%s%s" % (root, file_hash, ext)) |
| 168 | unparsed_name = list(parsed_name) |
| 169 | unparsed_name[2] = hashed_name |
| 170 | # Special casing for a @font-face hack, like url(myfont.eot?#iefix") |
| 171 | # http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax |
| 172 | if "?#" in name and not unparsed_name[3]: |
| 173 | unparsed_name[2] += "?" |
| 174 | return urlunsplit(unparsed_name) |
| 175 | |
| 176 | def _url(self, hashed_name_func, name, force=False, hashed_files=None): |
| 177 | """ |
no test coverage detected