From 601007a9a90e318ba276710801b537179df77f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Tue, 8 Jul 2014 14:45:17 +0200 Subject: [PATCH 1/2] bug fix: improve detection of 'cookiejar' argument When passing clean LWPCookieJar() object, it is retyped to False, which resulted in creating new CookieJar(). Comparison to None is necessary. --- simplemediawiki.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simplemediawiki.py b/simplemediawiki.py index b7591d1..7158efb 100644 --- a/simplemediawiki.py +++ b/simplemediawiki.py @@ -103,9 +103,9 @@ def __init__(self, api_url, cookie_file=None, cookiejar=None, self._api_url = api_url self._http_user = http_user self._http_password = http_password - if cookiejar: + if cookiejar is not None: self._cj = cookiejar - elif cookie_file: + elif cookie_file is not None: self._cj = cookielib.LWPCookieJar(cookie_file) try: self._cj.load() From 6f1a27984c89273dc78f2148425ec3e55b1d4e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Tue, 4 Aug 2015 23:40:45 +0200 Subject: [PATCH 2/2] fix exception class for cookie loading In Python2, cookielib.LoadError is a subclass of IOError, but in Python3, http.cookiejar.LoadError is a subclass of OSError. Catching LoadError should be portable enough. --- simplemediawiki.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplemediawiki.py b/simplemediawiki.py index 7158efb..6726bb9 100644 --- a/simplemediawiki.py +++ b/simplemediawiki.py @@ -109,7 +109,7 @@ def __init__(self, api_url, cookie_file=None, cookiejar=None, self._cj = cookielib.LWPCookieJar(cookie_file) try: self._cj.load() - except IOError: + except cookielib.LoadError: self._cj.save() self._cj.load() else: