]> granicus.if.org Git - python/commitdiff
Merged revisions 85223 via svnmerge from
authorÉric Araujo <merwok@netwok.org>
Mon, 4 Oct 2010 23:59:35 +0000 (23:59 +0000)
committerÉric Araujo <merwok@netwok.org>
Mon, 4 Oct 2010 23:59:35 +0000 (23:59 +0000)
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)
........

Lib/gettext.py
Lib/test/test_gettext.py
Misc/NEWS

index 8b8b510a0d9f3b5470b2fabd03bbe32ce8bc697b..9973535ac5029a7717b2b2d32e1426915d7b1936 100644 (file)
@@ -471,7 +471,7 @@ def translation(domain, localedir=None, languages=None,
     # 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:
index d60ece7297be2884013a3522e66402fd6bf4a2af..40dc61af7ae6477502177ecad67ea57bca71e512 100644 (file)
@@ -334,6 +334,37 @@ class WeirdMetadataTest(GettextBaseTest):
            'John Doe <jdoe@example.com>\nJane Foobar <jfoobar@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__)
 
index acdccd1b0dba4a92dbe540fdf771bcb764bc30e4..7b4c6a3c743179f00c393e02f982e155a2d7ef1b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -50,6 +50,9 @@ Core and Builtins
 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.