Xqt has uploaded a new change for review. https://gerrit.wikimedia.org/r/275169
Change subject: [IMPR] Use api.APIGenerator through site._generator ...................................................................... [IMPR] Use api.APIGenerator through site._generator - Create APIGenerator through site_generator method which is common for all other api generators. - site._generator adopts 'parameters' if they are in args dict. This enables other arguments passed to the api generator class. - deprecate limit parameter for search_entities method and replace it with total parameter which is a common parameter on other methods. - delete information message from pagegenerators method. Keep a generator a generator and don't bulk load all items and yield items afterwards. Change-Id: I9adf0b53dcd9dbcac5ae76aef9d4ddd86804d1b2 --- M pywikibot/pagegenerators.py M pywikibot/site.py M tests/site_tests.py 3 files changed, 17 insertions(+), 13 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/69/275169/1 diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index 2f80a3b..1242422 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -2583,8 +2583,7 @@ language = site.lang repo = site.data_repository() - data = repo.search_entities(text, language, limit=total) - pywikibot.output(u'retrieved %d items' % len(list(data))) + 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 4304a67..ba1e727 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1915,9 +1915,13 @@ type such as NoneType or bool """ # TODO: Support parameters/simple modes? - req_args = {'site': self, 'parameters': args} + req_args = {'site': self} if 'g_content' in args: req_args['g_content'] = args.pop('g_content') + if 'parameters' in args: + req_args.update(args) + else: + req_args['parameters'] = args if type_arg is not None: gen = gen_class(type_arg, **req_args) else: @@ -7393,7 +7397,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. @@ -7401,9 +7406,9 @@ @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 + @type total: int or None @return: 'search' list from API output. @rtype: api.APIGenerator """ @@ -7421,8 +7426,8 @@ del kwargs['site'] 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) + gen = self._generator(api.APIGenerator, + type_arg='wbsearchentities', + data_name='search', + total=total, parameters=parameters) return gen diff --git a/tests/site_tests.py b/tests/site_tests.py index a54b9ab..09391c2 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -2793,18 +2793,18 @@ 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) def test_continue(self): """Test that continue parameter in search_entities works.""" datasite = self.get_repo() - kwargs = {'limit': 50} + kwargs = {'total': 50} pages = datasite.search_entities('Rembrandt', 'en', **kwargs) kwargs['continue'] = 1 pages_continue = datasite.search_entities('Rembrandt', 'en', **kwargs) -- To view, visit https://gerrit.wikimedia.org/r/275169 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9adf0b53dcd9dbcac5ae76aef9d4ddd86804d1b2 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Xqt <i...@gno.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits