[Pywikibot-commits] Errored: wikimedia/pywikibot-core#3368 (master - afe418c)
Build Update for wikimedia/pywikibot-core - Build: #3368 Status: Errored Duration: 1 hour, 55 minutes, and 35 seconds Commit: afe418c (master) Author: jenkins-bot Message: Merge "Page.namespace() shall return Namespace() for pages in Main ns" View the changeset: https://github.com/wikimedia/pywikibot-core/compare/e89a1efe3738...afe418c1e3b8 View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/119009798 -- You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] Errored: wikimedia/pywikibot-core#3367 (master - e89a1ef)
Build Update for wikimedia/pywikibot-core - Build: #3367 Status: Errored Duration: 1 hour, 51 minutes, and 45 seconds Commit: e89a1ef (master) Author: jenkins-bot Message: Merge "[bugfix] return a list of names for category_namespaces" View the changeset: https://github.com/wikimedia/pywikibot-core/compare/5a612064e706...e89a1efe3738 View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/118989965 -- You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] Errored: wikimedia/pywikibot-core#3366 (master - 5a61206)
Build Update for wikimedia/pywikibot-core - Build: #3366 Status: Errored Duration: 28 minutes and 47 seconds Commit: 5a61206 (master) Author: xqt Message: Revert "Page.namespace() shall return Namespace() for pages in Main ns" This reverts commit f6556636fd91a13394f7f6412593ae29c238b2b3. Bug: T104864 Change-Id: Ib23eda2cbfd871f809254aeb22c2a14fb434cc7e View the changeset: https://github.com/wikimedia/pywikibot-core/compare/849134a061a0...5a612064e706 View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/118983238 -- You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] [Gerrit] Page.namespace() shall return Namespace() for pages in Main ns - change (pywikibot/core)
jenkins-bot has submitted this change and it was merged. Change subject: Page.namespace() shall return Namespace() for pages in Main ns .. Page.namespace() shall return Namespace() for pages in Main ns This reverts commit 5a612064e70653d4a6dd043c5b727d54cb5193c8 and restores f6556636fd91a13394f7f6412593ae29c238b2b3. Bug: T104864 Change-Id: I2d91ca1a9772d909874102e0e9149aa5bfd96b62 --- M pywikibot/page.py 1 file changed, 16 insertions(+), 14 deletions(-) Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/page.py b/pywikibot/page.py index c0c8294..dc83ae4 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -4873,7 +4873,11 @@ self._source = source or pywikibot.Site() self._text = text -self._defaultns = defaultNamespace +# See bug T104864, defaultNamespace might have been deleted. +try: +self._defaultns = self._source.namespaces[defaultNamespace] +except KeyError: +self._defaultns = defaultNamespace # preprocess text (these changes aren't site-dependent) # First remove anchor, which is stored unchanged, if there is one @@ -4988,7 +4992,7 @@ while u":" in t: # Initial colon indicates main namespace rather than default if t.startswith(u":"): -self._namespace = 0 +self._namespace = self._site.namespaces[0] # remove the colon but continue processing # remove any subsequent whitespace t = t.lstrip(u":").lstrip(u" ") @@ -5146,7 +5150,8 @@ def canonical_title(self): """Return full page title, including localized namespace.""" -if self.namespace: +# Avoid that ':' will be added to the title for Main ns. +if self.namespace != Namespace.MAIN: return "%s:%s" % (self.site.namespace(self.namespace), self.title) else: @@ -5162,26 +5167,23 @@ @raise pywikibot.Error: no corresponding namespace is found in onsite """ -ns_id = self.namespace -ns = self.site.namespaces[ns_id] - if onsite is None: -namespace = ns.canonical_name +name = self.namespace.canonical_name else: # look for corresponding ns in onsite by name comparison -for alias in ns: +for alias in self.namespace: namespace = onsite.namespaces.lookup_name(alias) -if namespace: -namespace = namespace.custom_name +if namespace is not None: +name = namespace.custom_name break else: # not found raise pywikibot.Error( u'No corresponding namespace found for namespace %s on %s.' -% (self.site.namespaces[ns_id], onsite)) +% (self.namespace, onsite)) -if namespace: -return u'%s:%s' % (namespace, self.title) +if self.namespace != Namespace.MAIN: +return u'%s:%s' % (name, self.title) else: return self.title @@ -5196,7 +5198,7 @@ if onsite is None: onsite = self._source title = self.title -if self.namespace: +if self.namespace != Namespace.MAIN: title = onsite.namespace(self.namespace) + ":" + title if self.section: title = title + "#" + self.section -- To view, visit https://gerrit.wikimedia.org/r/279948 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2d91ca1a9772d909874102e0e9149aa5bfd96b62 Gerrit-PatchSet: 2 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Xqt Gerrit-Reviewer: John Vandenberg Gerrit-Reviewer: Mpaa Gerrit-Reviewer: Xqt Gerrit-Reviewer: jenkins-bot <> ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] Errored: wikimedia/pywikibot-core#3365 (master - 849134a)
Build Update for wikimedia/pywikibot-core - Build: #3365 Status: Errored Duration: 1 hour, 41 minutes, and 22 seconds Commit: 849134a (master) Author: jenkins-bot Message: Merge "[IMPROV] site_detect: Fail with more specific error" View the changeset: https://github.com/wikimedia/pywikibot-core/compare/9aaeaca497f1...849134a061a0 View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/118971805 -- You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] [Gerrit] [bugfix] return a list of names for category_namespaces - change (pywikibot/core)
jenkins-bot has submitted this change and it was merged. Change subject: [bugfix] return a list of names for category_namespaces .. [bugfix] return a list of names for category_namespaces - category_namespaces did return a Namespace object instead a list of names which was supposed to. Convert the iterator to a list to solve it. - also add some further documentation for site.namespace(): site.namespace(num, True) does not return a list but a Namespace object. Change-Id: I0e2d5d9040c8b2fce25147b95ee55a255297d42e --- M pywikibot/site.py 1 file changed, 9 insertions(+), 2 deletions(-) Approvals: Mpaa: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/site.py b/pywikibot/site.py index 538537c..c421fbf 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1196,7 +1196,7 @@ @deprecated('list(namespaces.CATEGORY)') def category_namespaces(self): """Return names for the Category namespace.""" -return self.namespace(14, all=True) +return list(self.namespace(14, all=True)) # site-specific formatting preferences @@ -2826,8 +2826,15 @@ def namespace(self, num, all=False): """Return string containing local name of namespace 'num'. -If optional argument 'all' is true, return a list of all recognized +If optional argument 'all' is true, return all recognized values for this namespace. + +@param num: Namespace constant. +@type num: int +@param all: If True return a Namespace object. Otherwise +return the namespace name. +@return: local name or Namespace object +@rtype: str or Namespace """ if all: return self.namespaces[num] -- To view, visit https://gerrit.wikimedia.org/r/279926 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I0e2d5d9040c8b2fce25147b95ee55a255297d42e Gerrit-PatchSet: 2 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Xqt Gerrit-Reviewer: John Vandenberg Gerrit-Reviewer: Mpaa Gerrit-Reviewer: Xqt Gerrit-Reviewer: jenkins-bot <> ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] [Gerrit] Revert "Page.namespace() shall return Namespace() for pages ... - change (pywikibot/core)
jenkins-bot has submitted this change and it was merged. Change subject: Revert "Page.namespace() shall return Namespace() for pages in Main ns" .. Revert "Page.namespace() shall return Namespace() for pages in Main ns" This reverts commit f6556636fd91a13394f7f6412593ae29c238b2b3. Bug: T104864 Change-Id: Ib23eda2cbfd871f809254aeb22c2a14fb434cc7e --- M pywikibot/page.py 1 file changed, 14 insertions(+), 12 deletions(-) Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/page.py b/pywikibot/page.py index d2793ac..c0c8294 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -4873,7 +4873,7 @@ self._source = source or pywikibot.Site() self._text = text -self._defaultns = self._source.namespaces[defaultNamespace] +self._defaultns = defaultNamespace # preprocess text (these changes aren't site-dependent) # First remove anchor, which is stored unchanged, if there is one @@ -4988,7 +4988,7 @@ while u":" in t: # Initial colon indicates main namespace rather than default if t.startswith(u":"): -self._namespace = self._site.namespaces[0] +self._namespace = 0 # remove the colon but continue processing # remove any subsequent whitespace t = t.lstrip(u":").lstrip(u" ") @@ -5146,8 +5146,7 @@ def canonical_title(self): """Return full page title, including localized namespace.""" -# Avoid that ':' will be added to the title for Main ns. -if self.namespace != Namespace.MAIN: +if self.namespace: return "%s:%s" % (self.site.namespace(self.namespace), self.title) else: @@ -5163,23 +5162,26 @@ @raise pywikibot.Error: no corresponding namespace is found in onsite """ +ns_id = self.namespace +ns = self.site.namespaces[ns_id] + if onsite is None: -name = self.namespace.canonical_name +namespace = ns.canonical_name else: # look for corresponding ns in onsite by name comparison -for alias in self.namespace: +for alias in ns: namespace = onsite.namespaces.lookup_name(alias) -if namespace is not None: -name = namespace.custom_name +if namespace: +namespace = namespace.custom_name break else: # not found raise pywikibot.Error( u'No corresponding namespace found for namespace %s on %s.' -% (self.namespace, onsite)) +% (self.site.namespaces[ns_id], onsite)) -if self.namespace != Namespace.MAIN: -return u'%s:%s' % (name, self.title) +if namespace: +return u'%s:%s' % (namespace, self.title) else: return self.title @@ -5194,7 +5196,7 @@ if onsite is None: onsite = self._source title = self.title -if self.namespace != Namespace.MAIN: +if self.namespace: title = onsite.namespace(self.namespace) + ":" + title if self.section: title = title + "#" + self.section -- To view, visit https://gerrit.wikimedia.org/r/279947 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib23eda2cbfd871f809254aeb22c2a14fb434cc7e Gerrit-PatchSet: 2 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Xqt Gerrit-Reviewer: John Vandenberg Gerrit-Reviewer: Xqt Gerrit-Reviewer: jenkins-bot <> ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] Errored: wikimedia/pywikibot-core#3364 (master - 9aaeaca)
Build Update for wikimedia/pywikibot-core - Build: #3364 Status: Errored Duration: 1 hour, 32 minutes, and 39 seconds Commit: 9aaeaca (master) Author: jenkins-bot Message: Merge "site.py: prefixindex should also return non-redirects by default" View the changeset: https://github.com/wikimedia/pywikibot-core/compare/37dd35920d31...9aaeaca497f1 View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/118957340 -- You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] [Gerrit] [IMPROV] site_detect: Fail with more specific error - change (pywikibot/core)
jenkins-bot has submitted this change and it was merged. Change subject: [IMPROV] site_detect: Fail with more specific error .. [IMPROV] site_detect: Fail with more specific error When the API from a private wiki isn't exposed it may be able to determine the API path but it may not be able to determine the articlepath. This is guessing the article path from the original URL (if it wasn't the API URL) and also sets the language to the family name as a fallback. Bug: T112575 Change-Id: Ib7bc898ea179c5806a40260dbb69abf2084ed973 --- M generate_family_file.py M pywikibot/site_detect.py 2 files changed, 21 insertions(+), 1 deletion(-) Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified diff --git a/generate_family_file.py b/generate_family_file.py index b4675f8..520434b 100755 --- a/generate_family_file.py +++ b/generate_family_file.py @@ -84,6 +84,8 @@ print(e, "; continuing...") if len([lang for lang in self.langs if lang['url'] == w.iwpath]) == 0: +if w.private_wiki: +w.lang = self.name self.langs.append({u'language': w.lang, u'local': u'', u'prefix': w.lang, diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py index 16aace9..8b7d888 100644 --- a/pywikibot/site_detect.py +++ b/pywikibot/site_detect.py @@ -88,6 +88,18 @@ if not self.api: raise RuntimeError('Unsupported url: {0}'.format(self.fromurl)) +if not self.articlepath: +if self.private_wiki: +if self.api != self.fromurl and self.private_wiki: +self.articlepath = self.fromurl.rsplit('/', 1)[0] + '/$1' +else: +raise RuntimeError( +'Unable to determine articlepath because the wiki is ' +'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.14')): raise RuntimeError('Unsupported version: {0}'.format(self.version)) @@ -145,7 +157,13 @@ def _parse_post_117(self): """Parse 1.17+ siteinfo data.""" response = fetch(self.api + '?action=query&meta=siteinfo&format=json') -info = json.loads(response.content)['query']['general'] +info = json.loads(response.content) +self.private_wiki = ('error' in info and + info['error']['code'] == 'readapidenied') +if self.private_wiki: +return + +info = info['query']['general'] self.version = MediaWikiVersion.from_generator(info['generator']) if self.version < MediaWikiVersion('1.17'): return -- To view, visit https://gerrit.wikimedia.org/r/238307 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib7bc898ea179c5806a40260dbb69abf2084ed973 Gerrit-PatchSet: 2 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: XZise Gerrit-Reviewer: John Vandenberg Gerrit-Reviewer: Ladsgroup Gerrit-Reviewer: Xqt Gerrit-Reviewer: jenkins-bot <> ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] Errored: wikimedia/pywikibot-core#3363 (master - 37dd359)
Build Update for wikimedia/pywikibot-core - Build: #3363 Status: Errored Duration: 1 hour, 38 minutes, and 38 seconds Commit: 37dd359 (master) Author: jenkins-bot Message: Merge "Solve usage of expectedFailure for tools_tests.py" View the changeset: https://github.com/wikimedia/pywikibot-core/compare/f6556636fd91...37dd35920d31 View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/118949089 -- You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] Errored: wikimedia/pywikibot-core#3362 (master - f655663)
Build Update for wikimedia/pywikibot-core - Build: #3362 Status: Errored Duration: 1 hour, 20 minutes, and 25 seconds Commit: f655663 (master) Author: Mpaa Message: Page.namespace() shall return Namespace() for pages in Main ns For pages in Main ns, page.namespace() shall return a Namespace() object instead on an int(). Note: bool(namespace) is now True when namespace is Main. So explicit test vs. Namespace.MAIN is needed to discriminate if namespace is Main or not. Bug: T104864 Change-Id: I15667db612b5e3d7a65319e203065a0b33aa45ad View the changeset: https://github.com/wikimedia/pywikibot-core/compare/cff48cfd0015...f6556636fd91 View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/118948804 -- You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] [Gerrit] site.py: prefixindex should also return non-redirects by def... - change (pywikibot/core)
jenkins-bot has submitted this change and it was merged. Change subject: site.py: prefixindex should also return non-redirects by default .. site.py: prefixindex should also return non-redirects by default The prefixindex function was only returning redirects by default which was unintuitive. To fix that, calculate the appropriate value for filterredir before passing it to allpages() and try to keep the new implementation backward compatible with the original one. See the following commits for the original implementation: - df1292d96469bae6d06c919d5c1260025b3848c2 - 187f51bb7d9b4a5083e436d0c7027ea441da4eed Change-Id: Ib486292f2596612e7709ab44a563a207b8e2b58b --- M pywikibot/site.py 1 file changed, 7 insertions(+), 1 deletion(-) Approvals: John Vandenberg: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/site.py b/pywikibot/site.py index aac59f5..e366f5b 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -3966,8 +3966,14 @@ Use allpages() with the prefix= parameter instead of this method. """ +if not includeredirects: +filterredir = False +elif includeredirects == 'only': +filterredir = True +else: +filterredir = None return self.allpages(prefix=prefix, namespace=namespace, - filterredir=includeredirects) + filterredir=filterredir) @deprecated_args(step=None) def alllinks(self, start="!", prefix="", namespace=0, unique=False, -- To view, visit https://gerrit.wikimedia.org/r/274809 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib486292f2596612e7709ab44a563a207b8e2b58b Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Dalba Gerrit-Reviewer: John Vandenberg Gerrit-Reviewer: XZise Gerrit-Reviewer: Xqt Gerrit-Reviewer: jenkins-bot <> ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] [Gerrit] Solve usage of expectedFailure for tools_tests.py - change (pywikibot/core)
jenkins-bot has submitted this change and it was merged. Change subject: Solve usage of expectedFailure for tools_tests.py .. Solve usage of expectedFailure for tools_tests.py Bug: T130985 Change-Id: I60a6398f78d3f3dedea8073fa355662eef443cb9 --- M pywikibot/tools/__init__.py M tests/tools_tests.py 2 files changed, 11 insertions(+), 4 deletions(-) Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py index c2c5bba..cb3e0be 100644 --- a/pywikibot/tools/__init__.py +++ b/pywikibot/tools/__init__.py @@ -759,6 +759,8 @@ used automatically. Any other method may be provided explicitly using the add parameter. +Beware that key=id is only useful for cases where id() is not unique. + Note: This is not thread safe. @param iterable: the source iterable diff --git a/tests/tools_tests.py b/tests/tools_tests.py index 2d0935e..d48cfb0 100644 --- a/tests/tools_tests.py +++ b/tests/tools_tests.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """Test tools package alone which don't fit into other tests.""" # -# (C) Pywikibot team, 2015 +# (C) Pywikibot team, 2016 # # Distributed under the terms of the MIT license. from __future__ import absolute_import, unicode_literals @@ -409,13 +409,18 @@ deduper = tools.filter_unique(self.decs, container=deduped, key=hash) self._test_dedup_int(deduped, deduper, hash) -@unittest.expectedFailure def test_obj_id(self): """Test filter_unique with objects using id as key, which fails.""" -# Two objects which may be equal do not have the same id. +# Two objects which may be equal do not necessary have the same id. deduped = set() deduper = tools.filter_unique(self.decs, container=deduped, key=id) -self._test_dedup_int(deduped, deduper, id) +self.assertEqual(len(deduped), 0) +for _ in self.decs: +self.assertEqual(id(next(deduper)), deduped.pop()) +self.assertRaises(StopIteration, next, deduper) +# No. of Decimal with distinct ids != no. of Decimal with distinct value. +deduper_ids = list(tools.filter_unique(self.decs, key=id)) +self.assertNotEqual(len(deduper_ids), len(set(deduper_ids))) def test_str(self): """Test filter_unique with str.""" -- To view, visit https://gerrit.wikimedia.org/r/278456 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I60a6398f78d3f3dedea8073fa355662eef443cb9 Gerrit-PatchSet: 4 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Mpaa Gerrit-Reviewer: John Vandenberg Gerrit-Reviewer: Mpaa Gerrit-Reviewer: Xqt Gerrit-Reviewer: jenkins-bot <> ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits
[Pywikibot-commits] [Gerrit] Page.namespace() shall return Namespace() for pages in Main ns - change (pywikibot/core)
jenkins-bot has submitted this change and it was merged. Change subject: Page.namespace() shall return Namespace() for pages in Main ns .. Page.namespace() shall return Namespace() for pages in Main ns For pages in Main ns, page.namespace() shall return a Namespace() object instead on an int(). Note: bool(namespace) is now True when namespace is Main. So explicit test vs. Namespace.MAIN is needed to discriminate if namespace is Main or not. Bug: T104864 Change-Id: I15667db612b5e3d7a65319e203065a0b33aa45ad --- M pywikibot/page.py 1 file changed, 12 insertions(+), 14 deletions(-) Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/page.py b/pywikibot/page.py index c0c8294..d2793ac 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -4873,7 +4873,7 @@ self._source = source or pywikibot.Site() self._text = text -self._defaultns = defaultNamespace +self._defaultns = self._source.namespaces[defaultNamespace] # preprocess text (these changes aren't site-dependent) # First remove anchor, which is stored unchanged, if there is one @@ -4988,7 +4988,7 @@ while u":" in t: # Initial colon indicates main namespace rather than default if t.startswith(u":"): -self._namespace = 0 +self._namespace = self._site.namespaces[0] # remove the colon but continue processing # remove any subsequent whitespace t = t.lstrip(u":").lstrip(u" ") @@ -5146,7 +5146,8 @@ def canonical_title(self): """Return full page title, including localized namespace.""" -if self.namespace: +# Avoid that ':' will be added to the title for Main ns. +if self.namespace != Namespace.MAIN: return "%s:%s" % (self.site.namespace(self.namespace), self.title) else: @@ -5162,26 +5163,23 @@ @raise pywikibot.Error: no corresponding namespace is found in onsite """ -ns_id = self.namespace -ns = self.site.namespaces[ns_id] - if onsite is None: -namespace = ns.canonical_name +name = self.namespace.canonical_name else: # look for corresponding ns in onsite by name comparison -for alias in ns: +for alias in self.namespace: namespace = onsite.namespaces.lookup_name(alias) -if namespace: -namespace = namespace.custom_name +if namespace is not None: +name = namespace.custom_name break else: # not found raise pywikibot.Error( u'No corresponding namespace found for namespace %s on %s.' -% (self.site.namespaces[ns_id], onsite)) +% (self.namespace, onsite)) -if namespace: -return u'%s:%s' % (namespace, self.title) +if self.namespace != Namespace.MAIN: +return u'%s:%s' % (name, self.title) else: return self.title @@ -5196,7 +5194,7 @@ if onsite is None: onsite = self._source title = self.title -if self.namespace: +if self.namespace != Namespace.MAIN: title = onsite.namespace(self.namespace) + ":" + title if self.section: title = title + "#" + self.section -- To view, visit https://gerrit.wikimedia.org/r/279726 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I15667db612b5e3d7a65319e203065a0b33aa45ad Gerrit-PatchSet: 8 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Mpaa Gerrit-Reviewer: John Vandenberg Gerrit-Reviewer: Mpaa Gerrit-Reviewer: Xqt Gerrit-Reviewer: jenkins-bot <> ___ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits