Skip to content

Commit

Permalink
encoding stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
jharshman committed Jan 11, 2024
1 parent 342dec0 commit b1c225d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions assetman/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ def version_dependency(path, manifest):
if manifest.assets[path]['version']:
return manifest.assets[path]['version']
h = hashlib.md5()
h.update(get_file_hash(make_absolute_static_path(manifest.settings['static_dir'], path)))
h.update(get_file_hash(make_absolute_static_path(manifest.settings['static_dir'], path)).encode())
for dep_path in manifest.assets[path]['deps']:
h.update(version_dependency(dep_path, manifest))
h.update(version_dependency(dep_path, manifest).encode())
version = h.hexdigest()
_, ext = os.path.splitext(path)
manifest.assets[path]['version'] = version
Expand Down
2 changes: 1 addition & 1 deletion assetman/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get_current_content_hash(self, manifest):
for path in self.get_paths():
relative_path = make_relative_static_path(self.settings['static_dir'], path)
assert relative_path in manifest.assets, relative_path
h.update(manifest.assets[relative_path]['version'])
h.update(manifest.assets[relative_path]['version'].encode())
return h.hexdigest()

def get_paths(self):
Expand Down
2 changes: 1 addition & 1 deletion assetman/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_hash(self):
"""Gets the md5 hash for the URLs in this block of assets, which will
be used to refer to the compiled assets in production.
"""
return hashlib.md5('\n'.join(self.rel_urls)).hexdigest()
return hashlib.md5('\n'.join(self.rel_urls).encode()).hexdigest()

def get_ext(self):
"""Returns the file extension (without leading period) to use for the
Expand Down
10 changes: 9 additions & 1 deletion assetman/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ def _crc(key):
def _utf8(s):
"""encode a unicode string as utf-8"""
if isinstance(s, str):
return s.encode("utf-8")
return s.encode("utf-8").decode()
if isinstance(s, bytes):
return s.decode("utf-8")
assert isinstance(s, str), "_utf8 expected a str, not %r" % type(s)
return s
#def _utf8(s):
# """encode a unicode string as utf-8"""
# if isinstance(s, str):
# return s.encode("utf-8")
# assert isinstance(s, str), "_utf8 expected a str, not %r" % type(s)
# return s

def iter_template_paths(template_dirs, template_ext):
"""Walks each directory in the given list of template directories,
Expand Down

0 comments on commit b1c225d

Please sign in to comment.