brython-dev / brython

Brython (Browser Python) is an implementation of Python 3 running in the browser
BSD 3-Clause "New" or "Revised" License
6.4k stars 512 forks source link

Cannot convert sting to UTF16 #2438

Closed mbasaglia closed 6 months ago

mbasaglia commented 6 months ago

I'm struggling with encoding strings to UTF16.

If I try this

"a".encode("utf_16_le")

I get

TypeError: 'utf_16_le' codec returns UndefinedType, not bytes

(I get the same error by using the bytes constructor)

Encoding to UTF8 works fine though

PierreQuentel commented 6 months ago

Thanks for the report @mbasaglia !

The commit fixes the bug and also implements utf_16_be and utf-32 encoding / decoding, but still some work ahead (error handling among others).