[Checkins] SVN: z3c.language.negotiator/branches/1.0.3/ merge r115473
Adam Groszer
agroszer at gmail.com
Thu Aug 5 04:19:23 EDT 2010
Log message for revision 115479:
merge r115473
Changed:
U z3c.language.negotiator/branches/1.0.3/CHANGES.txt
U z3c.language.negotiator/branches/1.0.3/src/z3c/language/negotiator/app.py
U z3c.language.negotiator/branches/1.0.3/src/z3c/language/negotiator/tests.py
-=-
Modified: z3c.language.negotiator/branches/1.0.3/CHANGES.txt
===================================================================
--- z3c.language.negotiator/branches/1.0.3/CHANGES.txt 2010-08-05 08:17:42 UTC (rev 115478)
+++ z3c.language.negotiator/branches/1.0.3/CHANGES.txt 2010-08-05 08:19:23 UTC (rev 115479)
@@ -2,9 +2,19 @@
CHANGES
=======
-1.0.2 (unreleased)
+1.0.3 (unreleased)
------------------
+- Fixed an issue with the cache:
+ The cache just ignored the ``languages`` parameter.
+ The first request saved a specific language (e.g. ``de-de``) to the cache,
+ but the second did not have that available in ``languages``, still the cached
+ value was returned.
+ Worst case the uncached method is called.
+
+1.0.2 (2010-07-21)
+------------------
+
- backport from 1.1.1:
- added language choice caching, is by default turned off
Modified: z3c.language.negotiator/branches/1.0.3/src/z3c/language/negotiator/app.py
===================================================================
--- z3c.language.negotiator/branches/1.0.3/src/z3c/language/negotiator/app.py 2010-08-05 08:17:42 UTC (rev 115478)
+++ z3c.language.negotiator/branches/1.0.3/src/z3c/language/negotiator/app.py 2010-08-05 08:19:23 UTC (rev 115479)
@@ -111,14 +111,27 @@
def getLanguage(self, languages, request):
if self.cacheEnabled:
try:
- return request.annotations[LANGUAGE_CACHE_KEY]
+ cached = request.annotations[LANGUAGE_CACHE_KEY]
+ if cached in languages:
+ return cached
+
+ # If the user asked for a specific variation, but we don't
+ # have it available we may serve the most generic one,
+ # according to the spec (eg: user asks for ('en-us',
+ # 'de'), but we don't have 'en-us', then 'en' is preferred
+ # to 'de').
+ parts = cached.split('-')
+ if len(parts) > 1 and parts[0] in languages:
+ return parts[0]
+
+ #if there's still no match, we have to run through _getLanguage
except KeyError:
lang = self._getLanguage(languages, request)
request.annotations[LANGUAGE_CACHE_KEY] = lang
return lang
- else:
- return self._getLanguage(languages, request)
+ return self._getLanguage(languages, request)
+
def clearCache(self, request):
try:
del request.annotations[LANGUAGE_CACHE_KEY]
Modified: z3c.language.negotiator/branches/1.0.3/src/z3c/language/negotiator/tests.py
===================================================================
--- z3c.language.negotiator/branches/1.0.3/src/z3c/language/negotiator/tests.py 2010-08-05 08:17:42 UTC (rev 115478)
+++ z3c.language.negotiator/branches/1.0.3/src/z3c/language/negotiator/tests.py 2010-08-05 08:19:23 UTC (rev 115479)
@@ -142,7 +142,17 @@
self.negotiator.clearCache(env)
self.negotiator.clearCache(env)
+ #edge case, cache has a more specific language than available
+ self.negotiator.policy = 'browser'
+ env = testing.EnvStub(('de-de','de'))
+ self.assertEqual(self.negotiator.getLanguage(('de-de', 'de'), env), 'de-de')
+
+ self.assertEqual(self.negotiator.getLanguage(('de', 'en'), env), 'de')
+
+ self.negotiator.clearCache(env)
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(NegotiatorBaseTest),
More information about the checkins
mailing list