From 7f7620e7f4116de05219e5a582ef8f833c1313c5 Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Mon, 4 Apr 2016 17:47:00 +0000 Subject: [PATCH] Fix make_safe_filename() to work with unicode strings. --- quixote/http_request.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/quixote/http_request.py b/quixote/http_request.py index 403bccc..4a45cb5 100644 --- a/quixote/http_request.py +++ b/quixote/http_request.py @@ -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: