[Python-checkins] r85225 - in python/branches/release27-maint: Lib/gettext.py Lib/test/test_gettext.py Misc/NEWS

eric.araujo python-checkins at python.org
Tue Oct 5 01:59:35 CEST 2010


Author: eric.araujo
Date: Tue Oct 5 01:59:35 2010
New Revision: 85225
Log:
Merged revisions 85223 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
 r85223 | eric.araujo | 2010年10月05日 01:52:37 +0200 (mar., 05 oct. 2010) | 3 lines
 
 Fix interaction of custom translation classes and caching (#9042)
........
Modified:
 python/branches/release27-maint/ (props changed)
 python/branches/release27-maint/Lib/gettext.py
 python/branches/release27-maint/Lib/test/test_gettext.py
 python/branches/release27-maint/Misc/NEWS
Modified: python/branches/release27-maint/Lib/gettext.py
==============================================================================
--- python/branches/release27-maint/Lib/gettext.py	(original)
+++ python/branches/release27-maint/Lib/gettext.py	Tue Oct 5 01:59:35 2010
@@ -471,7 +471,7 @@
 # once.
 result = None
 for mofile in mofiles:
- key = os.path.abspath(mofile)
+ key = (class_, os.path.abspath(mofile))
 t = _translations.get(key)
 if t is None:
 with open(mofile, 'rb') as fp:
Modified: python/branches/release27-maint/Lib/test/test_gettext.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_gettext.py	(original)
+++ python/branches/release27-maint/Lib/test/test_gettext.py	Tue Oct 5 01:59:35 2010
@@ -334,6 +334,37 @@
 'John Doe <jdoe at example.com>\nJane Foobar <jfoobar at example.com>')
 
 
+class DummyGNUTranslations(gettext.GNUTranslations):
+ def foo(self):
+ return 'foo'
+
+
+class GettextCacheTestCase(GettextBaseTest):
+ def test_cache(self):
+ self.localedir = os.curdir
+ self.mofile = MOFILE
+
+ self.assertEqual(len(gettext._translations), 0)
+
+ t = gettext.translation('gettext', self.localedir)
+
+ self.assertEqual(len(gettext._translations), 1)
+
+ t = gettext.translation('gettext', self.localedir,
+ class_=DummyGNUTranslations)
+
+ self.assertEqual(len(gettext._translations), 2)
+ self.assertEqual(t.__class__, DummyGNUTranslations)
+
+ # Calling it again doesn't add to the cache
+
+ t = gettext.translation('gettext', self.localedir,
+ class_=DummyGNUTranslations)
+
+ self.assertEqual(len(gettext._translations), 2)
+ self.assertEqual(t.__class__, DummyGNUTranslations)
+
+
 def test_main():
 test_support.run_unittest(__name__)
 
Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS	(original)
+++ python/branches/release27-maint/Misc/NEWS	Tue Oct 5 01:59:35 2010
@@ -50,6 +50,9 @@
 Library
 -------
 
+- Issue #9042: Fix interaction of custom translation classes and caching in
+ gettext.
+
 - Issue #9065: tarfile no longer uses "root" as the default for the uname and
 gname field.
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /