jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/630384 )
Change subject: [bugfix] Raise RuntimeError instead of AttributeError for old wikis ......................................................................
[bugfix] Raise RuntimeError instead of AttributeError for old wikis
- raise RuntimeError if version is outdated at an early point - add ecoreality to Pre119SiteTestCase - remove test_wikitree, the url is not reachable
Bug: T263951 Change-Id: I93d5043e34cc80fc70634055f04ff0ea90a3cd7b --- M pywikibot/site_detect.py M tests/site_detect_tests.py 2 files changed, 23 insertions(+), 19 deletions(-)
Approvals: JJMC89: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py index d55342a..4e9b100 100644 --- a/pywikibot/site_detect.py +++ b/pywikibot/site_detect.py @@ -21,6 +21,8 @@ SERVER_DB_ERROR_MSG = \ '<h1>Sorry! This site is experiencing technical difficulties.</h1>'
+MIN_VERSION = MediaWikiVersion('1.19') +
class MWSite:
@@ -41,7 +43,7 @@ check_response(r)
if fromurl != r.data.url: - pywikibot.log('{0} redirected to {1}'.format(fromurl, r.data.url)) + pywikibot.log('{} redirected to {}'.format(fromurl, r.data.url)) fromurl = r.data.url
self.fromurl = fromurl @@ -62,13 +64,16 @@ except (ServerError, RequestException): raise except Exception as e: - pywikibot.log('MW detection failed: {0!r}'.format(e)) + pywikibot.log('MW detection failed: {!r}'.format(e))
if not self.version: self._fetch_old_version()
if not self.api: - raise RuntimeError('Unsupported url: {0}'.format(self.fromurl)) + raise RuntimeError('Unsupported url: {}'.format(self.fromurl)) + + if not self.version or self.version < MIN_VERSION: + raise RuntimeError('Unsupported version: {}'.format(self.version))
if not self.articlepath: if self.private_wiki: @@ -80,14 +85,10 @@ 'private. Use the Main Page URL instead of the API.') else: raise RuntimeError('Unable to determine articlepath: ' - '{0}'.format(self.fromurl)) - - if (not self.version - or self.version < MediaWikiVersion('1.19')): - raise RuntimeError('Unsupported version: {0}'.format(self.version)) + '{}'.format(self.fromurl))
def __repr__(self): - return '{0}("{1}")'.format( + return '{}("{}")'.format( self.__class__.__name__, self.fromurl)
@property @@ -150,8 +151,9 @@ info = site.siteinfo else: info = info['query']['general'] + self.version = MediaWikiVersion.from_generator(info['generator']) - if self.version < MediaWikiVersion('1.17'): + if self.version < MIN_VERSION: return
self.server = urljoin(self.fromurl, info['server']) @@ -228,7 +230,7 @@
if not new_parsed_url.scheme or not new_parsed_url.netloc: new_parsed_url = urlparse( - '{0}://{1}{2}'.format( + '{}://{}{}'.format( new_parsed_url.scheme or self.url.scheme, new_parsed_url.netloc or self.url.netloc, new_parsed_url.path)) @@ -244,11 +246,11 @@ or self._parsed_url.netloc in new_parsed_url.netloc): return
- assert new_parsed_url == self._parsed_url, '{0} != {1}'.format( + assert new_parsed_url == self._parsed_url, '{} != {}'.format( self._parsed_url, new_parsed_url)
self._parsed_url = new_parsed_url - self.server = '{0}://{1}'.format( + self.server = '{}://{}'.format( self._parsed_url.scheme, self._parsed_url.netloc) self.scriptpath = self._parsed_url.path
diff --git a/tests/site_detect_tests.py b/tests/site_detect_tests.py index 03b9946..34b4878 100644 --- a/tests/site_detect_tests.py +++ b/tests/site_detect_tests.py @@ -107,16 +107,18 @@
def test_hrwiki(self): """Test detection of MediaWiki sites for www.hrwiki.org.""" - self.assertNoSite('http://www.hrwiki.org/index.php/$1') # v 1.15 + self.assertNoSite('http://www.hrwiki.org/index.php/$1') # v 1.15.4
def test_wikifon(self): """Test detection of MediaWiki sites for www.wikifon.org.""" - self.assertNoSite('http://www.wikifon.org/$1') # v1.11 + self.assertNoSite('http://www.wikifon.org/$1') # v1.11.0
- def test_wikitree(self): - """Test detection of MediaWiki sites for wikitree.org.""" - # v1.11, with no query module - self.assertNoSite('http://wikitree.org/index.php?title=$1') + def test_ecoreality(self): + """Test detection of MediaWiki sites for www.ecoreality.org. + + api.php is not available. Anyway the wiki is outdated. + """ + self.assertNoSite('http://www.ecoreality.org/wiki/$1') # v1.16.2
class PreAPISiteTestCase(SiteDetectionTestCase):