Initial commit from pywikibot-compat

With some local modifications for pep8

Change-Id: I0b3058bedd03971d998ddb957c8c0c5b670e967c