epdb
epdb copied to clipboard
Decode stdout using preferred encoding not ascii, and combine multibyte as necessary
Original use case was using the rich.inspect within epdb session. https://pypi.org/project/rich/ is coloring output and uses UTF-8 characters for tables etc. epdb client was crashing unable to decode:
(Epdb) rich.inspect(self, value=False)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/yoh/proj/datalad/datalad-mihextras/venvs/dev3/lib/python3.9/site-packages/epdb/__init__.py", line 1091, in connect
t.interact()
File "/home/yoh/proj/datalad/datalad-mihextras/venvs/dev3/lib/python3.9/site-packages/epdb/epdb_client.py", line 146, in interact
sys.stdout.write(text.decode('ascii'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 5: ordinal not in range(128)
-
I think hardcoding to
ascii
is the wrong thing to do since AFAIK there is no guarantee that it would not be UTF-8 -
instead of leaving to default (not providing encoding) decided to go for prefered encoding
-
there is a code block which follows for reading/writing stdin, and I encoded also into preferable encoding which allows now to pass unicode to be encoded to utf-8 happen someone needs to enter it.
Signed-off-by: Yaroslav Halchenko [email protected]
demo of it working:
This looks okay to me, but I'd like at least one other reviewer. @mibanescu or @mtharp, what do you think?
ping @mibanescu @mtharp , your feedback would be appreciated.
ping on this PR -- I keep coming to the need to use patched version. Please let me know if I should improve on anything