MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / getdefaultlocale

Function getdefaultlocale

tools/python-3.11.9-amd64/Lib/locale.py:534–591  ·  view source on GitHub ↗

Tries to determine the default locale settings and returns them as tuple (language code, encoding). According to POSIX, a program which has not called setlocale(LC_ALL, "") runs using the portable 'C' locale. Calling setlocale(LC_ALL, "") lets it use the defaul

(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'))

Source from the content-addressed store, hash-verified

532 'two strings -- language code, encoding.') from None
533
534def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
535
536 """ Tries to determine the default locale settings and returns
537 them as tuple (language code, encoding).
538
539 According to POSIX, a program which has not called
540 setlocale(LC_ALL, "") runs using the portable 'C' locale.
541 Calling setlocale(LC_ALL, "") lets it use the default locale as
542 defined by the LANG variable. Since we don't want to interfere
543 with the current locale setting we thus emulate the behavior
544 in the way described above.
545
546 To maintain compatibility with other platforms, not only the
547 LANG variable is tested, but a list of variables given as
548 envvars parameter. The first found to be defined will be
549 used. envvars defaults to the search path used in GNU gettext;
550 it must always contain the variable name 'LANG'.
551
552 Except for the code 'C', the language code corresponds to RFC
553 1766. code and encoding can be None in case the values cannot
554 be determined.
555
556 """
557
558 import warnings
559 warnings._deprecated(
560 "locale.getdefaultlocale",
561 "{name!r} is deprecated and slated for removal in Python {remove}. "
562 "Use setlocale(), getencoding() and getlocale() instead.",
563 remove=(3, 15))
564
565 try:
566 # check if it's supported by the _locale module
567 import _locale
568 code, encoding = _locale._getdefaultlocale()
569 except (ImportError, AttributeError):
570 pass
571 else:
572 # make sure the code/encoding values are valid
573 if sys.platform == "win32" and code and code[:2] == "0x":
574 # map windows language identifier to language name
575 code = windows_locale.get(int(code, 0))
576 # ...add other platform-specific processing here, if
577 # necessary...
578 return code, encoding
579
580 # fall back on POSIX behaviour
581 import os
582 lookup = os.environ.get
583 for variable in envvars:
584 localename = lookup(variable,None)
585 if localename:
586 if variable == 'LANGUAGE':
587 localename = localename.split(':')[0]
588 break
589 else:
590 localename = 'C'
591 return _parse_localename(localename)

Callers 3

resetlocaleFunction · 0.85
getencodingFunction · 0.85
_print_localeFunction · 0.85

Calls 4

_parse_localenameFunction · 0.85
lookupFunction · 0.70
getMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected