Python encodings.normalize_encoding() Examples
The following are 30
code examples of encodings.normalize_encoding().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
encodings
, or try the search function
.
Example #1
Source File: locale.py From python with Apache License 2.0 | 6 votes |
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
Example #2
Source File: locale.py From android_universal with MIT License | 6 votes |
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
Example #3
Source File: locale.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #4
Source File: locale.py From odoo13-x64 with GNU General Public License v3.0 | 6 votes |
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
Example #5
Source File: codecs.py From Emoji-Tools with GNU General Public License v3.0 | 6 votes |
def search_function(name): name = encodings.normalize_encoding(name) # Rather undocumented... if name in _extended_encodings: if name not in _cache: base_encoding, mapping = _extended_encodings[name] assert(name[-4:] == "_ttx") # Python 2 didn't have any of the encodings that we are implementing # in this file. Python 3 added aliases for the East Asian ones, mapping # them "temporarily" to the same base encoding as us, with a comment # suggesting that full implementation will appear some time later. # As such, try the Python version of the x_mac_... first, if that is found, # use *that* as our base encoding. This would make our encoding upgrade # to the full encoding when and if Python finally implements that. # http://bugs.python.org/issue24041 base_encodings = [name[:-4], base_encoding] for base_encoding in base_encodings: try: codecs.lookup(base_encoding) except LookupError: continue _cache[name] = ExtendCodec(name, base_encoding, mapping) break return _cache[name].info return None
Example #6
Source File: test_codecs.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def setUp(self): # There's no way to unregister a codec search function, so we just # ensure we render this one fairly harmless after the test # case finishes by using the test case repr as the codec name # The codecs module normalizes codec names, although this doesn't # appear to be formally documented... # We also make sure we use a truly unique id for the custom codec # to avoid issues with the codec cache when running these tests # multiple times (e.g. when hunting for refleaks) unique_id = repr(self) + str(id(self)) self.codec_name = encodings.normalize_encoding(unique_id).lower() # We store the object to raise on the instance because of a bad # interaction between the codec caching (which means we can't # recreate the codec entry) and regrtest refleak hunting (which # runs the same test instance multiple times). This means we # need to ensure the codecs call back in to the instance to find # out which exception to raise rather than binding them in a # closure to an object that may change on the next run self.obj_to_raise = RuntimeError
Example #7
Source File: locale.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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
Example #8
Source File: locale.py From python2017 with MIT License | 6 votes |
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
Example #9
Source File: test_codecs.py From ironpython3 with Apache License 2.0 | 6 votes |
def setUp(self): # There's no way to unregister a codec search function, so we just # ensure we render this one fairly harmless after the test # case finishes by using the test case repr as the codec name # The codecs module normalizes codec names, although this doesn't # appear to be formally documented... # We also make sure we use a truly unique id for the custom codec # to avoid issues with the codec cache when running these tests # multiple times (e.g. when hunting for refleaks) unique_id = repr(self) + str(id(self)) self.codec_name = encodings.normalize_encoding(unique_id).lower() # We store the object to raise on the instance because of a bad # interaction between the codec caching (which means we can't # recreate the codec entry) and regrtest refleak hunting (which # runs the same test instance multiple times). This means we # need to ensure the codecs call back in to the instance to find # out which exception to raise rather than binding them in a # closure to an object that may change on the next run self.obj_to_raise = RuntimeError
Example #10
Source File: locale.py From ironpython3 with Apache License 2.0 | 6 votes |
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
Example #11
Source File: locale.py From scylla with Apache License 2.0 | 6 votes |
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
Example #12
Source File: locale.py From Imogen with MIT License | 6 votes |
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
Example #13
Source File: locale.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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
Example #14
Source File: locale.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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
Example #15
Source File: test_codecs.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def setUp(self): # There's no way to unregister a codec search function, so we just # ensure we render this one fairly harmless after the test # case finishes by using the test case repr as the codec name # The codecs module normalizes codec names, although this doesn't # appear to be formally documented... # We also make sure we use a truly unique id for the custom codec # to avoid issues with the codec cache when running these tests # multiple times (e.g. when hunting for refleaks) unique_id = repr(self) + str(id(self)) self.codec_name = encodings.normalize_encoding(unique_id).lower() # We store the object to raise on the instance because of a bad # interaction between the codec caching (which means we can't # recreate the codec entry) and regrtest refleak hunting (which # runs the same test instance multiple times). This means we # need to ensure the codecs call back in to the instance to find # out which exception to raise rather than binding them in a # closure to an object that may change on the next run self.obj_to_raise = RuntimeError
Example #16
Source File: encoding.py From nzb-subliminal with GNU General Public License v3.0 | 6 votes |
def get_encoding(html_string): """ Performs a simple RE based parsing of a HTML page (represented as a string) and extracts declared character encoding from the meta tags. If the extraction is successful, the encoding is returned. Otherwise, None is returned. """ re_meta1 = re.compile('''<meta\s+http-equiv=['"]?content-type['"]?\s+content=['"]?[^'"]*charset=([^'"]+)''', re.I) re_meta2 = re.compile('''<meta\s+content=['"]?[^'"]*charset=([^'"]+)['"]?\s+http-equiv=['"]?content-type['"]?''', re.I) re_meta3 = re.compile('''<meta\s+http-equiv=['"]?charset['"]?\s+content=['"]?([^'"]+)''', re.I) re_meta4 = re.compile('''<meta\s+content=['"]?([^'"]+)['"]?\s+http-equiv=['"]?charset['"]?''', re.I) re_meta5 = re.compile('''<meta\s+charset=['"]?([^'"]+)''', re.I) for re_meta in (re_meta1, re_meta2, re_meta3, re_meta4, re_meta5): m = re_meta.search(html_string) if m: meta_encoding = m.group(1) return normalize_encoding(meta_encoding) return None
Example #17
Source File: encoding.py From codimension with GNU General Public License v3.0 | 6 votes |
def decodeURLContent(content): """Decodes the content read from a URL""" project = GlobalData().project if project.isLoaded(): projectEncoding = project.props['encoding'] if projectEncoding: if not isValidEncoding(projectEncoding): raise Exception( "The prject encoding " + projectEncoding + " is invalid. " "Please select a valid one in the project properties and " "try again.") return content.decode( encodings.normalize_encoding(projectEncoding)) # Check the IDE wide encoding ideEncoding = Settings()['encoding'] if ideEncoding: if not isValidEncoding(ideEncoding): raise Exception("The ide encoding " + ideEncoding + " is invalid. " "Please set a valid one and try again.") return content.decode(encodings.normalize_encoding(ideEncoding)) # The default one return content.decode(DEFAULT_ENCODING)
Example #18
Source File: locale.py From kobo-predict with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #19
Source File: encoding.py From codimension with GNU General Public License v3.0 | 5 votes |
def getNormalizedEncoding(enc, validityCheck=True): """Returns a normalized encoding or throws an exception""" if validityCheck: if not isValidEncoding(enc): raise Exception('Unsupported encoding ' + enc) norm_enc = encodings.normalize_encoding(enc).lower() return encodings.aliases.aliases.get(norm_enc, norm_enc)
Example #20
Source File: locale.py From unity-python with MIT License | 5 votes |
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
Example #21
Source File: locale.py From PokemonGo-DesktopMap with MIT License | 5 votes |
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
Example #22
Source File: __init__.py From bazarr with GNU General Public License v3.0 | 5 votes |
def search_function(encoding): """ Register our "bad codecs" with Python's codecs API. This involves adding a search function that takes in an encoding name, and returns a codec for that encoding if it knows one, or None if it doesn't. The encodings this will match are: - Encodings of the form 'sloppy-windows-NNNN' or 'sloppy-iso-8859-N', where the non-sloppy version is an encoding that leaves some bytes unmapped to characters. - The 'utf-8-variants' encoding, which has the several aliases seen above. """ if encoding in _CACHE: return _CACHE[encoding] norm_encoding = normalize_encoding(encoding) codec = None if norm_encoding in UTF8_VAR_NAMES: from ftfy.bad_codecs.utf8_variants import CODEC_INFO codec = CODEC_INFO elif norm_encoding.startswith('sloppy_'): from ftfy.bad_codecs.sloppy import CODECS codec = CODECS.get(norm_encoding) if codec is not None: _CACHE[encoding] = codec return codec
Example #23
Source File: locale.py From ironpython2 with Apache License 2.0 | 5 votes |
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
Example #24
Source File: locale.py From syntheticmass with Apache License 2.0 | 5 votes |
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
Example #25
Source File: encoding.py From Cloudmare with GNU General Public License v3.0 | 5 votes |
def _c18n_encoding(encoding): """Cannonicalize an encoding name This performs normalization and translates aliases using python's encoding aliases """ normed = encodings.normalize_encoding(encoding).lower() return encodings.aliases.aliases.get(normed, normed)
Example #26
Source File: locale.py From oss-ftp with MIT License | 5 votes |
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
Example #27
Source File: locale.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
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
Example #28
Source File: locale.py From PhonePi_SampleServer with MIT License | 5 votes |
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
Example #29
Source File: locale.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
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
Example #30
Source File: locale.py From datafari with Apache License 2.0 | 5 votes |
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