wikitools
wikitools copied to clipboard
new: use ``requests`` instead of ``urllib2``.
This avoids much of hassle with gzip encoding, multipart, authentification, url encoding... which this module should avoid managing because requests does it better and is widely supported and tested. This allows wikitools to concentrate on its main task.
Please don't accept this code for now: as there are no tests, I didn't check enough yet the multipart and encoding parts... This is a quick overview and I wanted to know if you are open to this type of changes.
I would have also other changes to propose (I wanted to apply some general PEP8 considerations), would you be open to such pull-request ?
Do you know if third party software are currently relying on your code ? I just want to get in hand some code to test that nothing is broken.
Thank you very much for your work on wiki-tools !
This looks pretty interesting. I'm not normally a fan of adding dependencies on 3rd party software, but Requests looks pretty-well established (it's already installed by default on Wikimedia's Tool Labs platform)
In terms of testing, since everything calls APIRequest the same way, if it can log in and stay logged in, then everything else should work in theory. Perhaps another check of unicode handling. So a bare minimum test case would be
from wikitools import wiki, page
site = wiki.Wiki("https://en.wikipedia.org/w/api.php")
site.login("username", "password")
print site.isLoggedIn() # Should return True
p = page.Page(site, "Güçlükonak")
print p.title
The only thing this doesn't test is HTTP Auth (which isn't actually tested currently, since I don't have a place to test it).
I'd be interested in just about any improvements as long as they don't do anything like change public function inputs/outputs (I have sort of a grand plan for wikitools 2.0 that will change some of the less-optimal ones, but work on that is probably at least a few months away)
Using requests would improve security as well--requests automatically checks for ssl certificate validity, which urllib2 does not support at all.
As poster is unavailable for Python 3, I'm using requests in the Python 3 version I'm working on. The code here was useful in making the change - e5bc068b7c2d09bd8b8b5e4774be8094b83898ae - I've gotten it working for uploads, but haven't been able to test HTTP Auth.