jenkins-bot has submitted this change and it was merged.
Change subject: site.py: fix unpickling for TokenWallet ......................................................................
site.py: fix unpickling for TokenWallet
pickle.loads(pickle.dump(site)) was failing. Added also unpickling test for Page.
Change-Id: I40d3daabb920d1d0b32f858b9caf12d17a8d149d --- M pywikibot/site.py M tests/page_tests.py M tests/site_tests.py 3 files changed, 10 insertions(+), 7 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index 245115a..5d38dbd 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1314,7 +1314,7 @@ ])
def __init__(self, code, fam=None, user=None, sysop=None): - """ Constructor. """ + """Constructor.""" BaseSite.__init__(self, code, fam, user, sysop) self._msgcache = {} self._loginstatus = LoginStatus.NOT_ATTEMPTED @@ -1322,14 +1322,14 @@ self.tokens = TokenWallet(self)
def __getstate__(self): - """ Remove token wallet before pickling. """ + """Remove TokenWallet before pickling, for security reasons.""" new = super(APISite, self).__getstate__() del new['tokens'] return new
def __setstate__(self, attrs): - """ Restore things removed in __getstate__. """ - super(APISite, self).__setstate__() + """Restore things removed in __getstate__.""" + super(APISite, self).__setstate__(attrs) self.tokens = TokenWallet(self)
@staticmethod diff --git a/tests/page_tests.py b/tests/page_tests.py index 7dc7537..5883922 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -438,8 +438,9 @@ def testPickleAbility(self): mainpage = self.get_mainpage() import pickle - pickle.dumps(mainpage) - self.assertTrue(True) # No exception thrown! + mainpage_str = pickle.dumps(mainpage) + mainpage_unpickled = pickle.loads(mainpage_str) + self.assertEqual(mainpage, mainpage_unpickled)
def testRepr(self): mainpage = self.get_mainpage() diff --git a/tests/site_tests.py b/tests/site_tests.py index 592751b..6b8295f 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -64,7 +64,9 @@ def testPickleAbility(self): import pickle mysite = self.get_site() - pickle.dumps(mysite) + mysite_str = pickle.dumps(mysite) + mysite_pickled = pickle.loads(mysite_str) + self.assertEqual(mysite, mysite_pickled)
def testBaseMethods(self): """Test cases for BaseSite methods."""
pywikibot-commits@lists.wikimedia.org