我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用encodings.aliases()。
def _replace_encoding(code, encoding): if '.' in code: langname = code[:code.index('.')] else: langname = code # Convert the encoding to a C lib compatible encoding string norm_encoding = encodings.normalize_encoding(encoding) #print('norm encoding: %r' % norm_encoding) norm_encoding = encodings.aliases.aliases.get(norm_encoding.lower(), norm_encoding) #print('aliased encoding: %r' % norm_encoding) encoding = norm_encoding norm_encoding = norm_encoding.lower() if norm_encoding in locale_encoding_alias: encoding = locale_encoding_alias[norm_encoding] else: norm_encoding = norm_encoding.replace('_', '') norm_encoding = norm_encoding.replace('-', '') if norm_encoding in locale_encoding_alias: encoding = locale_encoding_alias[norm_encoding] #print('found encoding %r' % encoding) return langname + '.' + encoding
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 ### Database # # The following data was extracted from the locale.alias file which # comes with X11 and then hand edited removing the explicit encoding # definitions and adding some more aliases. The file is usually # available as /usr/lib/X11/locale/locale.alias. # # # The local_encoding_alias table maps lowercase encoding alias names # to C locale encoding names (case-sensitive). Note that normalize() # first looks up the encoding in the encodings.aliases dictionary and # then applies this mapping to find the correct C lib name for the # encoding. #
def getpreferredencoding(do_setlocale = True): """Return the charset that the user is likely using, according to the system configuration.""" if do_setlocale: oldloc = setlocale(LC_CTYPE) try: setlocale(LC_CTYPE, "") except Error: pass result = nl_langinfo(CODESET) setlocale(LC_CTYPE, oldloc) return result else: return nl_langinfo(CODESET) ### Database # # The following data was extracted from the locale.alias file which # comes with X11 and then hand edited removing the explicit encoding # definitions and adding some more aliases. The file is usually # available as /usr/lib/X11/locale/locale.alias. # # # The local_encoding_alias table maps lowercase encoding alias names # to C locale encoding names (case-sensitive). Note that normalize() # first looks up the encoding in the encodings.aliases dictionary and # then applies this mapping to find the correct C lib name for the # encoding. #
def _replace_encoding(code, encoding): if '.' in code: langname = code[:code.index('.')] else: langname = code # Convert the encoding to a C lib compatible encoding string norm_encoding = encodings.normalize_encoding(encoding) #print('norm encoding: %r' % norm_encoding) norm_encoding = encodings.aliases.aliases.get(norm_encoding, norm_encoding) #print('aliased encoding: %r' % norm_encoding) encoding = locale_encoding_alias.get(norm_encoding, norm_encoding) #print('found encoding %r' % encoding) return langname + '.' + encoding