Adam Williamson 17841107c0 Initial Python 3 port
This does enough Python 3 porting to make Tahrir run and do some
basic stuff under Python 3 - I've tested creating badges and
series, issuing badges, clicking around in Leaderboard and
Explore, looking at RSS and JSON views of things. This does not
break Python 2 compatibility - I'd rather not do that yet so we
can test things easily both ways and identify any differences.
We could remove Python 2 compat later.

Most of the changes are based on 2to3 suggestions and are pretty
self-explanatory. Some less obvious ones:

* The str_to_bytes and dogpile stuff: well, see
https://github.com/sqlalchemy/dogpile.cache/issues/159 . The
`sha1_mangle_key` mangler that we're using, which is provided by
dogpile, needs input as a bytestring. This is pretty awkward. It
obviously caused *some* problems even in Python 2 (as this app
explicitly uses unicodes in some places), but in Python 3 it's
worse; everywhere you see `str_to_bytes` being called is a place
where I found a crash because we wound up sending a non-encoded
`str` to `sha1_mangle_key` (or, in the case of `email_md5` and
`email_sha1`, to hashlib directly).

* map moved in Python 3; 2to3 suggests handling it with a six
move, but I preferred just replacing all the `map` uses with

* 2to3 recommended a change to strip_tags, but I noticed it is
not actually used any more. It was used to sanitize HTML input
to the admin route back when it was added, but the admin route
was entirely rewritten later and the use of strip_tags was taken
out. So I just removed strip_tags and its supporting players.

* merge_dicts is used in places where we were merging two dicts
in a single expression by converting them to lists, combining
the lists, and turning the combined list back into a dict again.
You can still do this in Python 3 but you have to add extra
`list()` calls and it gets really ugly. Per
it's also not resource-efficient, so this seems like a better
approach - it's informed by the code in that SO question but I
wrote the function myself rather than taking one from that page
to avoid technically having a tiny bit of CC-BY-SA code in this
AGPL project.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
2019-08-12 21:53:39 +02:00
__init__.py Add a test suite. 2019-01-21 08:34:57 -05:00
test_utils.py Initial Python 3 port 2019-08-12 21:53:39 +02:00