todo add new tests for example for dgettext remove dummy tests for example testing for single and double quotes has no sense it would have if we were testing a parser i e pygettext tests should have only one assert this data contains an invalid major version number 5 an unexpected major version number should be treated as an error when parsing a mo file gnumodatabadmajorversion b 3hielqaabqagaaaahaaaaewaaaalaaaafaaaaaaaaacoaaaafqaaakkaaaajaaaavwaaakeaaadj aaaabwaaaiubaaalaaaajqeaaeubaaczaqaafgaaan8caaaeaaaa9giaakeaaaavawaabqaaalcd aaajaaaavqmaaaeaaaadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaeaaaabqaaaayaaaacaaaaafjh ew1vbmqgthv4dxj5iflhy2gtdabuagvyzsbpcyalcybmawxlafrozxjligfyzsalcybmawxlcwbu aglzig1vzhvszsbwcm92awrlcybpbnrlcm5hdglvbmfsaxphdglvbibhbmqgbg9jywxpemf0aw9u cnn1chbvcnqgzm9yihlvdxiguhl0ag9uihbyb2dyyw1zigj5ihbyb3zpzgluzybhbibpbnrlcmzh y2ugdg8gdghliedovqpnzxr0zxh0ig1lc3nhz2ugy2f0ywxvzybsawjyyxj5lgbtdwxsdxnrag51 zgdlig51zgdlafbyb2ply3qtswqtvmvyc2lvbjogmi4wclbplvjldmlzaw9ulurhdgu6idiwmdat mdgtmjkgmti6mtktmdq6mdaktgfzdc1ucmfuc2xhdg9yoibklibeyxzpzcbjysohw7fleia8ai1k yxzpzebub29zlmzypgpmyw5ndwfnzs1uzwftoibywca8chl0ag9ulwrldkbwexrob24ub3jnpgpn su1flvzlcnnpb246ideumapdb250zw50lvr5cgu6ihrlehqvcgxhaw47ignoyxjzzxq9axnvltg4 ntktmqpdb250zw50lvryyw5zzmvyluvuy29kaw5noibub25lckdlbmvyyxrlzc1cetogchlnzxr0 zxh0lnb5ideumqpqbhvyywwtrm9ybxm6ig5wbhvyywxzpti7ihbsdxjhbd1uit0xowoavghyb2f0 d29iymxlcibnyw5ncm92zqbiyxkgjxmgzmljagvybwbiyxkgjxmgzmljagvyb3mar3v2zib6ynfo exigy2viaxzxcmygdmfncmvhbmd2ymfuexztbmd2ymegbmfxihlicg55dm1uz3ziyqpmagnjymvn ihnizsbsymhliensz3viysbjzwj0zw56zibvbcbjzwjpdnf2yxqgbmegdmfncmvzbnbyigdiigd1 cibuqugkdhjnz3jrzyb6cmzmbnryihbuz255ynqgexzvzw5lbc4aymfjb24ad2luayb3aw5raa this data contains an invalid minor version number 7 an unexpected minor version number only indicates that some of the file s contents may not be able to be read it does not indicate an error umodata b 3hielqaaaaadaaaahaaaadqaaaaaaaaaaaaaaaaaaabmaaaabaaaae0aaaaqaaaaugaaaa8baabj aaaabaaaahmbaaawaaaaeaeaaabhysoeag15y29udgv4dmoebgfiw54auhjvamvjdc1jzc1wzxjz aw9uoiayljakue8tumv2axnpb24trgf0ztogmjawmy0wnc0xmsaxmjo0mi0wndawckxhc3qtvhjh bnnsyxrvcjogqmfycnkgqs4gv0fyc2f3idxiyxjyeubwexrob24ub3jnpgpmyw5ndwfnzs1uzwft oibywca8chl0ag9ulwrldkbwexrob24ub3jnpgpnsu1flvzlcnnpb246ideumapdb250zw50lvr5 cgu6ihrlehqvcgxhaw47ignoyxjzzxq9dxrmltgkq29udgvudc1ucmfuc2zlci1fbmnvzgluzzog n2jpdaphzw5lcmf0zwqtqnk6ig1hbnvhbgx5cgdcphl6amkkexogkgnvbnrlehqgdmvyc2lvbika localedir os path join xx lcmessages mofile os path joinlocaledir gettext mo mofilebadmajorversion os path joinlocaledir gettextbadmajorversion mo mofilebadminorversion os path joinlocaledir gettextbadminorversion mo umofile os path joinlocaledir ugettext mo mmofile os path joinlocaledir metadata mo def resetgettext gettext localedirs clear gettext currentdomain messages gettext translations clear class gettextbasetestunittest testcase classmethod def setupclasscls cls addclasscleanuposhelper rmtree os path splitlocaledir0 if not os path isdirlocaledir os makedirslocaledir with openmofile wb as fp fp writebase64 decodebytesgnumodata with openmofilebadmajorversion wb as fp fp writebase64 decodebytesgnumodatabadmajorversion with openmofilebadminorversion wb as fp fp writebase64 decodebytesgnumodatabadminorversion with openumofile wb as fp fp writebase64 decodebytesumodata with openmmofile wb as fp fp writebase64 decodebytesmmodata def setupself self env self entercontextoshelper environmentvarguard self env language xx resetgettext self addcleanupresetgettext gnumodataissue17898 b 3hielqaaaaabaaaahaaaacqaaaaaaaaaaaaaaaaaaaasaaaaggaaac0aaaaaugx1cmfsluzvcm1z oibucgx1cmfscz0yoybwbhvyyww9kg4git0gmsk7cimtiy0jlsmtiyagbwvzc2fnzxmucg8gkevk wcbtdhvkaw8picajlsmtiy0jlsmkq29udgvudc1uexbloib0zxh0l3bsywluoybjagfyc2v0pvvu ri04cga test some translations double quotes triple single quotes triple double quotes multiline strings guvf zbqhyr cebivqrf vagreangvbanyvmngvba naq ybpnyvmngvba fhccbeg sbe lbhe clguba cebtenzf ol cebivqvat na vagresnpr gb gur tah trggrkg zrffntr pngnybt yvoenel def testthealternativeinterfaceself eq self assertequal neq self assertnotequal test the alternative interface with openself mofile rb as fp t gettext gnutranslationsfp install the translation object t install eq nudge nudge wink wink try unicode return type t install eq mullusk bacon test installation of other methods import builtins t installnamesgettext ngettext eq t gettext eqbuiltins gettext t gettext eqngettext t ngettext neqpgettext t pgettext del builtins gettext del builtins ngettext class gettexttestcase2gettextbasetest def setupself gettextbasetest setupself self localedir os curdir set up the bindings gettext bindtextdomain gettext self localedir gettext textdomain gettext for convenience self gettext gettext def testbindtextdomainself self assertequalgettext bindtextdomain gettext self localedir def testtextdomainself self assertequalgettext textdomain gettext def testbadmajorversionself with openmofilebadmajorversion rb as fp with self assertraisesoserror as cm gettext gnutranslationsfp exception cm exception self assertequalexception errno 0 self assertequalexception strerror bad version number 5 self assertequalexception filename mofilebadmajorversion def testbadminorversionself with openmofilebadminorversion rb as fp check that no error is thrown with a bad minor version number gettext gnutranslationsfp def testsometranslationsself eq self assertequal test some translations eqself albatross albatross eqself mullusk bacon eqself r raymond luxury yacht throatwobbler mangrove eqself r nudge nudge wink wink def testsometranslationswithcontextself eq self assertequal eqgettext pgettext my context nudge nudge wink wink in my context eqgettext pgettext my other context nudge nudge wink wink in my other context def testsometranslationswithcontextanddomainself eq self assertequal eqgettext dpgettext gettext my context nudge nudge wink wink in my context eqgettext dpgettext gettext my other context nudge nudge wink wink in my other context def testdoublequotesself eq self assertequal double quotes eqself albatross albatross eqself mullusk bacon eqself rraymond luxury yacht throatwobbler mangrove eqself rnudge nudge wink wink def testtriplesinglequotesself eq self assertequal triple single quotes eqself albatross albatross eqself mullusk bacon eqself r raymond luxury yacht throatwobbler mangrove eqself r nudge nudge wink wink def testtripledoublequotesself eq self assertequal triple double quotes eqself albatross albatross eqself mullusk bacon eqself rraymond luxury yacht throatwobbler mangrove eqself rnudge nudge wink wink def testmultilinestringsself eq self assertequal multiline strings eqself this module provides internationalization and localization support for your python programs by providing an interface to the gnu gettext message catalog library set up the bindings set up the bindings examples from http www gnu orgsoftwaregettextmanualgettext html tests the combination of parentheses and test for a dangerous expression issue28563 maximum recursion depth exceeded during compilation memoryerror during compilation maximum recursion depth exceeded in c to python translator c doesn t chain comparison as python so 2 2 2 gets different results if this runs cleanly the bug is fixed checks that comments like messages po edx studio are ignored calling it again doesn t add to the cache for reference here s the po file used to created the gnumodata above the original version was automatically generated from the sources with pygettext later it was manually modified to add plural forms support dummy translation for the python testgettext py module c 2001 python software foundation barry warsaw barrypython org 2000 testgettext py 19 testgettext py 25 testgettext py 31 testgettext py 37 testgettext py 51 testgettext py 80 testgettext py 86 testgettext py 92 testgettext py 98 testgettext py 16 testgettext py 22 testgettext py 28 testgettext py 34 testgettext py 77 testgettext py 83 testgettext py 89 testgettext py 95 testgettext py 18 testgettext py 24 testgettext py 30 testgettext py 36 testgettext py 79 testgettext py 85 testgettext py 91 testgettext py 97 testgettext py 17 testgettext py 23 testgettext py 29 testgettext py 35 testgettext py 56 testgettext py 78 testgettext py 84 testgettext py 90 testgettext py 96 testgettext py 40 testgettext py 101 manually added as neither pygettext nor xgettext support plural forms in python manually added as neither pygettext nor xgettext support plural forms and context in python here s the second example po file example used to generate the umodata containing utf8 encoded unicode strings b dummy translation for the python testgettext py module c 2001 python software foundation barry warsaw barrypython org 2000 msgid msgstr projectidversion 2 0n porevisiondate 20030411 12 420400n lasttranslator barry a warsaw barrypython orgn languageteam xx pythondevpython orgn mimeversion 1 0n contenttype textplain charsetutf8n contenttransferencoding 7bitn generatedby manuallyn nofile 0 msgid abxc3x9e msgstr xc2xa4yz nofile 1 msgctxt mycontextxc3x9e msgid abxc3x9e msgstr xc2xa4yz context version here s the third example po file used to generate mmodata messages po used for bug 17898 b test file for http bugs python orgissue17898 msgid msgstr pluralforms nplurals2 pluraln 1 n messages po edx studio n contenttype textplain charsetutf8n todo add new tests for example for dgettext remove dummy tests for example testing for single and double quotes has no sense it would have if we were testing a parser i e pygettext tests should have only one assert 3hielqaaaaajaaaahaaaagqaaaaaaaaaraaaaaaaaacsaaaafqaaak0aaaajaaaawwaaakeaaadn aaaamaaaaikbaaahaaaaugeaabyaaadcaqaahaaaankbaaalaaaa9geaaeibaaacagaafgaaaeud aaaeaaaaxamaakeaaab7awaamgaaab0eaaafaaaauaqaabsaaabwbaaaiqaaahieaaajaaaalaqa aabsyxltb25kiex1ehvyesbzywnolxqavghlcmugaxmgjxmgzmlszqbuagvyzsbhcmugjxmgzmls zxmavghpcybtb2r1bgugchjvdmlkzxmgaw50zxjuyxrpb25hbgl6yxrpb24gyw5kigxvy2fsaxph dglvbgpzdxbwb3j0igzvcib5b3vyifb5dghvbibwcm9ncmftcybiesbwcm92awrpbmcgyw4gaw50 zxjmywnlihrvihrozsbhtlukz2v0dgv4dcbtzxnzywdlignhdgfsb2cgbglicmfyes4av2l0acbj b250zxh0bfrozxjliglzicvzigzpbguavghlcmugyxjlicvzigzpbgvzag11bgx1c2sabxkgy29u dgv4darudwrnzsbudwrnzqbtesbvdghlcibjb250zxh0bg51zgdlig51zgdlag51zgdlig51zgdl afbyb2ply3qtswqtvmvyc2lvbjogmi4wclbplvjldmlzaw9ulurhdgu6idiwmdmtmdqtmtegmtq6 mzitmdqwmapmyxn0lvryyw5zbgf0b3i6ieouierhdmlkieliyw5leia8ai1kyxzpzebub29zlmzy pgpmyw5ndwfnzs1uzwftoibywca8chl0ag9ulwrldkbwexrob24ub3jnpgpnsu1flvzlcnnpb246 ideumapdb250zw50lvr5cgu6ihrlehqvcgxhaw47ignoyxjzzxq9axnvltg4ntktmqpdb250zw50 lvryyw5zzmvyluvuy29kaw5noia4yml0ckdlbmvyyxrlzc1cetogchlnzxr0zxh0lnb5ideumqpq bhvyywwtrm9ybxm6ig5wbhvyywxzpti7ihbsdxjhbd1uit0xowoavghyb2f0d29iymxlcibnyw5n cm92zqbiyxkgjxmgzmljagvybwbiyxkgjxmgzmljagvyb3mar3v2zib6ynfoexigy2viaxzxcmyg dmfncmvhbmd2ymfuexztbmd2ymegbmfxihlicg55dm1uz3ziyqpmagnjymvnihnizsbsymhliens z3viysbjzwj0zw56zibvbcbjzwjpdnf2yxqgbmegdmfncmvzbnbyigdiigd1cibuqugkdhjnz3jr zyb6cmzmbnryihbuz255ynqgexzvzw5lbc4asgf5icvzigzpy2hlcm8gkgnvbnrlehqpaehhesal cybmawnozxjvcyaoy29udgv4dckaymfjb24ad2luayb3aw5richpbiaibxkgy29udgv4dcipahdp bmsgd2luayaoaw4gim15ig90agvyignvbnrlehqikqb3aw5rihdpbmsa this data contains an invalid major version number 5 an unexpected major version number should be treated as an error when parsing a mo file 3hielqaabqagaaaahaaaaewaaaalaaaafaaaaaaaaacoaaaafqaaakkaaaajaaaavwaaakeaaadj aaaabwaaaiubaaalaaaajqeaaeubaaczaqaafgaaan8caaaeaaaa9giaakeaaaavawaabqaaalcd aaajaaaavqmaaaeaaaadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaeaaaabqaaaayaaaacaaaaafjh ew1vbmqgthv4dxj5iflhy2gtdabuagvyzsbpcyalcybmawxlafrozxjligfyzsalcybmawxlcwbu aglzig1vzhvszsbwcm92awrlcybpbnrlcm5hdglvbmfsaxphdglvbibhbmqgbg9jywxpemf0aw9u cnn1chbvcnqgzm9yihlvdxiguhl0ag9uihbyb2dyyw1zigj5ihbyb3zpzgluzybhbibpbnrlcmzh y2ugdg8gdghliedovqpnzxr0zxh0ig1lc3nhz2ugy2f0ywxvzybsawjyyxj5lgbtdwxsdxnrag51 zgdlig51zgdlafbyb2ply3qtswqtvmvyc2lvbjogmi4wclbplvjldmlzaw9ulurhdgu6idiwmdat mdgtmjkgmti6mtktmdq6mdaktgfzdc1ucmfuc2xhdg9yoibklibeyxzpzcbjysohw7fleia8ai1k yxzpzebub29zlmzypgpmyw5ndwfnzs1uzwftoibywca8chl0ag9ulwrldkbwexrob24ub3jnpgpn su1flvzlcnnpb246ideumapdb250zw50lvr5cgu6ihrlehqvcgxhaw47ignoyxjzzxq9axnvltg4 ntktmqpdb250zw50lvryyw5zzmvyluvuy29kaw5noibub25lckdlbmvyyxrlzc1cetogchlnzxr0 zxh0lnb5ideumqpqbhvyywwtrm9ybxm6ig5wbhvyywxzpti7ihbsdxjhbd1uit0xowoavghyb2f0 d29iymxlcibnyw5ncm92zqbiyxkgjxmgzmljagvybwbiyxkgjxmgzmljagvyb3mar3v2zib6ynfo exigy2viaxzxcmygdmfncmvhbmd2ymfuexztbmd2ymegbmfxihlicg55dm1uz3ziyqpmagnjymvn ihnizsbsymhliensz3viysbjzwj0zw56zibvbcbjzwjpdnf2yxqgbmegdmfncmvzbnbyigdiigd1 cibuqugkdhjnz3jrzyb6cmzmbnryihbuz255ynqgexzvzw5lbc4aymfjb24ad2luayb3aw5raa this data contains an invalid minor version number 7 an unexpected minor version number only indicates that some of the file s contents may not be able to be read it does not indicate an error 3hielqcaaaagaaaahaaaaewaaaalaaaafaaaaaaaaacoaaaafqaaakkaaaajaaaavwaaakeaaadj aaaabwaaaiubaaalaaaajqeaaeubaaczaqaafgaaan8caaaeaaaa9giaakeaaaavawaabqaaalcd aaajaaaavqmaaaeaaaadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaeaaaabqaaaayaaaacaaaaafjh ew1vbmqgthv4dxj5iflhy2gtdabuagvyzsbpcyalcybmawxlafrozxjligfyzsalcybmawxlcwbu aglzig1vzhvszsbwcm92awrlcybpbnrlcm5hdglvbmfsaxphdglvbibhbmqgbg9jywxpemf0aw9u cnn1chbvcnqgzm9yihlvdxiguhl0ag9uihbyb2dyyw1zigj5ihbyb3zpzgluzybhbibpbnrlcmzh y2ugdg8gdghliedovqpnzxr0zxh0ig1lc3nhz2ugy2f0ywxvzybsawjyyxj5lgbtdwxsdxnrag51 zgdlig51zgdlafbyb2ply3qtswqtvmvyc2lvbjogmi4wclbplvjldmlzaw9ulurhdgu6idiwmdat mdgtmjkgmti6mtktmdq6mdaktgfzdc1ucmfuc2xhdg9yoibklibeyxzpzcbjysohw7fleia8ai1k yxzpzebub29zlmzypgpmyw5ndwfnzs1uzwftoibywca8chl0ag9ulwrldkbwexrob24ub3jnpgpn su1flvzlcnnpb246ideumapdb250zw50lvr5cgu6ihrlehqvcgxhaw47ignoyxjzzxq9axnvltg4 ntktmqpdb250zw50lvryyw5zzmvyluvuy29kaw5noibub25lckdlbmvyyxrlzc1cetogchlnzxr0 zxh0lnb5ideumqpqbhvyywwtrm9ybxm6ig5wbhvyywxzpti7ihbsdxjhbd1uit0xowoavghyb2f0 d29iymxlcibnyw5ncm92zqbiyxkgjxmgzmljagvybwbiyxkgjxmgzmljagvyb3mar3v2zib6ynfo exigy2viaxzxcmygdmfncmvhbmd2ymfuexztbmd2ymegbmfxihlicg55dm1uz3ziyqpmagnjymvn ihnizsbsymhliensz3viysbjzwj0zw56zibvbcbjzwjpdnf2yxqgbmegdmfncmvzbnbyigdiigd1 cibuqugkdhjnz3jrzyb6cmzmbnryihbuz255ynqgexzvzw5lbc4aymfjb24ad2luayb3aw5raa 3hielqaaaaadaaaahaaaadqaaaaaaaaaaaaaaaaaaabmaaaabaaaae0aaaaqaaaaugaaaa8baabj aaaabaaaahmbaaawaaaaeaeaaabhysoeag15y29udgv4dmoebgfiw54auhjvamvjdc1jzc1wzxjz aw9uoiayljakue8tumv2axnpb24trgf0ztogmjawmy0wnc0xmsaxmjo0mi0wndawckxhc3qtvhjh bnnsyxrvcjogqmfycnkgqs4gv0fyc2f3idxiyxjyeubwexrob24ub3jnpgpmyw5ndwfnzs1uzwft oibywca8chl0ag9ulwrldkbwexrob24ub3jnpgpnsu1flvzlcnnpb246ideumapdb250zw50lvr5 cgu6ihrlehqvcgxhaw47ignoyxjzzxq9dxrmltgkq29udgvudc1ucmfuc2zlci1fbmnvzgluzzog n2jpdaphzw5lcmf0zwqtqnk6ig1hbnvhbgx5cgdcphl6amkkexogkgnvbnrlehqgdmvyc2lvbika 3hielqaaaaabaaaahaaaacqaaaadaaaalaaaaaaaaaa4aaaaeaeaadkaaaabaaaaaaaaaaaaaaaa uhjvamvjdc1jzc1wzxjzaw9uoibobybqcm9qzwn0idaumapqt1qtq3jlyxrpb24trgf0ztogv2vk ierlyyaxmsawnzo0ndoxnsaymdayclbplvjldmlzaw9ulurhdgu6idiwmditmdgtmtqgmde6mtg6 ntgrmda6mdaktgfzdc1ucmfuc2xhdg9yoibkb2huiervzsa8amrvzublegftcgxllmnvbt4ksmfu zsbgb29iyxigpgpmb29iyxjazxhhbxbszs5jb20 ckxhbmd1ywdllvrlyw06ihh4idx4eeblegft cgxllmnvbt4ktulnrs1wzxjzaw9uoiaxljakq29udgvudc1uexbloib0zxh0l3bsywluoybjagfy c2v0pwlzby04odu5lte1cknvbnrlbnqtvhjhbnnmzxitrw5jb2rpbmc6ihf1b3rlzc1wcmludgfi bgukr2vuzxjhdgvkluj5oibwewdldhrlehquchkgms4zcga 3hielqaaaaabaaaahaaaacqaaaaaaaaaaaaaaaaaaaasaaaaggaaac0aaaaaugx1cmfsluzvcm1z oibucgx1cmfscz0yoybwbhvyyww9kg4git0gmsk7cimtiy0jlsmtiyagbwvzc2fnzxmucg8gkevk wcbtdhvkaw8picajlsmtiy0jlsmkq29udgvudc1uexbloib0zxh0l3bsywluoybjagfyc2v0pvvu ri04cga test some translations double quotes triple single quotes albatross mullusk raymond luxury yach t nudge nudge triple double quotes albatross mullusk raymond luxury yach t nudge nudge multiline strings this module provides internationalization and localization support for your python programs by providing an interface to the gnu gettext message catalog library guvf zbqhyr cebivqrf vagreangvbanyvmngvba naq ybpnyvmngvba fhccbeg sbe lbhe clguba cebtenzf ol cebivqvat na vagresnpr gb gur tah trggrkg zrffntr pngnybt yvoenel test the alternative interface install the translation object try unicode return type test installation of other methods set up the bindings for convenience check that no error is thrown with a bad minor version number test some translations double quotes triple single quotes albatross mullusk raymond luxury yach t nudge nudge triple double quotes albatross mullusk raymond luxury yach t nudge nudge multiline strings this module provides internationalization and localization support for your python programs by providing an interface to the gnu gettext message catalog library guvf zbqhyr cebivqrf vagreangvbanyvmngvba naq ybpnyvmngvba fhccbeg sbe lbhe clguba cebtenzf ol cebivqvat na vagresnpr gb gur tah trggrkg zrffntr pngnybt yvoenel set up the bindings set up the bindings examples from http www gnu org software gettext manual gettext html tests the combination of parentheses and test for a dangerous expression issue28563 maximum recursion depth exceeded during compilation memoryerror during compilation maximum recursion depth exceeded in c to python translator c doesn t chain comparison as python so 2 2 2 gets different results if this runs cleanly the bug is fixed checks that comments like messages po edx studio are ignored calling it again doesn t add to the cache for reference here s the po file used to created the gnu_mo_data above the original version was automatically generated from the sources with pygettext later it was manually modified to add plural forms support dummy translation for the python test_gettext py module c 2001 python software foundation barry warsaw barry python org 2000 msgid msgstr project id version 2 0 n po revision date 2003 04 11 14 32 0400 n last translator j david ibanez j david noos fr n language team xx python dev python org n mime version 1 0 n content type text plain charset iso 8859 1 n content transfer encoding 8bit n generated by pygettext py 1 1 n plural forms nplurals 2 plural n 1 n test_gettext py 19 test_gettext py 25 test_gettext py 31 test_gettext py 37 test_gettext py 51 test_gettext py 80 test_gettext py 86 test_gettext py 92 test_gettext py 98 msgid nudge nudge msgstr wink wink msgctxt my context msgid nudge nudge msgstr wink wink in my context msgctxt my other context msgid nudge nudge msgstr wink wink in my other context test_gettext py 16 test_gettext py 22 test_gettext py 28 test_gettext py 34 test_gettext py 77 test_gettext py 83 test_gettext py 89 test_gettext py 95 msgid albatross msgstr test_gettext py 18 test_gettext py 24 test_gettext py 30 test_gettext py 36 test_gettext py 79 test_gettext py 85 test_gettext py 91 test_gettext py 97 msgid raymond luxury yach t msgstr throatwobbler mangrove test_gettext py 17 test_gettext py 23 test_gettext py 29 test_gettext py 35 test_gettext py 56 test_gettext py 78 test_gettext py 84 test_gettext py 90 test_gettext py 96 msgid mullusk msgstr bacon test_gettext py 40 test_gettext py 101 msgid this module provides internationalization and localization n support for your python programs by providing an interface to the gnu n gettext message catalog library msgstr guvf zbqhyr cebivqrf vagreangvbanyvmngvba naq ybpnyvmngvba n fhccbeg sbe lbhe clguba cebtenzf ol cebivqvat na vagresnpr gb gur tah n trggrkg zrffntr pngnybt yvoenel manually added as neither pygettext nor xgettext support plural forms in python msgid there is s file msgid_plural there are s files msgstr 0 hay s fichero msgstr 1 hay s ficheros manually added as neither pygettext nor xgettext support plural forms and context in python msgctxt with context msgid there is s file msgid_plural there are s files msgstr 0 hay s fichero context msgstr 1 hay s ficheros context here s the second example po file example used to generate the umo_data containing utf 8 encoded unicode strings dummy translation for the python test_gettext py module c 2001 python software foundation barry warsaw barry python org 2000 msgid msgstr project id version 2 0 n po revision date 2003 04 11 12 42 0400 n last translator barry a warsaw barry python org n language team xx python dev python org n mime version 1 0 n content type text plain charset utf 8 n content transfer encoding 7bit n generated by manually n nofile 0 msgid ab xc3 x9e msgstr xc2 xa4yz nofile 1 msgctxt mycontext xc3 x9e msgid ab xc3 x9e msgstr xc2 xa4yz context version here s the third example po file used to generate mmo_data msgid msgstr project id version no project 0 0 n pot creation date wed dec 11 07 44 15 2002 n po revision date 2002 08 14 01 18 58 00 00 n last translator john doe jdoe example com n jane foobar jfoobar example com n language team xx xx example com n mime version 1 0 n content type text plain charset iso 8859 15 n content transfer encoding quoted printable n generated by pygettext py 1 3 n messages po used for bug 17898 test file for http bugs python org issue17898 msgid msgstr plural forms nplurals 2 plural n 1 n messages po edx studio n content type text plain charset utf 8 n
import os
import base64
import gettext
import unittest
from functools import partial

from test import support
from test.support import os_helper








GNU_MO_DATA = b





GNU_MO_DATA_BAD_MAJOR_VERSION = b





GNU_MO_DATA_BAD_MINOR_VERSION = b


UMO_DATA = b

MMO_DATA = b

LOCALEDIR = os.path.join('xx', 'LC_MESSAGES')
MOFILE = os.path.join(LOCALEDIR, 'gettext.mo')
MOFILE_BAD_MAJOR_VERSION = os.path.join(LOCALEDIR, 'gettext_bad_major_version.mo')
MOFILE_BAD_MINOR_VERSION = os.path.join(LOCALEDIR, 'gettext_bad_minor_version.mo')
UMOFILE = os.path.join(LOCALEDIR, 'ugettext.mo')
MMOFILE = os.path.join(LOCALEDIR, 'metadata.mo')


def reset_gettext():
    gettext._localedirs.clear()
    gettext._current_domain = 'messages'
    gettext._translations.clear()


class GettextBaseTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.addClassCleanup(os_helper.rmtree, os.path.split(LOCALEDIR)[0])
        if not os.path.isdir(LOCALEDIR):
            os.makedirs(LOCALEDIR)
        with open(MOFILE, 'wb') as fp:
            fp.write(base64.decodebytes(GNU_MO_DATA))
        with open(MOFILE_BAD_MAJOR_VERSION, 'wb') as fp:
            fp.write(base64.decodebytes(GNU_MO_DATA_BAD_MAJOR_VERSION))
        with open(MOFILE_BAD_MINOR_VERSION, 'wb') as fp:
            fp.write(base64.decodebytes(GNU_MO_DATA_BAD_MINOR_VERSION))
        with open(UMOFILE, 'wb') as fp:
            fp.write(base64.decodebytes(UMO_DATA))
        with open(MMOFILE, 'wb') as fp:
            fp.write(base64.decodebytes(MMO_DATA))

    def setUp(self):
        self.env = self.enterContext(os_helper.EnvironmentVarGuard())
        self.env['LANGUAGE'] = 'xx'
        reset_gettext()
        self.addCleanup(reset_gettext)


GNU_MO_DATA_ISSUE_17898 = b

class GettextTestCase1(GettextBaseTest):
    def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        self.mofile = MOFILE
        gettext.install('gettext', self.localedir, names=['pgettext'])

    def test_some_translations(self):
        eq = self.assertEqual
        
        eq(_('albatross'), 'albatross')
        eq(_('mullusk'), 'bacon')
        eq(_(r'Raymond Luxury Yach-t'), 'Throatwobbler Mangrove')
        eq(_(r'nudge nudge'), 'wink wink')

    def test_some_translations_with_context(self):
        eq = self.assertEqual
        eq(pgettext('my context', 'nudge nudge'),
           'wink wink (in "my context")')
        eq(pgettext('my other context', 'nudge nudge'),
           'wink wink (in "my other context")')

    def test_double_quotes(self):
        eq = self.assertEqual
        
        eq(_("albatross"), 'albatross')
        eq(_("mullusk"), 'bacon')
        eq(_(r"Raymond Luxury Yach-t"), 'Throatwobbler Mangrove')
        eq(_(r"nudge nudge"), 'wink wink')

    def test_triple_single_quotes(self):
        eq = self.assertEqual
        
        eq(_(), 'albatross')
        eq(_(), 'bacon')
        eq(_(r), 'Throatwobbler Mangrove')
        eq(_(r), 'wink wink')

    def test_triple_double_quotes(self):
        eq = self.assertEqual
        
        eq(_(), 'albatross')
        eq(_(), 'bacon')
        eq(_(r), 'Throatwobbler Mangrove')
        eq(_(r), 'wink wink')

    def test_multiline_strings(self):
        eq = self.assertEqual
        
        eq(_(),
           )

    def test_the_alternative_interface(self):
        eq = self.assertEqual
        neq = self.assertNotEqual
        
        with open(self.mofile, 'rb') as fp:
            t = gettext.GNUTranslations(fp)
        
        t.install()
        eq(_('nudge nudge'), 'wink wink')
        
        t.install()
        eq(_('mullusk'), 'bacon')
        
        import builtins
        t.install(names=["gettext", "ngettext"])
        eq(_, t.gettext)
        eq(builtins.gettext, t.gettext)
        eq(ngettext, t.ngettext)
        neq(pgettext, t.pgettext)
        del builtins.gettext
        del builtins.ngettext


