jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/362797 )
Change subject: [bugfix] Don't fail when creating User class for autoblock id
......................................................................
[bugfix] Don't fail when creating User class for autoblock id
- Creating a user class with autoblock ID fails with InvalidTitle when a
namespace identifier is given in front of the ID. It works without that
preleading namespaces.
- This patch solves that issue and is needed handling BlockEvents in a
proper way.
- A more general solution with a different Autoblock class proposed by
b4f0bdd8 may come later.
- tests added
Bug: T108515
Change-Id: I6de75bea5c3287cca04700b230fdec881189f32c
---
M pywikibot/page.py
M tests/user_tests.py
2 files changed, 39 insertions(+), 2 deletions(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 5195af2..faf7f53 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3131,9 +3131,11 @@
All parameters are the same as for Page() constructor.
"""
- if len(title) > 1 and title[0] == u'#':
- self._isAutoblock = True
+ self._isAutoblock = True
+ if title.startswith('#'):
title = title[1:]
+ elif ':#' in title:
+ title = title.replace(':#', ':')
else:
self._isAutoblock = False
Page.__init__(self, source, title, ns=2)
diff --git a/tests/user_tests.py b/tests/user_tests.py
index ace810a..d604a97 100644
--- a/tests/user_tests.py
+++ b/tests/user_tests.py
@@ -9,6 +9,7 @@
import pywikibot
+from pywikibot.exceptions import AutoblockUser
from pywikibot.tools import suppress_warnings
from pywikibot import User
@@ -128,6 +129,40 @@
self.assertIn('bot', user.groups())
self.assertFalse(user.is_thankable)
+ def test_autoblocked_user(self):
+ """Test autoblocked user."""
+ user = User(self.site, '#1242976')
+ self.assertEqual('#1242976', user.username)
+ self.assertEqual(user.name(), user.username)
+ self.assertEqual(user.title(withNamespace=False), user.username[1:])
+ self.assertFalse(user.isRegistered())
+ self.assertFalse(user.isAnonymous())
+ self.assertIsNone(user.registration())
+ self.assertFalse(user.isEmailable())
+ self.assertIn('invalid', user.getprops())
+ self.assertTrue(user._isAutoblock)
+ self.assertRaisesRegex(AutoblockUser, 'This is an autoblock ID',
+ user.getUserPage)
+ self.assertRaisesRegex(AutoblockUser, 'This is an autoblock ID',
+ user.getUserTalkPage)
+
+ def test_autoblocked_user_with_namespace(self):
+ """Test autoblocked user."""
+ user = User(self.site, 'User:#1242976')
+ self.assertEqual('#1242976', user.username)
+ self.assertEqual(user.name(), user.username)
+ self.assertEqual(user.title(withNamespace=False), user.username[1:])
+ self.assertFalse(user.isRegistered())
+ self.assertFalse(user.isAnonymous())
+ self.assertIsNone(user.registration())
+ self.assertFalse(user.isEmailable())
+ self.assertIn('invalid', user.getprops())
+ self.assertTrue(user._isAutoblock)
+ self.assertRaisesRegex(AutoblockUser, 'This is an autoblock ID',
+ user.getUserPage)
+ self.assertRaisesRegex(AutoblockUser, 'This is an autoblock ID',
+ user.getUserTalkPage)
+
if __name__ == '__main__': # pragma: no cover
try:
--
To view, visit https://gerrit.wikimedia.org/r/362797
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I6de75bea5c3287cca04700b230fdec881189f32c
Gerrit-Change-Number: 362797
Gerrit-PatchSet: 8
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/416343 )
Change subject: [IMPR] Validate total parameter by api.py
......................................................................
[IMPR] Validate total parameter by api.py
Change-Id: I2620ecda1512ec222051296593c8dfbf054098a4
---
M pywikibot/data/api.py
M pywikibot/site.py
2 files changed, 19 insertions(+), 14 deletions(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 01137a8..1f8ca1f 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -2438,16 +2438,19 @@
more data to be retrieved from the API.
@param value: The value of maximum number of items to be retrieved
- in total to set.
- @type value: int
+ in total to set. Ignores None value.
+ @type value: int or str or None
"""
- self.limit = int(value)
- if self.query_increment and self.limit < self.query_increment:
- self.request[self.limit_name] = self.limit
- pywikibot.debug(u"%s: Set request item limit to %i"
- % (self.__class__.__name__, self.limit), _logger)
- pywikibot.debug(u"%s: Set limit (maximum_items) to %i."
- % (self.__class__.__name__, self.limit), _logger)
+ if value is not None and int(value) > 0:
+ self.limit = int(value)
+ if self.query_increment and self.limit < self.query_increment:
+ self.request[self.limit_name] = self.limit
+ pywikibot.debug('{0}: Set request item limit to {1}'
+ .format(self.__class__.__name__, self.limit),
+ _logger)
+ pywikibot.debug('{0}: Set limit (maximum_items) to {1}.'
+ .format(self.__class__.__name__, self.limit),
+ _logger)
def __iter__(self):
"""
@@ -2640,8 +2643,12 @@
prop=revisions), this is necessary to signal that only current
revision is to be returned.
+ @param value: The value of maximum number of items to be retrieved
+ in total to set. Ignores None value.
+ @type value: int or str or None
"""
- self.limit = int(value)
+ if value is not None:
+ self.limit = int(value)
def _update_limit(self):
"""Set query limit for self.module based on api response."""
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 0185915..ad28b7a 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1936,8 +1936,7 @@
gen = gen_class(**req_args)
if namespaces is not None:
gen.set_namespace(namespaces)
- if total is not None and int(total) > 0:
- gen.set_maximum_items(int(total))
+ gen.set_maximum_items(total)
return gen
def _request_class(self, kwargs):
@@ -8125,6 +8124,5 @@
parameters = dict(search=search, language=language, **kwargs)
gen = api.APIGenerator('wbsearchentities', data_name='search',
site=self, parameters=parameters)
- if total is not None:
- gen.set_maximum_items(total)
+ gen.set_maximum_items(total)
return gen
--
To view, visit https://gerrit.wikimedia.org/r/416343
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I2620ecda1512ec222051296593c8dfbf054098a4
Gerrit-Change-Number: 416343
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/416342 )
Change subject: [IMPR] Rename limit parameter for search_entities to total
......................................................................
[IMPR] Rename limit parameter for search_entities to total
- "total" parameter is used by all other generators in site.py
- change site_tests and pagegenerators accordingly
Change-Id: I1168136cf22a8c3b0530b2dbd75fcf6920a89745
---
M pywikibot/pagegenerators.py
M pywikibot/site.py
M tests/site_tests.py
3 files changed, 8 insertions(+), 7 deletions(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 24333a2..55a5c1b 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -2884,7 +2884,7 @@
language = site.lang
repo = site.data_repository()
- data = repo.search_entities(text, language, limit=total)
+ data = repo.search_entities(text, language, total=total)
for item in data:
yield pywikibot.ItemPage(repo, item['id'])
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 53e7a6b..0185915 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -8094,7 +8094,8 @@
result = self.editEntity({}, data, bot=bot, **kwargs)
return pywikibot.ItemPage(self, result['entity']['id'])
- def search_entities(self, search, language, limit=None, **kwargs):
+ @deprecated_args(limit='total')
+ def search_entities(self, search, language, total=None, **kwargs):
"""
Search for pages or properties that contain the given text.
@@ -8102,7 +8103,7 @@
@type search: str
@param language: Language to search in.
@type language: str
- @param limit: Maximum number of pages to retrieve in total, or None in
+ @param total: Maximum number of pages to retrieve in total, or None in
case of no limit.
@type limit: int or None
@return: 'search' list from API output.
@@ -8124,6 +8125,6 @@
parameters = dict(search=search, language=language, **kwargs)
gen = api.APIGenerator('wbsearchentities', data_name='search',
site=self, parameters=parameters)
- if limit is not None:
- gen.set_maximum_items(limit)
+ if total is not None:
+ gen.set_maximum_items(total)
return gen
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 81700ca..1c5353e 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -3069,11 +3069,11 @@
def test_general(self):
"""Test basic search_entities functionality."""
datasite = self.get_repo()
- pages = datasite.search_entities('abc', 'en', limit=50)
+ pages = datasite.search_entities('abc', 'en', total=50)
self.assertGreater(len(list(pages)), 0)
self.assertLessEqual(len(list(pages)), 50)
pages = datasite.search_entities('alphabet', 'en', type='property',
- limit=50)
+ total=50)
self.assertGreater(len(list(pages)), 0)
self.assertLessEqual(len(list(pages)), 50)
--
To view, visit https://gerrit.wikimedia.org/r/416342
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I1168136cf22a8c3b0530b2dbd75fcf6920a89745
Gerrit-Change-Number: 416342
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>