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 <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
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 <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
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 <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
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 <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>