class GettextTestCase2(GettextBaseTest):
    def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        
        gettext.bindtextdomain('gettext', self.localedir)
        gettext.textdomain('gettext')
        
        self._ = gettext.gettext

    def test_bindtextdomain(self):
        self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir)

    def test_textdomain(self):
        self.assertEqual(gettext.textdomain(), 'gettext')

    def test_bad_major_version(self):
        with open(MOFILE_BAD_MAJOR_VERSION, 'rb') as fp:
            with self.assertRaises(OSError) as cm:
                gettext.GNUTranslations(fp)

            exception = cm.exception
            self.assertEqual(exception.errno, 0)
            self.assertEqual(exception.strerror, "Bad version number 5")
            self.assertEqual(exception.filename, MOFILE_BAD_MAJOR_VERSION)

    def test_bad_minor_version(self):
        with open(MOFILE_BAD_MINOR_VERSION, 'rb') as fp:
            
            gettext.GNUTranslations(fp)

    def test_some_translations(self):
        eq = self.assertEqual
        
        eq(self._('albatross'), 'albatross')
        eq(self._('mullusk'), 'bacon')
        eq(self._(r'Raymond Luxury Yach-t'), 'Throatwobbler Mangrove')
        eq(self._(r'nudge nudge'), 'wink wink')

    def test_some_translations_with_context(self):
        eq = self.assertEqual
        eq(gettext.pgettext('my context', 'nudge nudge'),
           'wink wink (in "my context")')
        eq(gettext.pgettext('my other context', 'nudge nudge'),
           'wink wink (in "my other context")')

    def test_some_translations_with_context_and_domain(self):
        eq = self.assertEqual
        eq(gettext.dpgettext('gettext', 'my context', 'nudge nudge'),
           'wink wink (in "my context")')
        eq(gettext.dpgettext('gettext', 'my other context', 'nudge nudge'),
           'wink wink (in "my other context")')

    def test_double_quotes(self):
        eq = self.assertEqual
        
        eq(self._("albatross"), 'albatross')
        eq(self._("mullusk"), 'bacon')
        eq(self._(r"Raymond Luxury Yach-t"), 'Throatwobbler Mangrove')
        eq(self._(r"nudge nudge"), 'wink wink')

    def test_triple_single_quotes(self):
        eq = self.assertEqual
        
        eq(self._(), 'albatross')
        eq(self._(), 'bacon')
        eq(self._(r), 'Throatwobbler Mangrove')
        eq(self._(r), 'wink wink')

    def test_triple_double_quotes(self):
        eq = self.assertEqual
        
        eq(self._(), 'albatross')
        eq(self._(), 'bacon')
        eq(self._(r), 'Throatwobbler Mangrove')
        eq(self._(r), 'wink wink')

    def test_multiline_strings(self):
        eq = self.assertEqual
        
        eq(self._(),
           )


