ยปCore Development>Code coverage>Lib/_bootlocale.py

Python code coverage for Lib/_bootlocale.py

#countcontent
1n/a"""A minimal subset of the locale module used at interpreter startup
2n/a(imported by the _io module), in order to reduce startup time.
3n/a
4n/aDon't import directly from third-party code; use the `locale` module instead!
5n/a"""
6n/a
7n/aimport sys
8n/aimport _locale
9n/a
10n/aif sys.platform.startswith("win"):
11n/a def getpreferredencoding(do_setlocale=True):
12n/a return _locale._getdefaultlocale()[1]
13n/aelse:
14n/a try:
15n/a _locale.CODESET
16n/a except AttributeError:
17n/a if hasattr(sys, 'getandroidapilevel'):
18n/a # On Android langinfo.h and CODESET are missing, and UTF-8 is
19n/a # always used in mbstowcs() and wcstombs().
20n/a def getpreferredencoding(do_setlocale=True):
21n/a return 'UTF-8'
22n/a else:
23n/a def getpreferredencoding(do_setlocale=True):
24n/a # This path for legacy systems needs the more complex
25n/a # getdefaultlocale() function, import the full locale module.
26n/a import locale
27n/a return locale.getpreferredencoding(do_setlocale)
28n/a else:
29n/a def getpreferredencoding(do_setlocale=True):
30n/a assert not do_setlocale
31n/a result = _locale.nl_langinfo(_locale.CODESET)
32n/a if not result and sys.platform == 'darwin':
33n/a # nl_langinfo can return an empty string
34n/a # when the setting has an invalid value.
35n/a # Default to UTF-8 in that case because
36n/a # UTF-8 is the default charset on OSX and
37n/a # returning nothing will crash the
38n/a # interpreter.
39n/a result = 'UTF-8'
40n/a return result