mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-26 23:39:11 -05:00
generate_static_names: Fix case where no base specified.
This commit is contained in:
@@ -6,13 +6,17 @@ import json
|
||||
import base64
|
||||
import shutil
|
||||
|
||||
def generate_static_name(name, base=None, shorthash=None):
|
||||
def generate_static_name(name, base=None):
|
||||
"""Generate a unique filename.
|
||||
|
||||
Unique filenames are generated by base 64 encoding the first 64 bits of
|
||||
the SHA1 hash. This hash string is added to the filename before the extension.
|
||||
"""
|
||||
if base: path = os.path.join(base, name)
|
||||
if base:
|
||||
path = os.path.join(base, name)
|
||||
else:
|
||||
path = name
|
||||
|
||||
sha = hashlib.sha1(open(path).read()).digest()
|
||||
shorthash = base64.urlsafe_b64encode(sha[0:8]).rstrip("=")
|
||||
name, ext = os.path.splitext(name)
|
||||
|
||||
Reference in New Issue
Block a user