class PluralFormsTests:

    def _test_plural_forms(self, ngettext, gettext,
                           singular, plural, tsingular, tplural,
                           numbers_only=True):
        x = ngettext(singular, plural, 1)
        self.assertEqual(x, tsingular)
        x = ngettext(singular, plural, 2)
        self.assertEqual(x, tplural)
        x = gettext(singular)
        self.assertEqual(x, tsingular)

        lineno = self._test_plural_forms.__code__.co_firstlineno + 12
        with self.assertWarns(DeprecationWarning) as cm:
            x = ngettext(singular, plural, 1.0)
        self.assertEqual(cm.filename, __file__)
        self.assertEqual(cm.lineno, lineno)
        self.assertEqual(x, tsingular)
        with self.assertWarns(DeprecationWarning) as cm:
            x = ngettext(singular, plural, 1.1)
        self.assertEqual(cm.filename, __file__)
        self.assertEqual(cm.lineno, lineno + 5)
        self.assertEqual(x, tplural)

        if numbers_only:
            with self.assertRaises(TypeError):
                ngettext(singular, plural, None)
        else:
            with self.assertWarns(DeprecationWarning) as cm:
                x = ngettext(singular, plural, None)
            self.assertEqual(x, tplural)

    def test_plural_forms(self):
        self._test_plural_forms(
            self.ngettext, self.gettext,
            'There is %s file', 'There are %s files',
            'Hay %s fichero', 'Hay %s ficheros')
        self._test_plural_forms(
            self.ngettext, self.gettext,
            '%d file deleted', '%d files deleted',
            '%d file deleted', '%d files deleted')

    def test_plural_context_forms(self):
        ngettext = partial(self.npgettext, 'With context')
        gettext = partial(self.pgettext, 'With context')
        self._test_plural_forms(
            ngettext, gettext,
            'There is %s file', 'There are %s files',
            'Hay %s fichero (context)', 'Hay %s ficheros (context)')
        self._test_plural_forms(
            ngettext, gettext,
            '%d file deleted', '%d files deleted',
            '%d file deleted', '%d files deleted')

    def test_plural_wrong_context_forms(self):
        self._test_plural_forms(
            partial(self.npgettext, 'Unknown context'),
            partial(self.pgettext, 'Unknown context'),
            'There is %s file', 'There are %s files',
            'There is %s file', 'There are %s files')


