Make __str__ python3 compatible

To make a python 2 & 3 compatible code base, we need to have
a __str__ function that returns bytes on python 2 and unicode
on python 3. This Unicodemixin handles this, by using
__unicode__, and encoding that to utf-8 to get bytes.

Change-Id: I7229b884b630c0d05e2ebe171edec81511d7940b
Make tests/api_tests.py run on py3k

Syntactic/import changes:
comms/http.py syntax/import
data/wikidataquery.py import
pywikibot/textlib.py syntax


More elaborate changes:
comms/threadedhttp.py: import, plus adapt DummyResponse/DummyRequest
                       to have Python3 urllib's required parameters
pywikibot/throttle.py: close throttle file after use
userinterfaces/terminal_interface_unix.py: only encode when target stream
                       is a bytes stream (i.e. doesn't have encoding
                       property)

tests/api_tests.py: cleanup to more specific assertions.

Change-Id: Ib639e7dc70ffc5f192aefacf64e2770c80629c8a
Merge "Make __str__ python3 compatible"
Merge "Make tests/api_tests.py run on py3k"