--- a/src/pyams_utils/i18n.py Wed Jun 12 20:06:45 2019 +0200
+++ b/src/pyams_utils/i18n.py Fri Jun 14 12:41:06 2019 +0200
@@ -10,12 +10,15 @@
# FOR A PARTICULAR PURPOSE.
#
+"""I18n module used to get browser language from request"""
+
__docformat__ = 'restructuredtext'
import locale
def normalize_lang(lang):
+ """Normalize input languages string"""
lang = lang.strip().lower()
lang = lang.replace('_', '-')
lang = lang.replace(' ', '')
@@ -36,17 +39,17 @@
accepts = []
for index, lang in enumerate(accept_langs):
- l = lang.split(';', 2)
+ lang_item = lang.split(';', 2)
# If not supplied, quality defaults to 1...
quality = 1.0
- if len(l) == 2:
- q = l[1]
- if q.startswith('q='):
- q = q.split('=', 2)[1]
+ if len(lang_item) == 2:
+ qual = lang_item[1]
+ if qual.startswith('q='):
+ qual = qual.split('=', 2)[1]
try:
- quality = float(q)
+ quality = float(qual)
except ValueError:
# malformed quality value, skip it.
continue
@@ -58,7 +61,7 @@
# defined, and items with quality defined as 1.
quality = 1.9 - (0.001 * index)
- accepts.append((quality, l[0]))
+ accepts.append((quality, lang_item[0]))
# Filter langs with q=0, which means
# unwanted lang according to the spec
@@ -68,7 +71,7 @@
accepts.sort()
accepts.reverse()
- return [lang for qual, lang in accepts][0] if accepts else None
+ return [lang for _, lang in accepts][0] if accepts else None
def set_locales(config):