Fix dispatching of webhooks with non-ASCII content by sending only binary strings

Review Request #8560 — Created Dec. 4, 2016 and submitted — Latest diff uploaded

Information

Review Board
master
f026695...

Reviewers

When dispatching a webhook that contained non-ASCII content, the urlopen call raised an exception
that reported an encoding error, complaining that some characters are not encodable with the ascii
encoding.

This issue occurs because the urlopen implementation concatenates the given URL, headers, and body
using string concatenation, and, if the resulting string is a unicode string, encodes it implicitly
as ASCII before sending it to the server.

This change encodes all data passed to urlopen as binary strings, so that the result of string
concatenation is also a binary string, thus necessitating no implicit encoding. While writing tests
for this issue, an issue with silently swallowed assertions in the test _urlopen was fixed.

Added 4 unit tests for non-ASCII custom, JSON, XML and Form-Data content.
Checked locally that payloads are sent without issue.
Added check that all data sent to _test_dispatch is made of binary strings.