class GNUTranslationsPluralFormsTestCase(PluralFormsTests, GettextBaseTest):
    def setUp(self):
        GettextBaseTest.setUp(self)
        
        gettext.bindtextdomain('gettext', os.curdir)
        gettext.textdomain('gettext')

        self.gettext = gettext.gettext
        self.ngettext = gettext.ngettext
        self.pgettext = gettext.pgettext
        self.npgettext = gettext.npgettext


class GNUTranslationsWithDomainPluralFormsTestCase(PluralFormsTests, GettextBaseTest):
    def setUp(self):
        GettextBaseTest.setUp(self)
        
        gettext.bindtextdomain('gettext', os.curdir)

        self.gettext = partial(gettext.dgettext, 'gettext')
        self.ngettext = partial(gettext.dngettext, 'gettext')
        self.pgettext = partial(gettext.dpgettext, 'gettext')
        self.npgettext = partial(gettext.dnpgettext, 'gettext')

    def test_plural_forms_wrong_domain(self):
        self._test_plural_forms(
            partial(gettext.dngettext, 'unknown'),
            partial(gettext.dgettext, 'unknown'),
            'There is %s file', 'There are %s files',
            'There is %s file', 'There are %s files',
            numbers_only=False)

    def test_plural_context_forms_wrong_domain(self):
        self._test_plural_forms(
            partial(gettext.dnpgettext, 'unknown', 'With context'),
            partial(gettext.dpgettext, 'unknown', 'With context'),
            'There is %s file', 'There are %s files',
            'There is %s file', 'There are %s files',
            numbers_only=False)


