jenkins-bot has submitted this change and it was merged.
Change subject: new APISite.list_to_text() method
......................................................................
new APISite.list_to_text() method
to join two or more strings using localized MediaWiki messages
added some testcases accordingly
Change-Id: I84f2346f6f445089fd87b15c9c2c6612496bfa2a
---
M pywikibot/site.py
M tests/site_tests.py
2 files changed, 34 insertions(+), 0 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 9599d4c..6e71404 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -952,6 +952,37 @@
return self._months_names
+ def list_to_text(self, args):
+ """Join a list of strings together into a human-readable
+ list. The MediaWiki message 'and' is used as separator
+ between the last two arguments.
+ If present, other arguments are joined using a comma.
+
+ @param args: text to be expanded
+ @type args: iterable
+ @return: unicode
+
+ """
+ if not args:
+ return u''
+ args = [unicode(e) for e in args]
+ msgs = {
+ 'and': ',',
+ 'comma-separator': ', ',
+ 'word-separator': ' '
+ }
+ try:
+ self.mediawiki_messages(list(msgs.keys()))
+ except KeyError:
+ pass
+ for msg in msgs:
+ try:
+ msgs[msg] = self.mediawiki_message(msg)
+ except KeyError:
+ pass
+ concat = msgs['and'] + msgs['word-separator']
+ return msgs['comma-separator'].join(args[:-2] + [concat.join(args[-2:])])
+
def expand_text(self, text, title=None, includecomments=None):
""" Parses the given text for preprocessing and rendering
e.g expand templates and strip comments if includecomments
diff --git a/tests/site_tests.py b/tests/site_tests.py
index b9e8d34..644b782 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -180,6 +180,9 @@
self.assertType(ver[2], basestring)
self.assertType(mysite.months_names, list)
self.assertEqual(mysite.months_names[4], (u'May', u'May'))
+ self.assertEqual(mysite.list_to_text(('pywikibot',)), 'pywikibot')
+ self.assertEqual(mysite.list_to_text(('Pride', 'Prejudice')), 'Pride and Prejudice')
+ self.assertEqual(mysite.list_to_text(('This', 'that', 'the other')), 'This, that and the other')
def testPageMethods(self):
"""Test ApiSite methods for getting page-specific info"""
--
To view, visit https://gerrit.wikimedia.org/r/135187
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I84f2346f6f445089fd87b15c9c2c6612496bfa2a
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: small changes and typo fixes
......................................................................
small changes and typo fixes
asynchroneous → asynchronous
remove → removed
etc.
Change-Id: I44ad4b7a61d0c3dbf4c2b4f90987e479a5c26fdb
---
M pywikibot/config2.py
M pywikibot/page.py
M pywikibot/site.py
3 files changed, 7 insertions(+), 7 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 4424e89..18b9ca6 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -609,7 +609,7 @@
# Set simulate to True or use -simulate option to block all actions given above.
simulate = False
-# How many pages should be put to a queue in asynchroneous mode.
+# How many pages should be put to a queue in asynchronous mode.
# If maxsize is <= 0, the queue size is infinite.
# Increasing this value will increase memory space but could speed up
# processing. As higher this value this effect will decrease.
diff --git a/pywikibot/page.py b/pywikibot/page.py
index b40ec42..01efdf2 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2750,7 +2750,7 @@
@type claims: list
"""
- # this check allows single claims to be remove by pushing them into a
+ # this check allows single claims to be removed by pushing them into a
# list of length one.
if isinstance(claims, pywikibot.Claim):
claims = [claims]
diff --git a/pywikibot/site.py b/pywikibot/site.py
index a22d8e7..212b029 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -3539,7 +3539,7 @@
return lrgen
-class DataSite (APISite):
+class DataSite(APISite):
def __getattr__(self, attr):
"""Calls to methods get_info, get_sitelinks, get_aliases, get_labels,
@@ -3568,7 +3568,7 @@
@deprecated("pywikibot.PropertyPage")
def _get_propertyitem(self, props, source, **params):
- """generic method to get the data for multiple Wikibase items"""
+ """Generic method to get the data for multiple Wikibase items"""
wbdata = self.get_item(source, props=props, **params)
assert props in wbdata, \
"API wbgetentities response lacks %s key" % props
@@ -3576,7 +3576,7 @@
@deprecated("pywikibot.WikibasePage")
def get_item(self, source, **params):
- """get the data for multiple Wikibase items"""
+ """Get the data for multiple Wikibase items"""
if isinstance(source, int) or \
isinstance(source, basestring) and source.isdigit():
ids = 'q' + str(source)
@@ -3585,11 +3585,11 @@
wbdata = wbrequest.submit()
assert 'success' in wbdata, \
"API wbgetentities response lacks 'success' key"
- assert wbdata['success'] == 1, "API 'success' key ist not 1"
+ assert wbdata['success'] == 1, "API 'success' key is not 1"
assert 'entities' in wbdata, \
"API wbgetentities response lacks 'entities' key"
assert ids in wbdata['entities'], \
- "API wbgetentities response lacks %s key" % ids
+ "API wbgetentities response lacks %s key" % ids
return wbdata['entities'][ids]
else:
# not implemented yet
--
To view, visit https://gerrit.wikimedia.org/r/135999
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I44ad4b7a61d0c3dbf4c2b4f90987e479a5c26fdb
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: allow saving a page with empty text
......................................................................
allow saving a page with empty text
by checking "if text is None" instead of "if not text"
http://lists.wikimedia.org/pipermail/pywikipedia-l/2014-May/008740.html
Change-Id: I26426394ae4844a029c5867446d481d53faae68d
---
M pywikibot/site.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index c178191..a22d8e7 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -2692,7 +2692,7 @@
"""
text = page.text
- if not text:
+ if text is None:
raise Error("editpage: no text to be saved")
try:
lastrev = page.latestRevision()
--
To view, visit https://gerrit.wikimedia.org/r/135747
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I26426394ae4844a029c5867446d481d53faae68d
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)live.it>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: remove obsolete md5 import.
......................................................................
remove obsolete md5 import.
md5 is deprecated since 2.5 and we need py version 2.6.5 or higher
for core. On the other hand md5 isn't use at site.py. I removed it
and opened bug 65760 to fix if needed.
Change-Id: Ifdc0e07f90c842f33139fb45875d1a07ce8240cf
---
M pywikibot/site.py
1 file changed, 0 insertions(+), 8 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Legoktm: Looks good to me, but someone else must approve
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 9599d4c..e62e08c 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -11,10 +11,6 @@
__version__ = '$Id$'
#
-try:
- from hashlib import md5
-except ImportError:
- from md5 import md5
import datetime
import imp
import itertools
@@ -2740,10 +2736,6 @@
pywikibot.warning(
u"editpage: Invalid watch value '%(watch)s' ignored."
% locals())
-# FIXME: API gives 'badmd5' error
-# md5hash = md5()
-# md5hash.update(urllib.quote_plus(text.encode(self.encoding())))
-# params['md5'] = md5hash.digest()
req = api.Request(site=self, **params)
while True:
try:
--
To view, visit https://gerrit.wikimedia.org/r/135307
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifdc0e07f90c842f33139fb45875d1a07ce8240cf
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: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)live.it>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: (bugfix) archivebot.py: use pywikibot.error
......................................................................
(bugfix) archivebot.py: use pywikibot.error
The initial port of archivebot to 'core' left in one call to
parser.error which is used for command line parsing in 'compat'.
Change-Id: Ib1e2841e7cd901a0d298852c29ef5b4025b8852e
---
M scripts/archivebot.py
1 file changed, 3 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
Objections:
Ricordisamoa: There's a problem with this change, please improve
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 407bd91..6fe513c 100644
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -503,7 +503,9 @@
if calc:
if not salt:
- parser.error('Note: you must specify a salt to calculate a key')
+ pywikibot.error('Note: you must specify a salt to calculate a key')
+ return
+
s = new_hash()
s.update(salt + '\n')
s.update(calc + '\n')
--
To view, visit https://gerrit.wikimedia.org/r/135292
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib1e2841e7cd901a0d298852c29ef5b4025b8852e
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)live.it>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: use isinstance(obj, typ) instead of type(obj) == typ
......................................................................
use isinstance(obj, typ) instead of type(obj) == typ
it supports inheritance
Change-Id: I935c78736e9bfa995a62a88cc4c9a0c581ba0f60
---
M pywikibot/bot.py
M pywikibot/data/api.py
M pywikibot/i18n.py
M pywikibot/site.py
M scripts/checkimages.py
M scripts/commonscat.py
M scripts/featured.py
M scripts/interwiki.py
8 files changed, 16 insertions(+), 16 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index e8487e2..2e7e859 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -626,7 +626,7 @@
try:
_arg, _val = arg[1:].split(':')
# explicitly check for int (so bool doesn't match)
- if type(getattr(config, _arg)) is not int:
+ if not isinstance(getattr(config, _arg), int):
raise TypeError
setattr(config, _arg, int(_val))
except (ValueError, TypeError, AttributeError):
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 5ef6cee..a0f5aeb 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -350,7 +350,7 @@
continue
if not result:
result = {}
- if type(result) is not dict:
+ if not isinstance(result, dict):
raise APIError("Unknown",
"Unable to process query response of type %s."
% type(result),
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 3ec974b..a7dd59b 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -242,7 +242,7 @@
"occurences.")
i = 0
for selector, variants in plural_items:
- if type(parameters) == dict:
+ if isinstance(parameters, dict):
num = int(parameters[selector])
elif isinstance(parameters, basestring):
num = int(parameters)
@@ -299,7 +299,7 @@
code = code.code
# Check whether xdict has multiple projects
- if type(xdict) == dict:
+ if isinstance(xdict, dict):
if family in xdict:
xdict = xdict[family]
elif 'wikipedia' in xdict:
@@ -307,7 +307,7 @@
# Get the translated string
trans = None
- if type(xdict) != dict:
+ if not isinstance(xdict, dict):
trans = xdict
elif code in xdict:
trans = xdict[code]
@@ -355,7 +355,7 @@
if hasattr(code, 'code'):
lang = code.code
# check whether we need the language code back
- elif type(code) == list:
+ elif isinstance(code, list):
lang = code.pop()
code_needed = True
else:
@@ -455,7 +455,7 @@
# check for PLURAL variants
trans = _extract_plural(lang, trans, parameters)
# we always have a dict for replacement of translatewiki messages
- if parameters and type(parameters) == dict:
+ if parameters and isinstance(parameters, dict):
try:
return trans % parameters
except KeyError:
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 9599d4c..e6743b2 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -416,16 +416,16 @@
else:
ns2, name2 = 0, title2
for space in self.namespaces(): # iterate over all valid namespaces
- if type(ns1) is not int and valid_namespace(ns1, space):
+ if not isinstance(ns1, int) and valid_namespace(ns1, space):
ns1 = space
- if type(ns2) is not int and valid_namespace(ns2, space):
+ if not isinstance(ns2, int) and valid_namespace(ns2, space):
ns2 = space
- if type(ns1) is not int:
+ if not isinstance(ns1, int):
# no valid namespace prefix found, so the string followed by ":"
# must be part of the title
name1 = ns1 + ":" + name1
ns1 = 0
- if type(ns2) is not int:
+ if not isinstance(ns2, int):
name2 = ns2 + ":" + name2
ns2 = 0
if ns1 != ns2:
@@ -3585,7 +3585,7 @@
@deprecated("pywikibot.WikibasePage")
def get_item(self, source, **params):
"""get the data for multiple Wikibase items"""
- if type(source) == int or \
+ if isinstance(source, int) or \
isinstance(source, basestring) and source.isdigit():
ids = 'q' + str(source)
wbrequest = api.Request(site=self, action="wbgetentities", ids=ids,
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 64a90d5..d781a7e 100644
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -930,7 +930,7 @@
def countEdits(self, pagename, userlist):
"""Function to count the edit of a user or a list of users in a page."""
# self.botolist
- if type(userlist) == str:
+ if isinstance(userlist, basestring):
userlist = [userlist]
page = pywikibot.Page(self.site, pagename)
history = page.getVersionHistory()
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 27e98a2..04569f1 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -336,7 +336,7 @@
templatesInThePage = page.templates()
templatesWithParams = page.templatesWithParams()
for template in ignoreTemplates[page.site.language()]:
- if type(template) != tuple:
+ if not isinstance(template, tuple):
for pageTemplate in templatesInThePage:
if pageTemplate.title(withNamespace=False) == template:
return True
diff --git a/scripts/featured.py b/scripts/featured.py
index f56e63c..a056a40 100644
--- a/scripts/featured.py
+++ b/scripts/featured.py
@@ -92,7 +92,7 @@
except pywikibot.PageNotFound:
return
cat = pywikibot.Category(site, title)
- if type(hide) == dict:
+ if isinstance(hide, dict):
hide = hide.get(site.code)
for article in cat.articles(endsort=hide):
yield article
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 3c2dfe4..df70c62 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -2390,7 +2390,7 @@
tmpl, loc = moved_links[page.site.lang]
except KeyError:
pass
- if type(tmpl) != list:
+ if not isinstance(tmpl, list):
tmpl = [tmpl]
try:
tmpl += ignoreTemplates[page.site.lang]
--
To view, visit https://gerrit.wikimedia.org/r/135400
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I935c78736e9bfa995a62a88cc4c9a0c581ba0f60
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)live.it>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>