mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	Fix interaction of custom translation classes and caching (#9042)
This commit is contained in:
		
							parent
							
								
									701761693c
								
							
						
					
					
						commit
						6108bf5ed0
					
				
					 3 changed files with 35 additions and 1 deletions
				
			
		| 
						 | 
					@ -419,7 +419,7 @@ def translation(domain, localedir=None, languages=None,
 | 
				
			||||||
    # once.
 | 
					    # once.
 | 
				
			||||||
    result = None
 | 
					    result = None
 | 
				
			||||||
    for mofile in mofiles:
 | 
					    for mofile in mofiles:
 | 
				
			||||||
        key = os.path.abspath(mofile)
 | 
					        key = (class_, os.path.abspath(mofile))
 | 
				
			||||||
        t = _translations.get(key)
 | 
					        t = _translations.get(key)
 | 
				
			||||||
        if t is None:
 | 
					        if t is None:
 | 
				
			||||||
            with open(mofile, 'rb') as fp:
 | 
					            with open(mofile, 'rb') as fp:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -335,6 +335,37 @@ def test_weird_metadata(self):
 | 
				
			||||||
           'John Doe <jdoe@example.com>\nJane Foobar <jfoobar@example.com>')
 | 
					           '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():
 | 
					def test_main():
 | 
				
			||||||
    support.run_unittest(__name__)
 | 
					    support.run_unittest(__name__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -88,6 +88,9 @@ Core and Builtins
 | 
				
			||||||
Library
 | 
					Library
 | 
				
			||||||
-------
 | 
					-------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Issue #9042: Fix interaction of custom translation classes and caching in
 | 
				
			||||||
 | 
					  gettext.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Issue 6706: asyncore.dispatcher now provides a handle_accepted() method 
 | 
					- Issue 6706: asyncore.dispatcher now provides a handle_accepted() method 
 | 
				
			||||||
  returning a (sock, addr) pair which is called when a connection has been
 | 
					  returning a (sock, addr) pair which is called when a connection has been
 | 
				
			||||||
  established with a new remote endpoint. This is supposed to be used as a 
 | 
					  established with a new remote endpoint. This is supposed to be used as a 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue