Page MenuHomePhabricator

[LNT] Python 3 support: Parse HTML as text
ClosedPublic

Authored by thopre on Oct 10 2019, 1:32 PM.

Details

Summary

Several tests and the testsuite run import code parse text read from the
data attribute of a Flask response object (werkzeug.wrappers.Response).
However, in Python3 reading from that attribute yields binary data.
The attribute is in fact a property whose getter get_data() as a as_text
parameter that allows to request the result to be a string instead.

This commit adapts all reads from that property to request strings
instead of binary data (the default), except for a few cases in
tests/server/ui/V4Pages.py where the data is fed to ElementTree's
fromstring method in get_xml_tree() which tries to reencode it in ascii
in Python 2 mode if it gets a unicode string.

Event Timeline

thopre created this revision.Oct 10 2019, 1:32 PM
thopre updated this revision to Diff 224986.Oct 15 2019, 3:07 AM

Merge more similar cases into this patch

thopre edited the summary of this revision. (Show Details)Oct 15 2019, 3:08 AM

LGTM but someone else must approve.

tests/server/ui/test_api_modify.py
68

Nitpick:

We indeed tend toward assertEqual for Python 3.
You've already replaced one assertEquala with assertEqual in this patch, could you clean this one up as well?

thopre marked 2 inline comments as done.
thopre added inline comments.
tests/server/ui/test_api_modify.py
68

I've made a separate diff fixing all existing use of assertEquals: https://reviews.llvm.org/D71057

PrzemekWirkus accepted this revision.Dec 6 2019, 2:09 AM
This revision is now accepted and ready to land.Dec 6 2019, 2:09 AM
thopre closed this revision.Dec 6 2019, 2:23 AM
thopre marked an inline comment as done.Dec 6 2019, 2:24 AM

Committed as b2e114bd7f7c2d6fe08edbe0c5811768e703727d