jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/494008 )
Change subject: Removed note from file about using -help
......................................................................
Removed note from file about using -help
When user execute python pwb.py fixing_redirects -help
it shows same message, so I think to this can be removed
Change-Id: I2801cc8a8df5f78abdc87fbad2bc6d4beeafad09
---
M scripts/fixing_redirects.py
1 file changed, 0 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py
index 3c45aba..9112449 100755
--- a/scripts/fixing_redirects.py
+++ b/scripts/fixing_redirects.py
@@ -8,9 +8,6 @@
-featured Run over featured pages (for some wikimedia wikis only)
-Run python pwb.py fixing_redirects -help to see all the command-line
-options -file, -ref, -links, ...
-
"""
#
# (C) Pywikibot team, 2004-2019
--
To view, visit https://gerrit.wikimedia.org/r/494008
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I2801cc8a8df5f78abdc87fbad2bc6d4beeafad09
Gerrit-Change-Number: 494008
Gerrit-PatchSet: 1
Gerrit-Owner: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: D3r1ck01 <alangiderick(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/493661 )
Change subject: [doc] Prepare next release
......................................................................
[doc] Prepare next release
Also fix HISTORY.rst
Change-Id: I01b67a78ee67e56201eb9b5de3017970d2def12d
---
M HISTORY.rst
M docs/conf.py
2 files changed, 7 insertions(+), 2 deletions(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/HISTORY.rst b/HISTORY.rst
index 845f815..7e9aee1 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -4,11 +4,16 @@
Current release
---------------
+* Bugfixes and improvements
+* Localisation updates
+
+3.0.20190301
+------------
* Fix version comparison (T164163)
* Remove pre MediaWiki 1.14 code
* Dropped support for py2.7.2 and py2.7.3 (T191192)
* Fix header regex beginning with a comment (T209712)
-* Implement Claim.__eq__ (T766159
+* Implement Claim.__eq__ (T76615)
* cleanup config2.py
* Add missing Wikibase API write actions
* Bugfixes and improvements
diff --git a/docs/conf.py b/docs/conf.py
index 5251c73..9322320 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -71,7 +71,7 @@
# The short X.Y version.
version = '3.0'
# The full version, including alpha/beta/rc tags.
-release = '3.0.20190204'
+release = '3.0.20190301'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
--
To view, visit https://gerrit.wikimedia.org/r/493661
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I01b67a78ee67e56201eb9b5de3017970d2def12d
Gerrit-Change-Number: 493661
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/492504 )
Change subject: [IMPR] Fix handling of interlanguage links in replace_links
......................................................................
[IMPR] Fix handling of interlanguage links in replace_links
- fix iw (en:Example) links detection (it just didn't work at all)
- fix il (:en:Example) links detection (site should not be derived
from the replacement pair) and behavior (until now replace_links made
[[:en:Foo]] > [[Bar]] for :en:Foo > :en:Bar)
- make site mandatory (as the iw and il links correct detection and
handling needs a site matching the text source/target)
- extracted from
https://gerrit.wikimedia.org/r/#/c/pywikibot/core/+/491673/
Change-Id: Iae273b5440bd697b84b574bf2649996c1cec4f32
---
M pywikibot/textlib.py
M tests/textlib_tests.py
2 files changed, 62 insertions(+), 13 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 7c676c2..506fa93 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -644,8 +644,8 @@
in that case it will apply the second value from the sequence.
@type replace: sequence of pywikibot.Page/pywikibot.Link/str or
callable
- @param site: a Site object to use if replace is not a sequence or the link
- to be replaced is not a Link or Page instance.
+ @param site: a Site object to use. It should match the origin
+ or target site of the text
@type site: pywikibot.APISite
"""
def to_link(source):
@@ -689,14 +689,14 @@
if isinstance(replace_list[1], basestring):
replace_list[1] = pywikibot.Page(site, replace_list[1])
check_classes(replace_list[0])
- if replace_list[0].site != replace_list[1].site:
- raise ValueError('Both pages in the "replace" argument '
- 'must belong to the same site.')
- site = replace_list[0].site
replace = replace_callable
+ if site is None:
+ issue_deprecation_warning(
+ 'site=None',
+ 'a valid site for list or tuple parameter "replace"',
+ 2, since='20190223')
elif site is None:
- raise ValueError('If "replace" is not a tuple or list of pages, '
- 'the "site" argument must be provided.')
+ raise ValueError('The "site" argument must be provided.')
linktrail = site.linktrail()
link_pattern = re.compile(
@@ -710,10 +710,15 @@
m = link_pattern.search(text, pos=curpos)
if not m:
break
- # ignore links to sections of the same page
+ # Ignore links to sections of the same page
if not m.group('title').strip():
curpos = m.end()
continue
+ # Ignore interwiki links
+ if (site.isInterwikiLink(m.group('title').strip())
+ and not m.group('title').strip().startswith(':')):
+ curpos = m.end()
+ continue
groups = m.groupdict()
if groups['label'] and '[[' in groups['label']:
# TODO: Work on the link within the label too
@@ -740,10 +745,6 @@
# unrecognized iw prefix
curpos = end
continue
- # ignore interwiki links
- if link.site != site:
- curpos = end
- continue
# Check whether the link found should be replaced.
# Either None, False or tuple(Link, bool)
@@ -792,6 +793,9 @@
is_link = False
new_title = new_link.canonical_title()
+ # Make correct langlink if needed
+ if not new_link.site == site:
+ new_title = ':' + new_link.site.code + ':' + new_title
if is_link:
# Use link's label
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index 6b754da..860fbfb 100644
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -1060,6 +1060,51 @@
ValueError, r'unicode \(str.*bytes \(str',
textlib.replace_links, self.text, callback, self.wp_site)
+ def test_replace_interwiki_links(self):
+ """Make sure interwiki links can not be replaced."""
+ link = '[[fr:how]]'
+ self.assertEqual(
+ textlib.replace_links(link, ('fr:how', 'de:are'), self.wp_site),
+ link)
+ self.assertEqual(
+ textlib.replace_links(link, (':fr:how', ':de:are'), self.wp_site),
+ link)
+ self.assertEqual(
+ textlib.replace_links(link, ('how', 'de:are'), self.wp_site),
+ link)
+ self.assertEqual(
+ textlib.replace_links(link, ('de:how', 'de:are'), self.wp_site),
+ link)
+
+
+class TestReplaceLinksNonDry(TestCase):
+ """Test the replace_links function in textlib non-dry."""
+
+ family = 'wikipedia'
+ code = 'en'
+
+ cached = True
+
+ def test_replace_interlanguage_links(self):
+ """Test replacing interlanguage links."""
+ link = '[[:fr:how]]'
+ self.assertEqual(
+ textlib.replace_links(link, (':fr:how', ':de:are'),
+ self.site),
+ '[[:de:Are|fr:how]]')
+ self.assertEqual(
+ textlib.replace_links(link, ('fr:how', 'de:are'),
+ self.site),
+ '[[:de:Are|fr:how]]')
+ self.assertEqual(
+ textlib.replace_links(link, ('how', ':de:are'),
+ self.site),
+ link)
+ self.assertEqual(
+ textlib.replace_links(link, (':de:how', ':de:are'),
+ self.site),
+ link)
+
class TestLocalDigits(TestCase):
--
To view, visit https://gerrit.wikimedia.org/r/492504
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Iae273b5440bd697b84b574bf2649996c1cec4f32
Gerrit-Change-Number: 492504
Gerrit-PatchSet: 7
Gerrit-Owner: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: D3r1ck01 <alangiderick(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
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: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/489905 )
Change subject: api.py: check if QueryGenerator support namespaces (updated)
......................................................................
api.py: check if QueryGenerator support namespaces (updated)
Check if 'query+module' supports namespace parameter and set
namespace filtering accordingly in pagagenerators.
support_namespace() has been added for this purpose.
Note:
- issue FutureWarning to alert that set_namespace() will soon raise
a TypeError (and support_namespace() will then be removed).
- this will be a breaking change, so time is given to fix 3rd party-code.
- TODO left, so it will also be clear future evolution.
set_namespace() now returns a bool (it makes tests easier).
This should not be an issue as now nothing is returned anyhow.
Tests added for set_namespace() and support_namespace().
Bug: T198452
Change-Id: Ia2c548cb5a6a8311c4bb92d3d345d6f16df6f7b1
---
M pywikibot/data/api.py
M pywikibot/pagegenerators.py
M tests/api_tests.py
M tests/utils.py
4 files changed, 127 insertions(+), 18 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 1b86cf5..16ded04 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -2811,6 +2811,21 @@
self.api_limit),
_logger)
+ def support_namespace(self):
+ """Check if namespace is a supported parameter on this query.
+
+ Note: this function will be removed when self.set_namespace() will
+ throw TypeError() instead of just giving a warning.
+ See T196619.
+
+ @return: True if yes, False otherwise
+ @rtype: bool
+ """
+ assert(self.limited_module) # some modules do not have a prefix
+ return bool(
+ self.site._paraminfo.parameter('query+' + self.limited_module,
+ 'namespace'))
+
def set_namespace(self, namespaces):
"""Set a namespace filter on this query.
@@ -2820,9 +2835,12 @@
list of namespace identifiers. An empty iterator clears any
namespace restriction.
@raises KeyError: a namespace identifier was not resolved
- @raises TypeError: a namespace identifier has an inappropriate
- type such as NoneType or bool, or more than one namespace
- if the API module does not support multiple namespaces
+
+ # TODO: T196619
+ # @raises TypeError: module does not support a namespace parameter
+ # or a namespace identifier has an inappropriate
+ # type such as NoneType or bool, or more than one namespace
+ # if the API module does not support multiple namespaces
"""
assert(self.limited_module) # some modules do not have a prefix
param = self.site._paraminfo.parameter('query+' + self.limited_module,
@@ -2830,7 +2848,16 @@
if not param:
pywikibot.warning('{0} module does not support a namespace '
'parameter'.format(self.limited_module))
- return
+ warn('set_namespace() will be modified to raise TypeError '
+ 'when namespace parameter is not supported. '
+ 'It will be a Breaking Change, please update your code '
+ 'ASAP, due date July, 31st 2019.', FutureWarning, 2)
+
+ # TODO: T196619
+ # raise TypeError('{0} module does not support a namespace '
+ # 'parameter'.format(self.limited_module))
+
+ return False
if isinstance(namespaces, basestring):
namespaces = namespaces.split('|')
@@ -2852,6 +2879,8 @@
elif self.prefix + 'namespace' in self.request:
del self.request[self.prefix + 'namespace']
+ return None
+
def _query_continue(self):
if all(key not in self.data[self.continue_name]
for key in self.continuekey):
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 9555c39..9a31c29 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -14,7 +14,7 @@
¶ms;
"""
#
-# (C) Pywikibot team, 2008-2018
+# (C) Pywikibot team, 2008-2019
#
# Distributed under the terms of the MIT license.
#
@@ -503,16 +503,19 @@
self.gens.insert(0, gen)
for i in range(len(self.gens)):
- if isinstance(self.gens[i], pywikibot.data.api.QueryGenerator):
- if self.namespaces:
+ if self.namespaces:
+ if (isinstance(self.gens[i], pywikibot.data.api.QueryGenerator)
+ and self.gens[i].support_namespace()):
self.gens[i].set_namespace(self.namespaces)
- if self.limit:
- self.gens[i].set_maximum_items(self.limit)
- else:
- if self.namespaces:
+ # QueryGenerator does not support namespace param.
+ else:
self.gens[i] = NamespaceFilterPageGenerator(
self.gens[i], self.namespaces, self.site)
- if self.limit:
+
+ if self.limit:
+ try:
+ self.gens[i].set_maximum_items(self.limit)
+ except AttributeError:
self.gens[i] = itertools.islice(self.gens[i], self.limit)
if len(self.gens) == 0:
if (self.titlefilter_list
@@ -1013,8 +1016,7 @@
def _handle_unconnectedpages(self, value):
"""Handle `-unconnectedpages` argument."""
- # T196619 don't use QueryGenerator due to namespace filtering
- return (p for p in self.site.unconnected_pages(total=_int_none(value)))
+ return self.site.unconnected_pages(total=_int_none(value))
def _handle_imagesused(self, value):
"""Handle `-imagesused` argument."""
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 76d5fc3..e4d71c1 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""API test module."""
#
-# (C) Pywikibot team, 2007-2018
+# (C) Pywikibot team, 2007-2019
#
# Distributed under the terms of the MIT license.
#
@@ -852,6 +852,84 @@
self.assertEqual(len(links), count)
+class TestDryQueryGeneratorNamespaceParam(TestCase):
+
+ """Test setting of namespace param with ListGenerator.
+
+ Generators with different characteristics are used.
+ site._paraminfo is not always faithful to API, but serves the purpose
+ here.
+ """
+
+ family = 'wikipedia'
+ code = 'en'
+
+ dry = True
+
+ def setUp(self):
+ """Set up test case."""
+ super(TestDryQueryGeneratorNamespaceParam, self).setUp()
+ self.site = self.get_site()
+ self.site._paraminfo['query+querypage'] = {
+ 'prefix': 'qp',
+ 'limit': {'max': 10},
+ }
+ self.site._paraminfo['query+allpages'] = {
+ 'prefix': 'ap',
+ 'limit': {'max': 10},
+ 'namespace': {'multi': True}
+ }
+ self.site._paraminfo['query+alllinks'] = {
+ 'prefix': 'al',
+ 'limit': {'max': 10},
+ 'namespace': {'default': 0}
+ }
+ self.site._paraminfo['query+links'] = {
+ 'prefix': 'pl',
+ }
+ self.site._paraminfo.query_modules_with_limits = {'querypage',
+ 'allpages',
+ 'alllinks'}
+
+ def test_namespace_for_module_with_no_limit(self):
+ """Test PageGenerator set_namespace."""
+ self.gen = api.PageGenerator(site=self.site,
+ generator='links',
+ parameters={'titles': 'test'})
+ self.assertRaises(AssertionError, self.gen.set_namespace, 0)
+ self.assertRaises(AssertionError, self.gen.set_namespace, 1)
+ self.assertRaises(AssertionError, self.gen.set_namespace, None)
+
+ def test_namespace_param_is_not_settable(self):
+ """Test ListGenerator support_namespace."""
+ self.gen = api.ListGenerator(listaction='querypage', site=self.site)
+ self.assertFalse(self.gen.support_namespace())
+ self.assertFalse(self.gen.set_namespace([0, 1]))
+
+ def test_namespace_none(self):
+ """Test ListGenerator set_namespace with None."""
+ self.gen = api.ListGenerator(listaction='alllinks', site=self.site)
+ self.assertRaises(TypeError, self.gen.set_namespace, None)
+
+ def test_namespace_non_multi(self):
+ """Test ListGenerator set_namespace when non multi."""
+ self.gen = api.ListGenerator(listaction='alllinks', site=self.site)
+ self.assertRaises(TypeError, self.gen.set_namespace, [0, 1])
+ self.assertIsNone(self.gen.set_namespace(0))
+
+ def test_namespace_multi(self):
+ """Test ListGenerator set_namespace when multi."""
+ self.gen = api.ListGenerator(listaction='allpages', site=self.site)
+ self.assertTrue(self.gen.support_namespace())
+ self.assertIsNone(self.gen.set_namespace([0, 1]))
+
+ def test_namespace_resolve_failed(self):
+ """Test ListGenerator set_namespace when resolve fails."""
+ self.gen = api.ListGenerator(listaction='allpages', site=self.site)
+ self.assertTrue(self.gen.support_namespace())
+ self.assertRaises(KeyError, self.gen.set_namespace, 10000)
+
+
class TestDryListGenerator(TestCase):
"""Test ListGenerator."""
@@ -879,7 +957,7 @@
def test_namespace_zero(self):
"""Test ListGenerator set_namespace with 0."""
- self.gen.set_namespace(0)
+ self.assertIsNone(self.gen.set_namespace(0))
class TestCachedRequest(DefaultSiteTestCase):
diff --git a/tests/utils.py b/tests/utils.py
index c0ce35b..5819f8d 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Test utilities."""
#
-# (C) Pywikibot team, 2013-2018
+# (C) Pywikibot team, 2013-2019
#
# Distributed under the terms of the MIT license.
#
@@ -317,7 +317,7 @@
def parameter(self, module, param_name):
"""Load dry data."""
- return self[module][param_name]
+ return self[module].get(param_name)
def __getitem__(self, name):
"""Return dry data or a dummy parameter block."""
--
To view, visit https://gerrit.wikimedia.org/r/489905
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia2c548cb5a6a8311c4bb92d3d345d6f16df6f7b1
Gerrit-Change-Number: 489905
Gerrit-PatchSet: 3
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: Framawiki <framawiki(a)tools.wmflabs.org>