bpo-33710: Deprecate l*gettext() and related functions in the gettext… · python/cpython@fec35c9 (original) (raw)
`@@ -274,8 +274,14 @@ def gettext(self, message):
`
274
274
`return message
`
275
275
``
276
276
`def lgettext(self, message):
`
``
277
`+
import warnings
`
``
278
`+
warnings.warn('lgettext() is deprecated, use gettext() instead',
`
``
279
`+
DeprecationWarning, 2)
`
277
280
`if self._fallback:
`
278
``
`-
return self._fallback.lgettext(message)
`
``
281
`+
with warnings.catch_warnings():
`
``
282
`+
warnings.filterwarnings('ignore', r'.\blgettext\b.',
`
``
283
`+
DeprecationWarning)
`
``
284
`+
return self._fallback.lgettext(message)
`
279
285
`if self._output_charset:
`
280
286
`return message.encode(self._output_charset)
`
281
287
`return message.encode(locale.getpreferredencoding())
`
`@@ -289,8 +295,14 @@ def ngettext(self, msgid1, msgid2, n):
`
289
295
`return msgid2
`
290
296
``
291
297
`def lngettext(self, msgid1, msgid2, n):
`
``
298
`+
import warnings
`
``
299
`+
warnings.warn('lngettext() is deprecated, use ngettext() instead',
`
``
300
`+
DeprecationWarning, 2)
`
292
301
`if self._fallback:
`
293
``
`-
return self._fallback.lngettext(msgid1, msgid2, n)
`
``
302
`+
with warnings.catch_warnings():
`
``
303
`+
warnings.filterwarnings('ignore', r'.\blngettext\b.',
`
``
304
`+
DeprecationWarning)
`
``
305
`+
return self._fallback.lngettext(msgid1, msgid2, n)
`
294
306
`if n == 1:
`
295
307
`tmsg = msgid1
`
296
308
`else:
`
`@@ -306,9 +318,15 @@ def charset(self):
`
306
318
`return self._charset
`
307
319
``
308
320
`def output_charset(self):
`
``
321
`+
import warnings
`
``
322
`+
warnings.warn('output_charset() is deprecated',
`
``
323
`+
DeprecationWarning, 2)
`
309
324
`return self._output_charset
`
310
325
``
311
326
`def set_output_charset(self, charset):
`
``
327
`+
import warnings
`
``
328
`+
warnings.warn('set_output_charset() is deprecated',
`
``
329
`+
DeprecationWarning, 2)
`
312
330
`self._output_charset = charset
`
313
331
``
314
332
`def install(self, names=None):
`
`@@ -424,6 +442,9 @@ def _parse(self, fp):
`
424
442
`transidx += 8
`
425
443
``
426
444
`def lgettext(self, message):
`
``
445
`+
import warnings
`
``
446
`+
warnings.warn('lgettext() is deprecated, use gettext() instead',
`
``
447
`+
DeprecationWarning, 2)
`
427
448
`missing = object()
`
428
449
`tmsg = self._catalog.get(message, missing)
`
429
450
`if tmsg is missing:
`
`@@ -435,6 +456,9 @@ def lgettext(self, message):
`
435
456
`return tmsg.encode(locale.getpreferredencoding())
`
436
457
``
437
458
`def lngettext(self, msgid1, msgid2, n):
`
``
459
`+
import warnings
`
``
460
`+
warnings.warn('lngettext() is deprecated, use ngettext() instead',
`
``
461
`+
DeprecationWarning, 2)
`
438
462
`try:
`
439
463
`tmsg = self._catalog[(msgid1, self.plural(n))]
`
440
464
`except KeyError:
`
`@@ -510,9 +534,10 @@ def find(domain, localedir=None, languages=None, all=False):
`
510
534
``
511
535
`# a mapping between absolute .mo file path and Translation object
`
512
536
`_translations = {}
`
``
537
`+
_unspecified = ['unspecified']
`
513
538
``
514
539
`def translation(domain, localedir=None, languages=None,
`
515
``
`-
class_=None, fallback=False, codeset=None):
`
``
540
`+
class_=None, fallback=False, codeset=_unspecified):
`
516
541
`if class_ is None:
`
517
542
`class_ = GNUTranslations
`
518
543
`mofiles = find(domain, localedir, languages, all=True)
`
`@@ -538,16 +563,23 @@ def translation(domain, localedir=None, languages=None,
`
538
563
`# are not used.
`
539
564
`import copy
`
540
565
`t = copy.copy(t)
`
541
``
`-
if codeset:
`
542
``
`-
t.set_output_charset(codeset)
`
``
566
`+
if codeset is not _unspecified:
`
``
567
`+
import warnings
`
``
568
`+
warnings.warn('parameter codeset is deprecated',
`
``
569
`+
DeprecationWarning, 2)
`
``
570
`+
if codeset:
`
``
571
`+
with warnings.catch_warnings():
`
``
572
`+
warnings.filterwarnings('ignore', r'.\bset_output_charset\b.',
`
``
573
`+
DeprecationWarning)
`
``
574
`+
t.set_output_charset(codeset)
`
543
575
`if result is None:
`
544
576
`result = t
`
545
577
`else:
`
546
578
`result.add_fallback(t)
`
547
579
`return result
`
548
580
``
549
581
``
550
``
`-
def install(domain, localedir=None, codeset=None, names=None):
`
``
582
`+
def install(domain, localedir=None, codeset=_unspecified, names=None):
`
551
583
`t = translation(domain, localedir, fallback=True, codeset=codeset)
`
552
584
`t.install(names)
`
553
585
``
`@@ -576,6 +608,9 @@ def bindtextdomain(domain, localedir=None):
`
576
608
``
577
609
``
578
610
`def bind_textdomain_codeset(domain, codeset=None):
`
``
611
`+
import warnings
`
``
612
`+
warnings.warn('bind_textdomain_codeset() is deprecated',
`
``
613
`+
DeprecationWarning, 2)
`
579
614
`global _localecodesets
`
580
615
`if codeset is not None:
`
581
616
`_localecodesets[domain] = codeset
`
`@@ -584,24 +619,31 @@ def bind_textdomain_codeset(domain, codeset=None):
`
584
619
``
585
620
`def dgettext(domain, message):
`
586
621
`try:
`
587
``
`-
t = translation(domain, _localedirs.get(domain, None),
`
588
``
`-
codeset=_localecodesets.get(domain))
`
``
622
`+
t = translation(domain, _localedirs.get(domain, None))
`
589
623
`except OSError:
`
590
624
`return message
`
591
625
`return t.gettext(message)
`
592
626
``
593
627
`def ldgettext(domain, message):
`
``
628
`+
import warnings
`
``
629
`+
warnings.warn('ldgettext() is deprecated, use dgettext() instead',
`
``
630
`+
DeprecationWarning, 2)
`
594
631
`codeset = _localecodesets.get(domain)
`
595
632
`try:
`
596
``
`-
t = translation(domain, _localedirs.get(domain, None), codeset=codeset)
`
``
633
`+
with warnings.catch_warnings():
`
``
634
`+
warnings.filterwarnings('ignore', r'.\bparameter codeset\b.',
`
``
635
`+
DeprecationWarning)
`
``
636
`+
t = translation(domain, _localedirs.get(domain, None), codeset=codeset)
`
597
637
`except OSError:
`
598
638
`return message.encode(codeset or locale.getpreferredencoding())
`
599
``
`-
return t.lgettext(message)
`
``
639
`+
with warnings.catch_warnings():
`
``
640
`+
warnings.filterwarnings('ignore', r'.\blgettext\b.',
`
``
641
`+
DeprecationWarning)
`
``
642
`+
return t.lgettext(message)
`
600
643
``
601
644
`def dngettext(domain, msgid1, msgid2, n):
`
602
645
`try:
`
603
``
`-
t = translation(domain, _localedirs.get(domain, None),
`
604
``
`-
codeset=_localecodesets.get(domain))
`
``
646
`+
t = translation(domain, _localedirs.get(domain, None))
`
605
647
`except OSError:
`
606
648
`if n == 1:
`
607
649
`return msgid1
`
`@@ -610,28 +652,49 @@ def dngettext(domain, msgid1, msgid2, n):
`
610
652
`return t.ngettext(msgid1, msgid2, n)
`
611
653
``
612
654
`def ldngettext(domain, msgid1, msgid2, n):
`
``
655
`+
import warnings
`
``
656
`+
warnings.warn('ldngettext() is deprecated, use dngettext() instead',
`
``
657
`+
DeprecationWarning, 2)
`
613
658
`codeset = _localecodesets.get(domain)
`
614
659
`try:
`
615
``
`-
t = translation(domain, _localedirs.get(domain, None), codeset=codeset)
`
``
660
`+
with warnings.catch_warnings():
`
``
661
`+
warnings.filterwarnings('ignore', r'.\bparameter codeset\b.',
`
``
662
`+
DeprecationWarning)
`
``
663
`+
t = translation(domain, _localedirs.get(domain, None), codeset=codeset)
`
616
664
`except OSError:
`
617
665
`if n == 1:
`
618
666
`tmsg = msgid1
`
619
667
`else:
`
620
668
`tmsg = msgid2
`
621
669
`return tmsg.encode(codeset or locale.getpreferredencoding())
`
622
``
`-
return t.lngettext(msgid1, msgid2, n)
`
``
670
`+
with warnings.catch_warnings():
`
``
671
`+
warnings.filterwarnings('ignore', r'.\blngettext\b.',
`
``
672
`+
DeprecationWarning)
`
``
673
`+
return t.lngettext(msgid1, msgid2, n)
`
623
674
``
624
675
`def gettext(message):
`
625
676
`return dgettext(_current_domain, message)
`
626
677
``
627
678
`def lgettext(message):
`
628
``
`-
return ldgettext(_current_domain, message)
`
``
679
`+
import warnings
`
``
680
`+
warnings.warn('lgettext() is deprecated, use gettext() instead',
`
``
681
`+
DeprecationWarning, 2)
`
``
682
`+
with warnings.catch_warnings():
`
``
683
`+
warnings.filterwarnings('ignore', r'.\bldgettext\b.',
`
``
684
`+
DeprecationWarning)
`
``
685
`+
return ldgettext(_current_domain, message)
`
629
686
``
630
687
`def ngettext(msgid1, msgid2, n):
`
631
688
`return dngettext(_current_domain, msgid1, msgid2, n)
`
632
689
``
633
690
`def lngettext(msgid1, msgid2, n):
`
634
``
`-
return ldngettext(_current_domain, msgid1, msgid2, n)
`
``
691
`+
import warnings
`
``
692
`+
warnings.warn('lngettext() is deprecated, use ngettext() instead',
`
``
693
`+
DeprecationWarning, 2)
`
``
694
`+
with warnings.catch_warnings():
`
``
695
`+
warnings.filterwarnings('ignore', r'.\bldngettext\b.',
`
``
696
`+
DeprecationWarning)
`
``
697
`+
return ldngettext(_current_domain, msgid1, msgid2, n)
`
635
698
``
636
699
`# dcgettext() has been deemed unnecessary and is not implemented.
`
637
700
``