當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。