Replaced ansi encoding with cp1252
Python3 does not support (or no longer supports) encode('ansi'), I replaced this with encode('cp1252') which resolved the issue. Tested with Python 3.9.8, no errors that I am aware of.
Rather poor idea.
One has to call GetACP() and, if Python does not understand integer charset identificatior, convert it to strings like windows-1251.
- https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-getacp
- https://github.com/VFPX/Win32API/blob/master/libraries/kernel32/GetACP.md
Also, strings like "cp1252" AFAIR are legacy compatibility stubs anyway. Canonical form is "windows-"-prefixed. See chapters 9 and 4.2
- https://encoding.spec.whatwg.org/#windows-1252
- https://gist.github.com/trietptm/a2581ed4eadccb32609f9e23a6e6677b
- https://programtalk.com/python-more-examples/ctypes.windll.kernel32.GetACP/
- https://www.programcreek.com/python/example/128151/_winapi.GetACP
...and still i am wrong.
cipher = MobaXtermCrypto(sys.argv[1].encode('cp1252')
Since this is a text application, not GUI, then GetOEMCP() should be called, not GetACP().
- https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-getoemcp
- https://github.com/VFPX/Win32API/blob/master/libraries/kernel32/GetOEMCP.md
also
- https://stackoverflow.com/questions/52654470/get-a-code-page-for-each-locale-in-oem-and-ansi
Sadly, Python has "encode.mbcs" module (according to docs, it is a module not const) - s.encode('mbcs') for graphic apps, but not a text-mode counterpart.
There are also https://docs.python.org/3/library/sys.html
- sys.getdefaultencoding()
- sys.stdout.encoding() - sadly "On Windows, UTF-8 is used for the console device."
However https://habr.com/ru/articles/117236/ witnesses
>>> print sys.stdout.encoding # win32
cp866
...and still i am wrong.
Twice wrong actually.
Test shown, the Py3 runtime handles command line optinss encoding. So, only the .ini file and the registry encodings should be handled. But since MobaXTerm itself is GUI app, then it uses GUI charset, which on Python/Windows is "mbcs"