diff options
| author | Sergey Schetinin <sergey@maluke.com> | 2010-08-11 06:50:23 +0300 |
|---|---|---|
| committer | Sergey Schetinin <sergey@maluke.com> | 2010-08-11 06:50:23 +0300 |
| commit | c73cd681b7bb97914f873ace39f70bd59df2289c (patch) | |
| tree | 116721f625fdd0455203907355e3a31a84708c4a /webob/acceptparse.py | |
| parent | bc6db627670732158cb401d2cc8dc526b3c54f3e (diff) | |
| download | webob-c73cd681b7bb97914f873ace39f70bd59df2289c.tar.gz | |
accept-language:
* add prefix matching http://trac.pythonpaste.org/pythonpaste/ticket/393
* best_match(fallback) should add fallback as it was passed, not how it was specified in the request
Diffstat (limited to 'webob/acceptparse.py')
| -rw-r--r-- | webob/acceptparse.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/webob/acceptparse.py b/webob/acceptparse.py index 058e59d..2d761de 100644 --- a/webob/acceptparse.py +++ b/webob/acceptparse.py @@ -56,6 +56,8 @@ class Accept(object): break else: self._parsed.append(('iso-8859-1', 1)) + elif header_name == 'Accept-Language': + self._match = self._match_lang def __repr__(self): @@ -185,12 +187,11 @@ class Accept(object): Return all the matches in order of quality, with fallback (if given) at the end. """ - items = [i for i, q - in sorted(self._parsed, key=lambda iq: -iq[1])] + items = [i for i, q in sorted(self._parsed, key=lambda iq: -iq[1])] if fallback: for index, item in enumerate(items): if self._match(item, fallback): - items[index+1:] = [] + items[index:] = [fallback] break else: items.append(fallback) @@ -199,6 +200,12 @@ class Accept(object): def _match(self, mask, item): return mask == '*' or item.lower() == mask.lower() + def _match_lang(self, mask, item): + return (mask == '*' + or item.lower() == mask.lower() + or item.lower().split('-')[0] == mask.lower() + ) + class NilAccept(object): |
