# Return the registry entry
return entry
-# Register the search_function in the Python codec registry
-codecs.register(search_function)
-
if sys.platform == 'win32':
def _alias_mbcs(encoding):
try:
# Imports may fail while we are shutting down
pass
+ # It must be registered before search_function()
codecs.register(_alias_mbcs)
+
+# Register the search_function in the Python codec registry
+codecs.register(search_function)
name += "_codec"
elif encoding == "latin_1":
name = "latin_1"
- self.assertEqual(encoding.replace("_", "-"), name.replace("_", "-"))
+ # Skip the mbcs alias on Windows
+ if name != "mbcs":
+ self.assertEqual(encoding.replace("_", "-"),
+ name.replace("_", "-"))
(b, size) = codecs.getencoder(encoding)(s)
self.assertEqual(size, len(s), "encoding=%r" % encoding)
self.assertEqual(decoded, ('abc', 3))
def test_mbcs_alias(self):
- # Check that looking up our 'default' codepage will return
- # mbcs when we don't have a more specific one available
- with mock.patch('_winapi.GetACP', return_value=123):
- codec = codecs.lookup('cp123')
- self.assertEqual(codec.name, 'mbcs')
+ # On Windows, the encoding name must be the ANSI code page
+ encoding = locale.getpreferredencoding(False)
+ self.assertTrue(encoding.startswith('cp'), encoding)
+
+ # The encodings module create a "mbcs" alias to the ANSI code page
+ codec = codecs.lookup(encoding)
+ self.assertEqual(codec.name, "mbcs")
@support.bigmemtest(size=2**31, memuse=7, dry_run=False)
def test_large_input(self, size):
# 'help' should be set in builtins
self.assertTrue(hasattr(builtins, "help"))
- def test_aliasing_mbcs(self):
- if sys.platform == "win32":
- import locale
- if locale.getdefaultlocale()[1].startswith('cp'):
- for value in encodings.aliases.aliases.values():
- if value == "mbcs":
- break
- else:
- self.fail("did not alias mbcs")
-
def test_sitecustomize_executed(self):
# If sitecustomize is available, it should have been imported.
if "sitecustomize" not in sys.modules: