Fix make_safe_filename() to work with unicode strings.

This commit is contained in:
Neil Schemenauer 2016-04-04 17:47:00 +00:00
parent 77ff7b370d
commit 7f7620e7f4
1 changed files with 3 additions and 10 deletions

View File

@ -621,18 +621,11 @@ def parse_cookies(text):
result[name] = value
return result
SAFE_CHARS = string.ascii_letters + string.digits + "-@&+=_., "
_safe_trans = None
# characters considered safe in a filename
_SAFE_PAT = re.compile(r'[^\w@&+=., -]')
def make_safe_filename(s):
global _safe_trans
if _safe_trans is None:
_safe_trans = ["_"] * 256
for c in SAFE_CHARS:
_safe_trans[ord(c)] = c
_safe_trans = "".join(_safe_trans)
return s.translate(_safe_trans)
return _SAFE_PAT.sub('_', s)
class Upload: