本文整理汇总了Python中_bootlocale.getpreferredencoding方法的典型用法代码示例。如果您正苦于以下问题:Python _bootlocale.getpreferredencoding方法的具体用法?Python _bootlocale.getpreferredencoding怎么用?Python _bootlocale.getpreferredencoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_bootlocale
的用法示例。
在下文中一共展示了_bootlocale.getpreferredencoding方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getpreferredencoding
# 需要导入模块: import _bootlocale [as 别名]
# 或者: from _bootlocale import getpreferredencoding [as 别名]
def getpreferredencoding(do_setlocale = True):
"""Return the charset that the user is likely using."""
import _bootlocale
return _bootlocale.getpreferredencoding(False)
示例2: getpreferredencoding
# 需要导入模块: import _bootlocale [as 别名]
# 或者: from _bootlocale import getpreferredencoding [as 别名]
def getpreferredencoding(do_setlocale = True):
"""Return the charset that the user is likely using."""
if sys.flags.utf8_mode:
return 'UTF-8'
import _bootlocale
return _bootlocale.getpreferredencoding(False)
示例3: test_universal_newlines_communicate_encodings
# 需要导入模块: import _bootlocale [as 别名]
# 或者: from _bootlocale import getpreferredencoding [as 别名]
def test_universal_newlines_communicate_encodings(self):
# Check that universal newlines mode works for various encodings,
# in particular for encodings in the UTF-16 and UTF-32 families.
# See issue #15595.
#
# UTF-16 and UTF-32-BE are sufficient to check both with BOM and
# without, and UTF-16 and UTF-32.
import _bootlocale
for encoding in ['utf-16', 'utf-32-be']:
old_getpreferredencoding = _bootlocale.getpreferredencoding
# Indirectly via io.TextIOWrapper, Popen() defaults to
# locale.getpreferredencoding(False) and earlier in Python 3.2 to
# locale.getpreferredencoding().
def getpreferredencoding(do_setlocale=True):
return encoding
code = ("import sys; "
r"sys.stdout.buffer.write('1\r\n2\r3\n4'.encode('%s'))" %
encoding)
args = [sys.executable, '-c', code]
try:
_bootlocale.getpreferredencoding = getpreferredencoding
# We set stdin to be non-None because, as of this writing,
# a different code path is used when the number of pipes is
# zero or one.
popen = subprocess.Popen(args, universal_newlines=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
stdout, stderr = popen.communicate(input='')
finally:
_bootlocale.getpreferredencoding = old_getpreferredencoding
self.assertEqual(stdout, '1\n2\n3\n4')
示例4: aliasmbcs
# 需要导入模块: import _bootlocale [as 别名]
# 或者: from _bootlocale import getpreferredencoding [as 别名]
def aliasmbcs():
"""On Windows, some default encodings are not provided by Python,
while they are always available as "mbcs" in each locale. Make
them usable by aliasing to "mbcs" in such a case."""
if sys.platform == 'win32':
import _bootlocale, codecs
enc = _bootlocale.getpreferredencoding(False)
if enc.startswith('cp'): # "cp***" ?
try:
codecs.lookup(enc)
except LookupError:
import encodings
encodings._cache[enc] = encodings._unknown
encodings.aliases.aliases[enc] = 'mbcs'
示例5: _alias_mbcs
# 需要导入模块: import _bootlocale [as 别名]
# 或者: from _bootlocale import getpreferredencoding [as 别名]
def _alias_mbcs(encoding):
try:
import _bootlocale
if encoding == _bootlocale.getpreferredencoding(False):
import encodings.mbcs
return encodings.mbcs.getregentry()
except ImportError:
# Imports may fail while we are shutting down
pass