jenkins-bot has submitted this change and it was merged.
Change subject: fileIsShared fails on sites with shared file repo ......................................................................
fileIsShared fails on sites with shared file repo
"missing" exists in page dict when the file is shared.
KeyError occurs for file on a shared repo if the file is not a local file. To prevent KeyError, check if 'imageinfo' exists first, then if 'missing' exists the page does not exist.
Bug: 70494 Change-Id: I2cfbbd2434cb03600c9d53e648e0534f05756d46 --- M pywikibot/page.py M pywikibot/site.py M tests/file_tests.py 3 files changed, 9 insertions(+), 9 deletions(-)
Approvals: John Vandenberg: Looks good to me, but someone else must approve Mpaa: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 1fc54eb..5484370 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -1860,8 +1860,6 @@ # TODO: put the URLs to family file if not self.site.has_image_repository: return False - elif not self.exists(): - raise pywikibot.NoPage(self) elif 'wikitravel_shared' in self.site.shared_image_repository(): return self.fileUrl().startswith( u'http://wikitravel.org/upload/shared/') diff --git a/pywikibot/site.py b/pywikibot/site.py index 6825a26..b520fef 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -33,6 +33,7 @@ from pywikibot.data import api from pywikibot.exceptions import ( Error, + PageRelatedError, PageSaveRelatedError, EditConflict, PageCreatedConflict, @@ -2017,12 +2018,13 @@ u"loadimageinfo: Query on %s returned data on '%s'" % (page, pageitem['title'])) api.update_page(page, pageitem) - if "missing" in pageitem: - raise pywikibot.NoPage(page) if "imageinfo" not in pageitem: - raise Error( - u"loadimageinfo: Query on %s returned no imageinfo" - % page) + if "missing" in pageitem: + raise NoPage(page) + + raise PageRelatedError( + page, + u"loadimageinfo: Query on %s returned no imageinfo") return (pageitem['imageinfo'] if history else pageitem['imageinfo'][0])
diff --git a/tests/file_tests.py b/tests/file_tests.py index 7e83d0b..dc4a3b3 100644 --- a/tests/file_tests.py +++ b/tests/file_tests.py @@ -28,11 +28,11 @@ self.assertFalse(itwp_file.exists()) self.assertTrue(commons_file.exists())
- self.assertRaises(pywikibot.NoPage, itwp_file.fileIsShared) + self.assertTrue(itwp_file.fileIsShared()) self.assertTrue(commons_file.fileIsShared()) self.assertTrue(commons_file.fileUrl())
- self.assertRaises(pywikibot.NoPage, itwp_file.fileUrl) + self.assertIn('/wikipedia/commons/', itwp_file.fileUrl()) self.assertRaises(pywikibot.NoPage, itwp_file.get)
def testLocalOnly(self):
pywikibot-commits@lists.wikimedia.org