Skip to content

Etree python 3.5 fix#95

Open
57uff3r wants to merge 1 commit into
aerkalov:masterfrom
57uff3r:master
Open

Etree python 3.5 fix#95
57uff3r wants to merge 1 commit into
aerkalov:masterfrom
57uff3r:master

Conversation

@57uff3r

@57uff3r 57uff3r commented Mar 5, 2016

Copy link
Copy Markdown

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

aerkalov commented Apr 2, 2016

Copy link
Copy Markdown
Owner

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
Copy Markdown

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