jenkins-bot submitted this change.

View Change

Approvals: D3r1ck01: Looks good to me, approved jenkins-bot: Verified
[IMPR] Make APISite._simple_request a public method

APISite._simple_request is already used outside the APISite class;
therefore it should become a public method

Change-Id: I1f99c49f0d700629b1260cb3bc016f9751e79cc2
---
M pywikibot/page/__init__.py
M pywikibot/pagegenerators.py
M pywikibot/site/_apisite.py
M pywikibot/site/_datasite.py
M pywikibot/site/_extensions.py
M pywikibot/site/_upload.py
M scripts/change_pagelang.py
7 files changed, 88 insertions(+), 82 deletions(-)

diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 9f4671e..904358f 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -3093,7 +3093,7 @@
}
if ccme:
params['ccme'] = 1
- mailrequest = self.site._simple_request(**params)
+ mailrequest = self.site.simple_request(**params)
maildata = mailrequest.submit()

if 'emailuser' in maildata:
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index a4f998d..f8f1b26 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -2901,7 +2901,7 @@
'action': 'wbgetentities',
'props': 'sitelinks'}

- wbrequest = repo._simple_request(**req)
+ wbrequest = repo.simple_request(**req)
wbdata = wbrequest.submit()
entities = (item for item in wbdata['entities'].values() if
'sitelinks' in item and site.dbName() in item['sitelinks'])
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index 491bbc4..118fed7 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -268,8 +268,17 @@

return self._request_class(kwargs)(site=self, **kwargs)

+ @deprecated('simple_request', since='7.1.0')
def _simple_request(self, **kwargs):
- """Create a request by defining all kwargs as parameters."""
+ """DEPRECATED. Create a request using all kwargs as parameters."""
+ return self.simple_request(**kwargs)
+
+ def simple_request(self, **kwargs):
+ """Create a request by defining all kwargs as parameters.
+
+ .. versionchanged:: 7.1
+ `_simple_request` becomes a public method
+ """
return self._request_class({'parameters': kwargs}).create_simple(
self, **kwargs)

@@ -419,7 +428,7 @@
# csrf token introduced in MW 1.24
with suppress(Error):
req_params['token'] = self.tokens['csrf']
- uirequest = self._simple_request(**req_params)
+ uirequest = self.simple_request(**req_params)
uirequest.submit()
self._loginstatus = _LoginStatus.NOT_LOGGED_IN

@@ -464,7 +473,7 @@

"""
if not hasattr(self, '_userinfo'):
- uirequest = self._simple_request(
+ uirequest = self.simple_request(
action='query',
meta='userinfo',
uiprop='blockinfo|hasmsg|groups|rights|ratelimits'
@@ -527,7 +536,7 @@
meta='globaluserinfo',
guiprop='groups|rights|editcount',
)
- uirequest = self._simple_request(**param)
+ uirequest = self.simple_request(**param)
uidata = uirequest.submit()
assert 'query' in uidata, \
"API userinfo response lacks 'query' key"
@@ -603,7 +612,7 @@
# TODO: Integrate into _userinfo
if (force or not hasattr(self, '_useroptions')
or self.user() != self._useroptions['_name']):
- uirequest = self._simple_request(
+ uirequest = self.simple_request(
action='query',
meta='userinfo',
uiprop='options'
@@ -843,7 +852,7 @@
raise ValueError('text must be a string')
if not text:
return ''
- req = self._simple_request(action='expandtemplates', text=text)
+ req = self.simple_request(action='expandtemplates', text=text)
if title is not None:
req['title'] = title
if includecomments is True:
@@ -1281,11 +1290,12 @@
return page._redirtarget

title = page.title(with_section=False)
- query = self._simple_request(
+ query = self.simple_request(
action='query',
prop='info',
titles=title,
- redirects=True)
+ redirects=True
+ )
result = query.submit()
if 'query' not in result or 'redirects' not in result['query']:
raise RuntimeError(
@@ -1406,16 +1416,16 @@
types_wiki = self._paraminfo.parameter('tokens',
'type')['type']
types.extend(types_wiki)
- req = self._simple_request(action='tokens',
- type=self.validate_tokens(types))
+ req = self.simple_request(action='tokens',
+ type=self.validate_tokens(types))
else:
if all is not False:
types_wiki = self._paraminfo.parameter('query+tokens',
'type')['type']
types.extend(types_wiki)

- req = self._simple_request(action='query', meta='tokens',
- type=self.validate_tokens(types))
+ req = self.simple_request(action='query', meta='tokens',
+ type=self.validate_tokens(types))

req._warning_handler = warn_handler
data = req.submit()
@@ -1436,7 +1446,7 @@

:see: https://www.mediawiki.org/wiki/API:Parse
"""
- req = self._simple_request(action='parse', page=page)
+ req = self.simple_request(action='parse', page=page)
data = req.submit()
assert 'parse' in data, "API parse response lacks 'parse' key"
assert 'text' in data['parse'], "API parse response lacks 'text' key"
@@ -1516,7 +1526,7 @@
'target': target,
'reason': reason}

- req = self._simple_request(**params)
+ req = self.simple_request(**params)

if target:
self.lock_page(page)
@@ -1686,7 +1696,7 @@
elif watch:
pywikibot.warning("editpage: Invalid watch value '{}' ignored."
.format(watch))
- req = self._simple_request(**params)
+ req = self.simple_request(**params)

self.lock_page(page)
try:
@@ -1867,8 +1877,7 @@

# Send the merge API request
token = self.tokens['csrf']
- req = self._simple_request(action='mergehistory',
- token=token)
+ req = self.simple_request(action='mergehistory', token=token)
req['from'] = source
req['to'] = dest
if reason:
@@ -1966,12 +1975,12 @@
'does not exist on {site}.')
token = self.tokens['move']
self.lock_page(page)
- req = self._simple_request(action='move',
- noredirect=noredirect,
- reason=summary,
- movetalk=movetalk,
- token=token,
- to=newtitle)
+ req = self.simple_request(action='move',
+ noredirect=noredirect,
+ reason=summary,
+ movetalk=movetalk,
+ token=token,
+ to=newtitle)
req['from'] = oldtitle # "from" is a python keyword
try:
result = req.submit()
@@ -2076,7 +2085,7 @@
token=self.tokens['rollback'],
user=user)
self.lock_page(page)
- req = self._simple_request(**parameters)
+ req = self.simple_request(**parameters)
try:
req.submit()
except APIError as err:
@@ -2174,7 +2183,7 @@
else:
params['deletetalk'] = deletetalk

- req = self._simple_request(**params)
+ req = self.simple_request(**params)
self.lock_page(page)
try:
req.submit()
@@ -2229,7 +2238,7 @@
'fileids': fileids,
}

- req = self._simple_request(**params)
+ req = self.simple_request(**params)
self.lock_page(page)
try:
req.submit()
@@ -2312,7 +2321,7 @@
protections=protections, reason=reason,
expiry=expiry)

- req = self._simple_request(**parameters)
+ req = self.simple_request(**parameters)
try:
result = req.submit()
except APIError as err:
@@ -2391,12 +2400,11 @@
token = self.tokens['block']
if expiry is False:
expiry = 'never'
- req = self._simple_request(action='block', user=user.username,
- expiry=expiry, reason=reason, token=token,
- anononly=anononly, nocreate=nocreate,
- autoblock=autoblock, noemail=noemail,
- reblock=reblock,
- allowusertalk=allowusertalk)
+ req = self.simple_request(action='block', user=user.username,
+ expiry=expiry, reason=reason, token=token,
+ anononly=anononly, nocreate=nocreate,
+ autoblock=autoblock, noemail=noemail,
+ reblock=reblock, allowusertalk=allowusertalk)

data = req.submit()
return data
@@ -2412,10 +2420,10 @@
:type user: :py:obj:`pywikibot.User`
:param reason: Reason for the unblock.
"""
- req = self._simple_request(action='unblock',
- user=user.username,
- token=self.tokens['block'],
- reason=reason)
+ req = self.simple_request(action='unblock',
+ user=user.username,
+ token=self.tokens['block'],
+ reason=reason)

data = req.submit()
return data
@@ -2440,7 +2448,7 @@
'token': self.tokens['watch'],
'unwatch': unwatch,
}
- req = self._simple_request(**parameters)
+ req = self.simple_request(**parameters)
results = req.submit()
unwatch = 'unwatched' if unwatch else 'watched'
return all(unwatch in r for r in results['watch'])
@@ -2464,7 +2472,7 @@
links tables for any page that uses this page as a template.
:return: True if API returned expected response; False otherwise
"""
- req = self._simple_request(action='purge', titles=list(set(pages)))
+ req = self.simple_request(action='purge', titles=list(set(pages)))
if converttitles:
req['converttitles'] = True
if redirects:
@@ -2531,9 +2539,8 @@
:see: https://www.mediawiki.org/wiki/API:Stashimageinfo
"""
props = props or False
- req = self._simple_request(
- action='query', prop='stashimageinfo', siifilekey=file_key,
- siiprop=props)
+ req = self.simple_request(action='query', prop='stashimageinfo',
+ siifilekey=file_key, siiprop=props)
return req.submit()['query']['stashimageinfo'][0]

@need_right('upload')
@@ -2610,7 +2617,7 @@
'from{}'.format(old[0]): old[1],
'to{}'.format(diff[0]): diff[1]}

- req = self._simple_request(**params)
+ req = self.simple_request(**params)
data = req.submit()
comparison = data['compare']['*']
return comparison
diff --git a/pywikibot/site/_datasite.py b/pywikibot/site/_datasite.py
index ebce64f..7662092 100644
--- a/pywikibot/site/_datasite.py
+++ b/pywikibot/site/_datasite.py
@@ -170,7 +170,7 @@
# an empty string ('&props=') but it should
# result in a missing entry.
props=props if props else False)
- req = self._simple_request(**params)
+ req = self.simple_request(**params)
data = req.submit()
if 'success' not in data:
raise APIError(data['errors'], '')
@@ -206,7 +206,7 @@
req['sites'].append(p.site.dbName())
req['titles'].append(p._link._text)

- req = self._simple_request(action='wbgetentities', **req)
+ req = self.simple_request(action='wbgetentities', **req)
data = req.submit()
for entity in data['entities']:
if 'missing' in data['entities'][entity]:
@@ -291,7 +291,7 @@
UserWarning, 2)

params['data'] = json.dumps(data)
- req = self._simple_request(**params)
+ req = self.simple_request(**params)
return req.submit()

@need_right('edit')
@@ -315,7 +315,7 @@
'token': self.tokens['edit'],
'bot': bot,
}
- req = self._simple_request(**params)
+ req = self.simple_request(**params)
data = req.submit()
# Update the item
if claim.getID() in entity.claims:
@@ -351,7 +351,7 @@
params['value'] = json.dumps(claim._formatValue())

params['baserevid'] = claim.on_item.latest_revision_id
- req = self._simple_request(**params)
+ req = self.simple_request(**params)
return req.submit()

@need_right('edit')
@@ -378,7 +378,7 @@
'bot': bot,
}

- req = self._simple_request(**params)
+ req = self.simple_request(**params)
data = req.submit()
claim.on_item.latest_revision_id = data['pageinfo']['lastrevid']
return data
@@ -433,7 +433,7 @@
params['reference'] = sourceclaim.hash
params['snaks'] = json.dumps(snak)

- req = self._simple_request(**params)
+ req = self.simple_request(**params)
return req.submit()

@need_right('edit')
@@ -472,7 +472,7 @@
params['snaktype'] = qualifier.getSnakType()
params['property'] = qualifier.getID()

- req = self._simple_request(**params)
+ req = self.simple_request(**params)
return req.submit()

@need_right('edit')
@@ -505,7 +505,7 @@
'token': self.tokens['edit'],
}

- req = self._simple_request(**params)
+ req = self.simple_request(**params)
return req.submit()

@need_right('edit')
@@ -534,7 +534,7 @@
'token': self.tokens['edit'],
}

- req = self._simple_request(**params)
+ req = self.simple_request(**params)
return req.submit()

@need_right('edit')
@@ -564,7 +564,7 @@
'token': self.tokens['edit']
}

- req = self._simple_request(**params)
+ req = self.simple_request(**params)
return req.submit()

@need_right('edit')
@@ -590,7 +590,7 @@
}
if bot:
params['bot'] = 1
- req = self._simple_request(**params)
+ req = self.simple_request(**params)
return req.submit()

@need_right('item-merge')
@@ -623,7 +623,7 @@
}
if bot:
params['bot'] = 1
- req = self._simple_request(**params)
+ req = self.simple_request(**params)
return req.submit()

@need_right('item-redirect')
@@ -644,7 +644,7 @@
'token': self.tokens['edit'],
'bot': bot,
}
- req = self._simple_request(**params)
+ req = self.simple_request(**params)
return req.submit()

def search_entities(self, search: str, language: str,
@@ -787,7 +787,7 @@
warn('Unknown parameter {} for action {}, ignored'
.format(arg, action), UserWarning, 2)

- req = self._simple_request(**params)
+ req = self.simple_request(**params)
data = req.submit()
return data

diff --git a/pywikibot/site/_extensions.py b/pywikibot/site/_extensions.py
index 38f53fa..4aca5d5 100644
--- a/pywikibot/site/_extensions.py
+++ b/pywikibot/site/_extensions.py
@@ -1,6 +1,6 @@
"""Objects representing API interface to MediaWiki site extenstions."""
#
-# (C) Pywikibot team, 2008-2021
+# (C) Pywikibot team, 2008-2022
#
# Distributed under the terms of the MIT license.
#
@@ -40,7 +40,7 @@
for key, value in kwargs.items():
params['not' + key] = value

- data = self._simple_request(**params).submit()
+ data = self.simple_request(**params).submit()
notifications = data['query']['notifications']['list']

# Support API before 1.27.0-wmf.22
@@ -61,7 +61,7 @@
# is supported by the site
kwargs = merge_unique_dicts(kwargs, action='echomarkread',
token=self.tokens['edit'])
- req = self._simple_request(**kwargs)
+ req = self.simple_request(**kwargs)
data = req.submit()
try:
return data['query']['echomarkread']['result'] == 'success'
@@ -315,8 +315,8 @@
:return: The API response.
"""
token = self.tokens['csrf']
- req = self._simple_request(action='thank', rev=revid, token=token,
- source=source)
+ req = self.simple_request(action='thank', rev=revid, token=token,
+ source=source)
data = req.submit()
if data['result']['success'] != 1:
raise APIError('Thanking unsuccessful', '')
@@ -339,8 +339,8 @@
"""
post_id = post.uuid
token = self.tokens['csrf']
- req = self._simple_request(action='flowthank',
- postid=post_id, token=token)
+ req = self.simple_request(action='flowthank', postid=post_id,
+ token=token)
data = req.submit()
if data['result']['success'] != 1:
raise APIError('Thanking unsuccessful', '')
@@ -361,9 +361,8 @@
:return: A dict representing the board's metadata.
:rtype: dict
"""
- req = self._simple_request(action='flow', page=page,
- submodule='view-topiclist',
- vtllimit=1)
+ req = self.simple_request(action='flow', page=page,
+ submodule='view-topiclist', vtllimit=1)
data = req.submit()
return data['flow']['view-topiclist']['result']['topiclist']

