New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetMondrianData() returns bytes, not characters/strings #959

Closed
sinkva opened this Issue Aug 12, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@sinkva
Copy link

sinkva commented Aug 12, 2018

Operating system: MacOS 10.13.5
wxPython version: 4.0.3 (Stock)
Python version: 3.7.0 (Stock)

Running thumbnailctrl.py gives:
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/wx/lib/agw/thumbnailctrl.py", line 204, in GetMondrianImage
stream = six.StringIO(GetMondrianData())
TypeError: initial_value must be str or None, not bytes

The description of GetMondrianData() says:
Returns a default image placeholder as a decompressed stream of characters.

But GetMondrianData() at
https://github.com/wxWidgets/Phoenix/blob/master/wx/lib/agw/thumbnailctrl.py
def GetMondrianData():
""" Returns a default image placeholder as a decompressed stream of characters. """
return
b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00
\x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID
ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16
o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80
\xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-\x9fQ\xe9\ \x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\ \x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB\x82'

Which is a byte-stream.

@mesalu

This comment has been minimized.

Copy link
Collaborator

mesalu commented Aug 12, 2018

Images aren't pure ascii/utf-8 characters, but rather binary data. As such, you're dealing with bytes that don't have may not have any relation to the typical character encoding schemas like ascii/utf-8.
In python3 (more so than python2) data like this is preferred to be handled as byte-strings, rather than character strings.)
If anything, I'd say there's a defect in the docstring for hinting at string-usability. I recommend using six.BytesIO rather than six.StringIO

@mesalu mesalu added the not-a-bug label Aug 12, 2018

@mesalu mesalu closed this Aug 13, 2018

@RobinD42

This comment has been minimized.

Copy link
Member

RobinD42 commented Aug 13, 2018

GetMondrianImage needs to be changed to use BytesIO.

@RobinD42 RobinD42 reopened this Aug 13, 2018

@RobinD42 RobinD42 added bug and removed not-a-bug labels Aug 13, 2018

@mesalu

This comment has been minimized.

Copy link
Collaborator

mesalu commented Aug 14, 2018

Oh, my bad. I though StrinIO was coming from submitter's code. Ooops, sorry all.

I'll create a PR for this shortly.

@mesalu mesalu referenced this issue Aug 14, 2018

Merged

Fix 959 #962

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment