jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/638017 )
Change subject: [bugfix] Enable APISite.exturlusage() with default parameters ......................................................................
[bugfix] Enable APISite.exturlusage() with default parameters
- url parameter of APISite.exturlusage() may be None and not a sequence by default. - use rpartition to retrieve protocol and url
Bug: T266989 Change-Id: I392fbbbdb5a41c6e435f41ba9673685c0b057c68 --- M pywikibot/site/__init__.py 1 file changed, 15 insertions(+), 13 deletions(-)
Approvals: Mpaa: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py index f4408a1..0c28349 100644 --- a/pywikibot/site/__init__.py +++ b/pywikibot/site/__init__.py @@ -3890,7 +3890,7 @@
@see: U{https://www.mediawiki.org/wiki/API:Exturlusage%7D
- @param url: The URL to search for (with ot without the protocol + @param url: The URL to search for (with or without the protocol prefix); this may include a '*' as a wildcard, only at the start of the hostname @param namespaces: list of namespace numbers to fetch contribs from @@ -3899,21 +3899,23 @@ @param protocol: Protocol to search for, likely http or https, http by default. Full list shown on Special:LinkSearch wikipage """ - separator = '://' - if separator in url: - found_protocol = url[:url.index(separator)] - url = url[url.index(separator) + len(separator):] - if protocol and protocol != found_protocol: - raise ValueError('Protocol was specified, but a different one ' - 'was found in searched url') - protocol = found_protocol + if url is not None: + found_protocol, _, url = url.rpartition('://') + + # If url is * we make it None in order to search for every page + # with any URL. + if url == '*': + url = None + + if found_protocol: + if protocol and protocol != found_protocol: + raise ValueError('Protocol was specified, but a different ' + 'one was found in searched url') + protocol = found_protocol + if not protocol: protocol = 'http'
- # If url is * we make it None in order to search for every page - # with any URL. - if url == '*': - url = None return self._generator(api.PageGenerator, type_arg='exturlusage', geuquery=url, geuprotocol=protocol, namespaces=namespaces,