Skip to content
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

fix: decode bytes not str (easy_xml.py) #160

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

owl-from-hogvarts
Copy link
Contributor

See nodejs/node-gyp/issues/2505

proper fix for #118
Special thanks to @cclauss

@cclauss
Copy link
Contributor

cclauss commented Aug 30, 2022

Please rebase so we can ensure that the tests pass.

proper fix for nodejs#118
Special thanks to @cclauss
@owl-from-hogvarts
Copy link
Contributor Author

Please rebase so we can ensure that the tests pass.

Done

xml_string = xml_string.encode(encoding)
if sys.platform == "win32":
if isinstance(xml_string, str):
xml_string = xml_string.decode("cp1251") # str --> bytes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems incorrect to me. XmlToString always returns a str and a str object has no attribute decode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct: str.encode() and bytes.decode() exist but the opposites are undefined.

>>> for s_or_b in ("s", b"b"):
...     for method_name in ("encode", "decode"):
...         print(f"{s_or_b}: {method_name} is {getattr(s_or_b, method_name, None)}")
...
s: encode is <built-in method encode of str object at 0x103cbe928>
s: decode is None
b'b': encode is None
b'b': decode is <built-in method decode of bytes object at 0x103cb4bf0>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants