jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/331965 )
Change subject: [bugfix] Fix for positional_arg behavior of GeneratorFactory ......................................................................
[bugfix] Fix for positional_arg behavior of GeneratorFactory
When a positional arg is used by GeneratorFactory the argument may contain a colon. The colon splits the option arg from the option value. This patch enables positional arguments with colon inside.
Test added. Also fix old test method.
Bug: T155227 Change-Id: Id61dfd57e514a845d952b1d710b0bf7295fc0a1c --- M pywikibot/pagegenerators.py M tests/pagegenerators_tests.py 2 files changed, 20 insertions(+), 6 deletions(-)
Approvals: Dalba: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index 61dacdb..c290fd6 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -14,7 +14,7 @@ ¶ms; """ # -# (C) Pywikibot team, 2008-2016 +# (C) Pywikibot team, 2008-2017 # # Distributed under the terms of the MIT license. # @@ -632,14 +632,15 @@ """Return None if v is None or '' else return int(v).""" return v if (v is None or v is '') else int(v)
- arg, sep, value = arg.partition(':') - if value == '': - value = None - gen = None if not arg.startswith('-') and self._positional_arg_name: value = arg arg = '-' + self._positional_arg_name + else: + arg, sep, value = arg.partition(':') + + if value == '': + value = None
if arg == '-filelinks': if not value: diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index d8061c4..77eba56 100755 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -1028,7 +1028,20 @@ self.assertIsNotNone(gen1) gf2 = pagegenerators.GeneratorFactory(site=self.site) gf2.handleArg('-page:Main Page') - gen2 = gf1.getCombinedGenerator() + gen2 = gf2.getCombinedGenerator() + self.assertIsNotNone(gen2) + self.assertEqual(list(gen1), list(gen2)) + + def test_positionalargument_with_colon(self): + """Test page generator with positional argument with colon.""" + gf1 = pagegenerators.GeneratorFactory(site=self.site, + positional_arg_name='page') + gf1.handleArg('Project:Main Page') + gen1 = gf1.getCombinedGenerator() + self.assertIsNotNone(gen1) + gf2 = pagegenerators.GeneratorFactory(site=self.site) + gf2.handleArg('-page:Project:Main Page') + gen2 = gf2.getCombinedGenerator() self.assertIsNotNone(gen2) self.assertEqual(list(gen1), list(gen2))