当前位置: 首页>>代码示例>>Python>>正文


Python _bootlocale.getpreferredencoding方法代码示例

本文整理汇总了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) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:6,代码来源:locale.py

示例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) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:8,代码来源:locale.py

示例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') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:33,代码来源:test_subprocess.py

示例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' 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:16,代码来源:site.py

示例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 
开发者ID:Yeah-Kun,项目名称:python,代码行数:11,代码来源:__init__.py


注:本文中的_bootlocale.getpreferredencoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。