[issue33865] [EASY] Missing code page aliases: "unknown encoding: 874"

Karthikeyan Singaravelan report at bugs.python.org
Sat Jun 16 08:01:24 EDT 2018


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

I am able to verify the newly added aliases using the below assert statement

assert codecs.encode('a', '874') == codecs.encode('a', 'cp874')

I am struck on the part where it could be patched in the search_function and I hope this is the approach @serhiy.storchaka was making. After the usual logic I am checking if the aliased_encoding is None and if the normalized_encoding is all digits then I am prepending 'cp' in front and calling search_function again so that cases like '936' first look at the table which has higher precedence and then for other cases even though an entry is not present it returns 'cpXXXX' encoder. 

I have tested it by removing newly added '874' from aliases.py so that instead of an error 'cp874' is returned. Since in the next call the case of encoding being digits is not valid due to prepending 'cp' there will be no error due to infinite recursion for wrong ones.

Thanks

----------
Added file: https://bugs.python.org/file47643/33865.patch

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33865>
_______________________________________


More information about the Python-bugs-list mailing list