jenkins-bot has submitted this change and it was merged.
Change subject: Fix docstrings and PEP257
......................................................................
Fix docstrings and PEP257
Change-Id: I3406bee8df5c244703f744b9dd83b953af983517
---
M pywikibot/data/api.py
1 file changed, 42 insertions(+), 20 deletions(-)
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/data/api.py b/pywikibot/data/api.py
index 2bdb78a..efe88b3 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -47,7 +47,9 @@
class APIError(pywikibot.Error):
+
"""The wiki site returned an error message."""
+
def __init__(self, code, info, **kwargs):
"""Save error dict returned by MW API."""
self.code = code
@@ -67,6 +69,7 @@
class Request(MutableMapping):
+
"""A request to a Site's api.php interface.
Attributes of this object (except for the special parameters listed
@@ -121,6 +124,7 @@
@param format: (optional) Defaults to "json"
"""
+
def __init__(self, **kwargs):
try:
self.site = kwargs.pop("site")
@@ -277,7 +281,7 @@
def submit(self):
"""Submit a query and parse the response.
- @return: The data retrieved from api.php (a dict)
+ @return: a dict containing data retrieved from api.php
"""
while True:
@@ -469,7 +473,10 @@
class CachedRequest(Request):
def __init__(self, expiry, *args, **kwargs):
- """ expiry should be either a number of days or a datetime.timedelta object """
+ """Construct a CachedRequest object.
+
+ @param expiry: either a number of days or a datetime.timedelta object
+ """
super(CachedRequest, self).__init__(*args, **kwargs)
if not isinstance(expiry, datetime.timedelta):
expiry = datetime.timedelta(expiry)
@@ -479,7 +486,7 @@
@staticmethod
def _get_cache_dir():
- """The base directory path for cache entries.
+ """Return the base directory path for cache entries.
The directory will be created if it does not already exist.
@@ -508,11 +515,12 @@
return dir
def _uniquedescriptionstr(self):
- """ Unique description for the cache entry.
+ """Return unique description for the cache entry.
If this is modified, please also update
scripts/maintenance/cache.py to support
- the new key and all previous keys. """
+ the new key and all previous keys.
+ """
login_status = self.site._loginstatus
@@ -544,7 +552,7 @@
return dt + self.expiry < datetime.datetime.now()
def _load_cache(self):
- """ Return whether the cache can be used """
+ """Return whether the cache can be used."""
try:
with open(self._cachefile_path(), 'rb') as f:
uniquedescr, self._data, self._cachetime = pickle.load(f)
@@ -561,7 +569,7 @@
return False
def _write_cache(self, data):
- """ writes data to self._cachefile_path() """
+ """Write data to self._cachefile_path()."""
data = [self._uniquedescriptionstr(), data, datetime.datetime.now()]
with open(self._cachefile_path(), 'wb') as f:
pickle.dump(data, f)
@@ -575,6 +583,7 @@
class QueryGenerator(object):
+
"""Base class for iterators that handle responses to API action=query.
By default, the iterator will iterate each item in the query response,
@@ -590,11 +599,12 @@
links. See the API documentation for specific query options.
"""
+
def __init__(self, **kwargs):
- """
- Constructor: kwargs are used to create a Request object;
- see that object's documentation for values. 'action'='query' is
- assumed.
+ """Construct a QueryGenerator object.
+
+ kwargs are used to create a Request object; see that object's
+ documentation for values. 'action'='query' is assumed.
"""
if "action" in kwargs and kwargs["action"] != "query":
@@ -644,7 +654,7 @@
def __modules(self):
"""
Instance cache: hold the query data for paraminfo on
- querymodule=self.module at self.site
+ querymodule=self.module at self.site.
"""
if not hasattr(self.site, "_modules"):
@@ -653,13 +663,13 @@
@__modules.deleter
def __modules(self):
- """Delete the instance cache - maybe we don't need it"""
+ """Delete the instance cache - maybe we don't need it."""
if hasattr(self.site, "_modules"):
del self.site._modules
@property
def _modules(self):
- """Query api on self.site for paraminfo on querymodule=self.module"""
+ """Query api on self.site for paraminfo on querymodule=self.module."""
if not set(self.module.split('|')) <= set(self.__modules.keys()):
paramreq = CachedRequest(expiry=config.API_config_expiry,
site=self.site, action="paraminfo",
@@ -711,7 +721,7 @@
self.limit = int(value)
def update_limit(self):
- """Set query limit for self.module based on api response"""
+ """Set query limit for self.module based on api response."""
for mod in self.module.split('|'):
for param in self._modules[mod].get("parameters", []):
@@ -745,7 +755,7 @@
return
def __iter__(self):
- """Submit request and iterate the response based on self.resultkey
+ """Submit request and iterate the response based on self.resultkey.
Continues response as needed until limit (if any) is reached.
@@ -857,13 +867,15 @@
class PageGenerator(QueryGenerator):
+
"""Iterator for response to a request of type action=query&generator=foo.
This class can be used for any of the query types that are listed in the
- API documentation as being able to be used as a generator. Instances of
+ API documentation as being able to be used as a generator. Instances of
this class iterate Page objects.
"""
+
def __init__(self, generator, g_content=False, **kwargs):
"""
Required and optional parameters are as for C{Request}, except that
@@ -905,6 +917,7 @@
class CategoryPageGenerator(PageGenerator):
+
"""Like PageGenerator, but yields Category objects instead of Pages."""
def result(self, pagedata):
@@ -913,6 +926,7 @@
class ImagePageGenerator(PageGenerator):
+
"""Like PageGenerator, but yields ImagePage objects instead of Pages."""
def result(self, pagedata):
@@ -924,7 +938,8 @@
class PropertyGenerator(QueryGenerator):
- """Iterator for queries of type action=query&property=...
+
+ """Iterator for queries of type action=query&prop=...
See the API documentation for types of page properties that can be
queried.
@@ -936,12 +951,13 @@
be supplied when instantiating this class).
"""
+
def __init__(self, prop, **kwargs):
"""
Required and optional parameters are as for C{Request}, except that
action=query is assumed and prop is required.
- @param prop: the "property=" type from api.php
+ @param prop: the "prop=" type from api.php
@type prop: str
"""
@@ -950,6 +966,7 @@
class ListGenerator(QueryGenerator):
+
"""Iterator for queries of type action=query&list=...
See the API documentation for types of lists that can be queried. Lists
@@ -963,6 +980,7 @@
returned information into a Page object.
"""
+
def __init__(self, listaction, **kwargs):
"""
Required and optional parameters are as for C{Request}, except that
@@ -976,10 +994,12 @@
class LogEntryListGenerator(ListGenerator):
+
"""
Like ListGenerator, but specialized for listaction="logevents" :
yields LogEntry objects instead of dicts.
"""
+
def __init__(self, logtype=None, **kwargs):
ListGenerator.__init__(self, "logevents", **kwargs)
@@ -991,13 +1011,15 @@
class LoginManager(login.LoginManager):
+
"""Supply getCookie() method to use API interface."""
+
def getCookie(self, remember=True, captchaId=None, captchaAnswer=None):
"""Login to the site.
Parameters are all ignored.
- Returns cookie data if successful, None otherwise.
+ @return: cookie data if successful, None otherwise.
"""
if hasattr(self, '_waituntil'):
--
To view, visit https://gerrit.wikimedia.org/r/153224
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3406bee8df5c244703f744b9dd83b953af983517
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Nullzero <nullzero.free(a)gmail.com>
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: update mw version
......................................................................
update mw version
Change-Id: Id14bd21dc89b4c3a84a692d75b9db29624a5fe00
---
M family.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/family.py b/family.py
index 28ba723..1f1616e 100644
--- a/family.py
+++ b/family.py
@@ -4326,7 +4326,7 @@
# Don't use this, use versionnumber() instead. This only exists
# to not break family files.
# Here we return the latest mw release for downloading
- return '1.23.1'
+ return '1.23.2'
def versionnumber(self, code, version=None):
"""Return an int identifying MediaWiki version.
@@ -4962,7 +4962,7 @@
# Don't use this, use versionnumber() instead. This only exists
# to not break family files.
# Here we return the latest mw release of wikimedia projects
- return '1.24wmf14'
+ return '1.24wmf15'
def shared_image_repository(self, code):
return ('commons', 'commons')
--
To view, visit https://gerrit.wikimedia.org/r/153287
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id14bd21dc89b4c3a84a692d75b9db29624a5fe00
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(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: Allow unicode usernames in headers
......................................................................
Allow unicode usernames in headers
Headers are bytes (with either an undefined encoding or latin-1, but
that does not stop us from putting in data that's actually utf-8, as
MW does with MySQL).
Bug: 69354
Change-Id: I062d16604a8b87b5d0c598d4936eca2ecb8303f2
---
M pywikibot/comms/http.py
1 file changed, 2 insertions(+), 1 deletion(-)
Approvals:
Legoktm: Looks good to me, approved
Eranroz: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 69789e1..5edbd62 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -158,10 +158,11 @@
username = site.username()
if not username:
username = ""
+
kwargs["headers"]["user-agent"] = config.USER_AGENT_FORMAT.format(
script=pywikibot.calledModuleName(),
version=pywikibot.version.getversiondict()['rev'],
- username=quote(username),
+ username=quote(username.encode('utf-8')),
lang=site.code,
family=site.family.name)
else:
--
To view, visit https://gerrit.wikimedia.org/r/153221
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I062d16604a8b87b5d0c598d4936eca2ecb8303f2
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Eranroz <eranroz89(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Fix tests to work with user config site fr.wikt
......................................................................
Fix tests to work with user config site fr.wikt
Two wikibase test cases assumed that the config specified wiki has
a data repository.
One page test didnt specify a source for a Link( ), so it defaulted
to the config site, which in the case of wikt behaves differently
to the expectations of the test writer.
Change-Id: Ic8075275e52b9cbbf8a3d24164be7ab665b97ed0
---
M tests/page_tests.py
M tests/wikibase_tests.py
2 files changed, 6 insertions(+), 4 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
Objections:
Ricordisamoa: There's a problem with this change, please improve
diff --git a/tests/page_tests.py b/tests/page_tests.py
index c9f02e2..4948638 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -83,10 +83,12 @@
"""Test that Link() normalizes titles"""
for title in self.titles:
for num in (0, 1):
- l = pywikibot.page.Link(self.namespaces[num][0] + title)
+ l = pywikibot.page.Link(self.namespaces[num][0] + title,
+ self.enwiki)
self.assertEqual(l.title, self.titles[title])
# prefixing name with ":" shouldn't change result
- m = pywikibot.page.Link(":" + self.namespaces[num][0] + title)
+ m = pywikibot.page.Link(":" + self.namespaces[num][0] + title,
+ self.enwiki)
self.assertEqual(m.title, self.titles[title])
def testHashCmp(self):
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index f30ded4..a9142dd 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -396,7 +396,7 @@
def test_set_date(self):
claim = pywikibot.Claim(wikidata, 'P569')
self.assertEquals(claim.type, 'time')
- claim.setTarget(pywikibot.WbTime(year=2001, month=01, day=01))
+ claim.setTarget(pywikibot.WbTime(year=2001, month=01, day=01, site=wikidata))
self.assertEquals(claim.target.year, 2001)
self.assertEquals(claim.target.month, 1)
self.assertEquals(claim.target.day, 1)
@@ -405,7 +405,7 @@
claim = pywikibot.Claim(wikidata, 'P569')
self.assertRaises(ValueError, claim.setTarget, 'foo')
claim = pywikibot.Claim(wikidata, 'P856')
- self.assertRaises(ValueError, claim.setTarget, pywikibot.WbTime(2001))
+ self.assertRaises(ValueError, claim.setTarget, pywikibot.WbTime(2001, site=wikidata))
class TestPageMethods(PywikibotTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/153011
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic8075275e52b9cbbf8a3d24164be7ab665b97ed0
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
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)openmailbox.org>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Remove new flake in basic.py
......................................................................
Remove new flake in basic.py
I63e1699a4b70dde161c0430beaaa5ed0b44093cb introduced a flake.
Change-Id: I6602e0b8b849670428280891a5754521bbb2ae67
---
M scripts/basic.py
1 file changed, 0 insertions(+), 1 deletion(-)
Approvals:
Ricordisamoa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/basic.py b/scripts/basic.py
index 07d2305..99f83f1 100755
--- a/scripts/basic.py
+++ b/scripts/basic.py
@@ -140,7 +140,6 @@
""" Process command line arguments and invoke BasicBot. """
# Process global arguments to determine desired site
local_args = pywikibot.handleArgs()
- site = pywikibot.Site()
# This factory is responsible for processing command line arguments
# that are also used by other scripts and that determine on which pages
--
To view, visit https://gerrit.wikimedia.org/r/153009
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6602e0b8b849670428280891a5754521bbb2ae67
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)openmailbox.org>
Gerrit-Reviewer: jenkins-bot <>