Update webhook support for Python 3.x and Django 1.11.

Review Request #10483 — Created March 31, 2019 and submitted

Information

Review Board
release-4.0.x

Reviewers

This brings Python 3.x and Django 1.11 support to our webhook code.
There were a few key areas that required some rethinking in order for
modern support:

  1. Python 2 has a long type, but Python 3 does not, so we just
    needed to alias long to int for testing purposes.

  2. Python 3.x's JSON support doesn't handle sorting of non-string keys.
    They recommend avoiding non-string keys entirely, but it only breaks
    when sorting. However, our XML and custom payloads support them. We
    now normalize keys to strings if we know we're going to run the
    data through a JSON encoder.

  3. We were outputting byte strings for JSON and form-data payloads,
    but Unicode strings for XML. We're now consistent in the format
    returned across all types.

  4. Django 1.6 and 1.11 have different setup requirements for manually
    parsing templates and getting results. This has to be solved with a
    version check, and using different logic for each version of Django.

  5. Django 1.11 tries to be helpful when encountering an invalid block
    tag, making recommendations about loading libraries. We don't want
    this at all, since users don't have this option with our webhook
    templates, so we now override this error message to be less helpful.

Unit tests pass for Python 2.7 with Django 1.6 and 3.5-3.7 with
Django 1.11 (with other in-progress changes).

Summary ID
Update webhook support for Python 3.x and Django 1.11.
This brings Python 3.x and Django 1.11 support to our webhook code. There were a few key areas that required some rethinking in order for modern support: 1. Python 2 has a `long` type, but Python 3 does not, so we just needed to alias `long` to `int` for testing purposes. 2. Python 3.x's JSON support doesn't handle sorting of non-string keys. They recommend avoiding non-string keys entirely, but it only breaks when sorting. However, our XML and custom payloads support them. We now normalize keys to strings if we know we're going to run the data through a JSON encoder. 3. We were outputting byte strings for JSON and form-data payloads, but Unicode strings for XML. We're now consistent in the format returned across all types. 4. Django 1.6 and 1.11 have different setup requirements for manually parsing templates and getting results. This has to be solved with a version check, and using different logic for each version of Django. 5. Django 1.11 tries to be helpful when encountering an invalid block tag, making recommendations about loading libraries. We don't want this at all, since users don't have this option with our webhook templates, so we now override this error message to be less helpful.
00adba5d03b7804b288ba079ff7124a0bba058c3
Description From Last Updated

E251 unexpected spaces around keyword / parameter equals

reviewbotreviewbot

E131 continuation line unaligned for hanging indent

reviewbotreviewbot

F821 undefined name 'get_text_list'

reviewbotreviewbot

F821 undefined name 'parse_unil'

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-4.0.x (ef0c0aa)