class GNUTranslationsClassPluralFormsTestCase(PluralFormsTests, GettextBaseTest):
    def setUp(self):
        GettextBaseTest.setUp(self)
        with open(MOFILE, 'rb') as fp:
            t = gettext.GNUTranslations(fp)

        self.gettext = t.gettext
        self.ngettext = t.ngettext
        self.pgettext = t.pgettext
        self.npgettext = t.npgettext

    def test_plural_forms_null_translations(self):
        t = gettext.NullTranslations()
        self._test_plural_forms(
            t.ngettext, t.gettext,
            'There is %s file', 'There are %s files',
            'There is %s file', 'There are %s files',
            numbers_only=False)

    def test_plural_context_forms_null_translations(self):
        t = gettext.NullTranslations()
        self._test_plural_forms(
            partial(t.npgettext, 'With context'),
            partial(t.pgettext, 'With context'),
            'There is %s file', 'There are %s files',
            'There is %s file', 'There are %s files',
            numbers_only=False)


class PluralFormsInternalTestCase:
    

    def test_ja(self):
        eq = self.assertEqual
        f = gettext.c2py('0')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")

    def test_de(self):
        eq = self.assertEqual
        f = gettext.c2py('n != 1')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")

    def test_fr(self):
        eq = self.assertEqual
        f = gettext.c2py('n>1')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "00111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")

    def test_lv(self):
        eq = self.assertEqual
        f = gettext.c2py('n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "20111111111111111111101111111110111111111011111111101111111110111111111011111111101111111110111111111011111111111111111110111111111011111111101111111110111111111011111111101111111110111111111011111111")

    def test_gd(self):
        eq = self.assertEqual
        f = gettext.c2py('n==1 ? 0 : n==2 ? 1 : 2')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "20122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222")

    def test_gd2(self):
        eq = self.assertEqual
        
        f = gettext.c2py('n==1 ? 0 : (n==2 ? 1 : 2)')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "20122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222")

    def test_ro(self):
        eq = self.assertEqual
        f = gettext.c2py('n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "10111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222222")

    def test_lt(self):
        eq = self.assertEqual
        f = gettext.c2py('n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "20111111112222222222201111111120111111112011111111201111111120111111112011111111201111111120111111112011111111222222222220111111112011111111201111111120111111112011111111201111111120111111112011111111")

    def test_ru(self):
        eq = self.assertEqual
        f = gettext.c2py('n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "20111222222222222222201112222220111222222011122222201112222220111222222011122222201112222220111222222011122222222222222220111222222011122222201112222220111222222011122222201112222220111222222011122222")

    def test_cs(self):
        eq = self.assertEqual
        f = gettext.c2py('(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "20111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222")

    def test_pl(self):
        eq = self.assertEqual
        f = gettext.c2py('n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "20111222222222222222221112222222111222222211122222221112222222111222222211122222221112222222111222222211122222222222222222111222222211122222221112222222111222222211122222221112222222111222222211122222")

    def test_sl(self):
        eq = self.assertEqual
        f = gettext.c2py('n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "30122333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333012233333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333")

    def test_ar(self):
        eq = self.assertEqual
        f = gettext.c2py('n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5')
        s = ''.join([ str(f(x)) for x in range(200) ])
        eq(s, "01233333333444444444444444444444444444444444444444444444444444444444444444444444444444444444444444445553333333344444444444444444444444444444444444444444444444444444444444444444444444444444444444444444")

    def test_security(self):
        raises = self.assertRaises
        
        raises(ValueError, gettext.c2py, "os.chmod('/etc/passwd',0777)")
        
        raises(ValueError, gettext.c2py, '"(eval(foo) && ""')
        raises(ValueError, gettext.c2py, 'f"{os.system(\'sh\')}"')
        
        raises(ValueError, gettext.c2py, 'n+'*10000 + 'n')
        self.assertEqual(gettext.c2py('n+'*100 + 'n')(1), 101)
        
        raises(ValueError, gettext.c2py, '('*100 + 'n' + ')'*100)
        
        raises(ValueError, gettext.c2py, '('*10000 + 'n' + ')'*10000)
        self.assertEqual(gettext.c2py('('*20 + 'n' + ')'*20)(1), 1)

    def test_chained_comparison(self):
        
        f = gettext.c2py('n == n == n')
        self.assertEqual(''.join(str(f(x)) for x in range(3)), '010')
        f = gettext.c2py('1 < n == n')
        self.assertEqual(''.join(str(f(x)) for x in range(3)), '100')
        f = gettext.c2py('n == n < 2')
        self.assertEqual(''.join(str(f(x)) for x in range(3)), '010')
        f = gettext.c2py('0 < n < 2')
        self.assertEqual(''.join(str(f(x)) for x in range(3)), '111')

    def test_decimal_number(self):
        self.assertEqual(gettext.c2py('0123')(1), 123)

    def test_invalid_syntax(self):
        invalid_expressions = [
            'x>1', '(n>1', 'n>1)', '42**42**42', '0xa', '1.0', '1e2',
            'n>0x1', '+n', '-n', 'n()', 'n(1)', '1+', 'nn', 'n n',
        ]
        for expr in invalid_expressions:
            with self.assertRaises(ValueError):
                gettext.c2py(expr)

    def test_nested_condition_operator(self):
        self.assertEqual(gettext.c2py('n?1?2:3:4')(0), 4)
        self.assertEqual(gettext.c2py('n?1?2:3:4')(1), 2)
        self.assertEqual(gettext.c2py('n?1:3?4:5')(0), 4)
        self.assertEqual(gettext.c2py('n?1:3?4:5')(1), 1)

    def test_division(self):
        f = gettext.c2py('2/n*3')
        self.assertEqual(f(1), 6)
        self.assertEqual(f(2), 3)
        self.assertEqual(f(3), 0)
        self.assertEqual(f(-1), -6)
        self.assertRaises(ZeroDivisionError, f, 0)

    def test_plural_number(self):
        f = gettext.c2py('n != 1')
        self.assertEqual(f(1), 0)
        self.assertEqual(f(2), 1)
        with self.assertWarns(DeprecationWarning):
            self.assertEqual(f(1.0), 0)
        with self.assertWarns(DeprecationWarning):
            self.assertEqual(f(2.0), 1)
        with self.assertWarns(DeprecationWarning):
            self.assertEqual(f(1.1), 1)
        self.assertRaises(TypeError, f, '2')
        self.assertRaises(TypeError, f, b'2')
        self.assertRaises(TypeError, f, [])
        self.assertRaises(TypeError, f, object())


class GNUTranslationParsingTest(GettextBaseTest):
    def test_plural_form_error_issue17898(self):
        with open(MOFILE, 'wb') as fp:
            fp.write(base64.decodebytes(GNU_MO_DATA_ISSUE_17898))
        with open(MOFILE, 'rb') as fp:
            
            t = gettext.GNUTranslations(fp)

    def test_ignore_comments_in_headers_issue36239(self):
        
        with open(MOFILE, 'wb') as fp:
            fp.write(base64.decodebytes(GNU_MO_DATA_ISSUE_17898))
        with open(MOFILE, 'rb') as fp:
            t = gettext.GNUTranslations(fp)
            self.assertEqual(t.info()["plural-forms"], "nplurals=2; plural=(n != 1);")


class UnicodeTranslationsTest(GettextBaseTest):
    def setUp(self):
        GettextBaseTest.setUp(self)
        with open(UMOFILE, 'rb') as fp:
            self.t = gettext.GNUTranslations(fp)
        self._ = self.t.gettext
        self.pgettext = self.t.pgettext

    def test_unicode_msgid(self):
        self.assertIsInstance(self._(''), str)

    def test_unicode_msgstr(self):
        self.assertEqual(self._('ab\xde'), '\xa4yz')

    def test_unicode_context_msgstr(self):
        t = self.pgettext('mycontext\xde', 'ab\xde')
        self.assertTrue(isinstance(t, str))
        self.assertEqual(t, '\xa4yz (context version)')


class UnicodeTranslationsPluralTest(GettextBaseTest):
    def setUp(self):
        GettextBaseTest.setUp(self)
        with open(MOFILE, 'rb') as fp:
            self.t = gettext.GNUTranslations(fp)
        self.ngettext = self.t.ngettext
        self.npgettext = self.t.npgettext

    def test_unicode_msgid(self):
        unless = self.assertTrue
        unless(isinstance(self.ngettext('', '', 1), str))
        unless(isinstance(self.ngettext('', '', 2), str))

    def test_unicode_context_msgid(self):
        unless = self.assertTrue
        unless(isinstance(self.npgettext('', '', '', 1), str))
        unless(isinstance(self.npgettext('', '', '', 2), str))

    def test_unicode_msgstr(self):
        eq = self.assertEqual
        unless = self.assertTrue
        t = self.ngettext("There is %s file", "There are %s files", 1)
        unless(isinstance(t, str))
        eq(t, "Hay %s fichero")
        unless(isinstance(t, str))
        t = self.ngettext("There is %s file", "There are %s files", 5)
        unless(isinstance(t, str))
        eq(t, "Hay %s ficheros")

    def test_unicode_msgstr_with_context(self):
        eq = self.assertEqual
        unless = self.assertTrue
        t = self.npgettext("With context",
                           "There is %s file", "There are %s files", 1)
        unless(isinstance(t, str))
        eq(t, "Hay %s fichero (context)")
        t = self.npgettext("With context",
                           "There is %s file", "There are %s files", 5)
        unless(isinstance(t, str))
        eq(t, "Hay %s ficheros (context)")


class WeirdMetadataTest(GettextBaseTest):
    def setUp(self):
        GettextBaseTest.setUp(self)
        with open(MMOFILE, 'rb') as fp:
            try:
                self.t = gettext.GNUTranslations(fp)
            except:
                self.tearDown()
                raise

    def test_weird_metadata(self):
        info = self.t.info()
        self.assertEqual(len(info), 9)
        self.assertEqual(info['last-translator'],
           '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)

        

        t = gettext.translation('gettext', self.localedir,
                                class_=DummyGNUTranslations)

        self.assertEqual(len(gettext._translations), 2)
        self.assertEqual(t.__class__, DummyGNUTranslations)


class MiscTestCase(unittest.TestCase):
    def test__all__(self):
        support.check__all__(self, gettext,
                             not_exported={'c2py', 'ENOENT'})


if __name__ == '__main__':
    unittest.main()







b




b



b





b