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

Etree python 3.5 fix #95

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

Etree python 3.5 fix #95

wants to merge 1 commit into from

Conversation

57uff3r
Copy link

@57uff3r 57uff3r commented Mar 5, 2016

I've found some problems with etree and python 3. Etree component was returning bites in python 3 instead of unicode string and I made small change to fix this problems.

[https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring](XML etree documentation)

Use encoding="unicode" to generate a Unicode string (otherwise, a bytestring is generated)

@aerkalov
Copy link
Owner

aerkalov commented Apr 2, 2016

I checked it out and I would say this should be the fix. The problem is that we are trying to find 'str' in 'bytes', and that would fail. In the rest of the code we return 'bytes' all the time, so I assume we should do it also this time, and if you would need Unicode string you should convert it manually. Will think about this issue a bit more.

tree_str = etree.tostring(body, pretty_print=True, encoding='utf-8', xml_declaration=False)

if tree_str.startswith(six.b('<body>')):
    n = tree_str.rindex(six.b('</body>'))
    return tree_str[7:n]

@highpost
Copy link

This appears to be a limitation of XML. So you may want to add your example of how to handle Unicode strings to the documentation.

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