From 5ec6bb4b2783a71fda9914159438a9015f74d4d1 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Fri, 22 Jun 2018 00:27:54 +0000 Subject: [PATCH 66/67] Python 3 preparation: update string translate method call in cgi/accept_language.py. --- roundup/cgi/accept_language.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/roundup/cgi/accept_language.py b/roundup/cgi/accept_language.py index 09c06cf..919cb02 100644 --- a/roundup/cgi/accept_language.py +++ b/roundup/cgi/accept_language.py @@ -35,8 +35,13 @@ qlre = "([A-Za-z]+[-[A-Za-z]+]*);q=([\d\.]+)" # both lre = re.compile(nqlre + "|" + qlre) -ascii = ''.join([chr(x) for x in range(256)]) whitespace = ' \t\n\r\v\f' +try: + # Python 3. + remove_ws = (str.maketrans('', '', whitespace),) +except AttributeError: + # Python 2. + remove_ws = (None, whitespace) def parse(language_header): """parse(string_with_accept_header_content) -> languages list""" @@ -44,7 +49,7 @@ def parse(language_header): if language_header is None: return [] # strip whitespaces. - lh = language_header.translate(ascii, whitespace) + lh = language_header.translate(*remove_ws) # if nothing, return if lh == "": return [] -- 2.7.4