def _alias_mbcs(encoding): try: import _bootlocale if encoding == _bootlocale.getpreferredencoding(False): import encodings.mbcs return encodings.mbcs.getregentry() except ImportError: pass
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
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'
def getpreferredencoding(do_setlocale=True): """Return the charset that the user is likely using, according to the system configuration.""" import _bootlocale if do_setlocale: oldloc = setlocale(LC_CTYPE) try: setlocale(LC_CTYPE, '') except Error: pass result = _bootlocale.getpreferredencoding(False) if do_setlocale: setlocale(LC_CTYPE, oldloc) return result
def aliasmbcs(): if sys.platform == 'win32': if sys.version_info < (3, 0): import locale, codecs enc = locale.getdefaultlocale()[1] else: import _bootlocale, codecs enc = _bootlocale.getpreferredencoding(False) if enc.startswith('cp'): try: codecs.lookup(enc) except LookupError: import encodings encodings._cache[enc] = encodings._unknown encodings.aliases.aliases[enc] = 'mbcs'
def update_event(self, inp=-1): self.set_output_val(0, _bootlocale.getpreferredencoding(self.input(0)))
def getpreferredencoding(do_setlocale=True): """Return the charset that the user is likely using.""" import _bootlocale return _bootlocale.getpreferredencoding(False)