@@ -428,9 +427,9 @@
:return: A dict representing the topic's data.
:rtype: dict
"""
- req = self._simple_request(action='flow', page=page,
- submodule='view-topic',
- vtformat=content_format)
+ req = self.simple_request(action='flow', page=page,
+ submodule='view-topic',
+ vtformat=content_format)
data = req.submit()
return data['flow']['view-topic']['result']['topic']

@@ -448,9 +447,9 @@
:return: A dict representing the post data for the given UUID.
:rtype: dict
"""
- req = self._simple_request(action='flow', page=page,
- submodule='view-post', vppostId=post_id,
- vpformat=content_format)
+ req = self.simple_request(action='flow', page=page,
+ submodule='view-post', vppostId=post_id,
+ vpformat=content_format)
data = req.submit()
return data['flow']['view-post']['result']['topic']

@@ -711,6 +710,6 @@
:return: The reduced link, without protocol prefix.
:rtype: str
"""
- req = self._simple_request(action='shortenurl', url=url)
+ req = self.simple_request(action='shortenurl', url=url)
data = req.submit()
return data['shortenurl']['shorturl']
diff --git a/pywikibot/site/_upload.py b/pywikibot/site/_upload.py
index a8608ae..c85a397 100644
--- a/pywikibot/site/_upload.py
+++ b/pywikibot/site/_upload.py
@@ -288,7 +288,7 @@
if poll:
# run a poll; not possible in first iteration
assert file_key
- req = self.site._simple_request(
+ req = self.site.simple_request(
action='upload',
token=token,
filekey=file_key,
@@ -440,7 +440,7 @@
raise Error(
"User '{}' is not authorized to upload by URL on site {}."
.format(self.site.user(), self))
- final_request = self.site._simple_request(
+ final_request = self.site.simple_request(
action='upload', filename=file_page_title, url=self.url,
comment=self.comment, text=self.text, token=token)

@@ -509,7 +509,7 @@
assert file_key
pywikibot.log('Waiting for upload to be published.')
result = None
- final_request = self.site._simple_request(
+ final_request = self.site.simple_request(
action='upload',
token=token,
filekey=file_key,
diff --git a/scripts/change_pagelang.py b/scripts/change_pagelang.py
index ea205cb..75a3c04 100755
--- a/scripts/change_pagelang.py
+++ b/scripts/change_pagelang.py
@@ -66,7 +66,7 @@
'title': page.title(),
'lang': self.opt.setlang,
'token': token}
- r = self.site._simple_request(**parameters)
+ r = self.site.simple_request(**parameters)
r.submit()
pywikibot.output(color_format(
'{lightpurple}{0}{default}: Setting '
@@ -84,7 +84,7 @@
'prop': 'info',
'titles': page.title(),
'meta': 'siteinfo'}
- r = self.site._simple_request(**parameters)
+ r = self.site.simple_request(**parameters)
langcheck = r.submit()['query']

currentlang = ''

To view, visit change 770135. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I1f99c49f0d700629b1260cb3bc016f9751e79cc2
Gerrit-Change-Number: 770135
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged