jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/658043 )
Change subject: [cleanup] use site._update_page with loadimageinfo method
......................................................................
[cleanup] use site._update_page with loadimageinfo method
- additional parameter verify_imageinfo in site._update_page will
check 'imageinfo' content in every pageitem and probably raise
an exception
- call site._update_page with verify_imageinfo=True inside
loadimageinfo and remove all other stuff for backward compatibility.
loadimageinfo does not return a generator anymore.
Change-Id: I9093ece5c55cd6217b40a71a68ebb5ba53a77806
---
M pywikibot/site/__init__.py
1 file changed, 19 insertions(+), 18 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 893218b..8d9a282 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -1177,13 +1177,30 @@
return self.namespaces[num]
return self.namespaces[num][0]
- def _update_page(self, page, query):
+ def _update_page(self, page, query, verify_imageinfo: bool = False):
+ """Update page attributes.
+
+ @param page: page object to be updated
+ @param query: a api.QueryGenerator
+ @param verify_imageinfo: if given, every pageitem is checked
+ whether 'imageinfo' is missing. In that case an exception
+ is raised.
+
+ @raises NoPage: 'missing' key is found in pageitem
+ @raises PageRelatedError: 'imageinfo' is missing in pageitem
+ """
for pageitem in query:
if not self.sametitle(pageitem['title'],
page.title(with_section=False)):
raise InconsistentTitleReceived(page, pageitem['title'])
api.update_page(page, pageitem, query.props)
+ if verify_imageinfo and 'imageinfo' not in pageitem:
+ if 'missing' in pageitem:
+ raise NoPage(page)
+ raise PageRelatedError(
+ page, 'loadimageinfo: Query on %s returned no imageinfo')
+
def loadpageinfo(self, page, preload=False):
"""Load page info from api and store in page attributes.
@@ -1312,23 +1329,7 @@
'url', 'size', 'sha1', 'mime',
'metadata', 'archivename'],
**args)
- # kept for backward compatibility
- # TODO: when backward compatibility can be broken, adopt
- # self._update_page() pattern and remove return
- for pageitem in query:
- if not self.sametitle(pageitem['title'], title):
- raise InconsistentTitleReceived(page, pageitem['title'])
- api.update_page(page, pageitem, query.props)
-
- if 'imageinfo' not in pageitem:
- if 'missing' in pageitem:
- raise NoPage(page)
- raise PageRelatedError(
- page,
- 'loadimageinfo: Query on %s returned no imageinfo')
-
- return (pageitem['imageinfo']
- if history else pageitem['imageinfo'][0])
+ self._update_page(page, query, verify_imageinfo=True)
@deprecated('Check the content model instead', since='20150128',
future_warning=True)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/658043
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I9093ece5c55cd6217b40a71a68ebb5ba53a77806
Gerrit-Change-Number: 658043
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/657988 )
Change subject: [6.0] drop support for mw 1.19-1.22 in data/api.py
......................................................................
[6.0] drop support for mw 1.19-1.22 in data/api.py
- also add typing hints
- raise a TypeError if mime is given as boolean; this type is
deprecated for 3 months
- remove dry_api_tests.MimeTests because Request mime parameter's
value is no longer changed but a TypeError is raised
Bug: T268979
Change-Id: Ieecf9fda098ed30dff350a952149735575d9b1b1
---
M pywikibot/data/api.py
M tests/dry_api_tests.py
2 files changed, 23 insertions(+), 69 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index bde7b4f..b12553e 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -37,11 +37,7 @@
)
from pywikibot.family import SubdomainFamily
from pywikibot.login import LoginStatus
-from pywikibot.tools import (
- issue_deprecation_warning,
- itergroup,
- PYTHON_VERSION,
-)
+from pywikibot.tools import itergroup, PYTHON_VERSION
from pywikibot.tools.formatter import color_format
@@ -973,8 +969,12 @@
# To make sure the default value of 'parameters' can be identified.
_PARAM_DEFAULT = object()
- def __init__(self, site=None, mime=None, throttle=True,
- max_retries=None, retry_wait=None, use_get=None,
+ def __init__(self, site=None,
+ mime: Optional[dict] = None,
+ throttle: bool = True,
+ max_retries: Optional[int] = None,
+ retry_wait: Optional[int] = None,
+ use_get: Optional[bool] = None,
parameters=_PARAM_DEFAULT, **kwargs):
"""
Create a new Request instance with the given parameters.
@@ -1006,14 +1006,13 @@
None). Parameters which should only be transferred via mime
mode are defined via this parameter (even an empty dict means
mime shall be used).
- @type mime: None or dict
- @param max_retries: (optional) Maximum number of times to retry after
+ @param max_retries: Maximum number of times to retry after
errors, defaults to config.max_retries.
- @param retry_wait: (optional) Minimum time in seconds to wait after an
+ @param retry_wait: Minimum time in seconds to wait after an
error, defaults to config.retry_wait seconds (doubles each retry
until config.retry_max seconds is reached).
- @param use_get: (optional) Use HTTP GET request if possible. If False
- it uses a POST request. If None, it'll try to determine via
+ @param use_get: Use HTTP GET request if possible. If False it
+ uses a POST request. If None, it'll try to determine via
action=paraminfo if the action requires a POST.
@param parameters: The parameters used for the request to the API.
@type parameters: dict
@@ -1025,12 +1024,11 @@
.format(self.site), RuntimeWarning, 2)
else:
self.site = site
+
self.mime = mime
- if isinstance(mime, bool): # type(mime) == bool is deprecated.
- issue_deprecation_warning(
- 'Bool values of mime param in api.Request()',
- depth=3, warning_class=FutureWarning, since='20201028')
- self.mime = {} if mime is True else None
+ if isinstance(mime, bool):
+ raise TypeError('mime param in api.Request() must not be boolean')
+
self.throttle = throttle
self.use_get = use_get
if max_retries is None:
@@ -1100,21 +1098,10 @@
'userinfo: {!r}'.format(username, self.site.userinfo))
# MediaWiki 1.23 allows assertion for any action,
- # whereas earlier WMF wikis and others used an extension which
- # could only allow assert for action=edit.
- #
- # When we can't easily check whether the extension is loaded,
- # to avoid cyclic recursion in the Pywikibot codebase, assume
- # that it is present, which will cause an API warning emitted
- # to the logging (console) if it is not present, but will not
- # otherwise be a problem.
- # This situation is only tripped when one of the first actions
- # on the site is a write action and the extension isn't installed.
- if (self.write and self.site.mw_version >= '1.23'
- or self.action == 'edit'
- and self.site.has_extension('AssertEdit')):
+ # make sure user is logged in
+ if self.write:
pywikibot.debug('Adding user assertion', _logger)
- self['assert'] = 'user' # make sure user is logged in
+ self['assert'] = 'user'
@classmethod
def create_simple(cls, req_site, **kwargs):
@@ -2247,14 +2234,10 @@
% self.__class__.__name__)
parameters['indexpageids'] = True # always ask for list of pageids
- if self.site.mw_version < '1.21':
- self.continue_name = 'query-continue'
- self.continue_update = self._query_continue
- else:
- self.continue_name = 'continue'
- self.continue_update = self._continue
- # Explicitly enable the simplified continuation
- parameters['continue'] = True
+ self.continue_name = 'continue'
+ self.continue_update = self._continue
+ # Explicitly enable the simplified continuation
+ parameters['continue'] = True
self.request = self.request_class(**kwargs)
self.site._paraminfo.fetch('query+' + mod for mod in self.modules)
@@ -3087,18 +3070,7 @@
def _update_revisions(page, revisions):
"""Update page revisions."""
- content_model = {'.js': 'javascript', '.css': 'css'}
for rev in revisions:
- if page.site.mw_version < '1.21':
- # T102735: use content model depending on the page suffix
- title = page.title(with_ns=False)
- for suffix, cm in content_model.items():
- if title.endswith(suffix):
- rev['contentmodel'] = cm
- break
- else:
- rev['contentmodel'] = 'wikitext'
-
page._revisions[rev['revid']] = pywikibot.page.Revision(**rev)
diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py
index bd88503..f64ff7b 100644
--- a/tests/dry_api_tests.py
+++ b/tests/dry_api_tests.py
@@ -1,6 +1,6 @@
"""API tests which do not interact with a site."""
#
-# (C) Pywikibot team, 2012-2020
+# (C) Pywikibot team, 2012-2021
#
# Distributed under the terms of the MIT license.
#
@@ -303,24 +303,6 @@
self.assertNotEqual(body.find(file_content), -1)
-class MimeTests(DefaultDrySiteTestCase):
-
- """Test MIME request handling with a real site."""
-
- def test_upload_object(self):
- """Test Request object prepared to upload."""
- # fake write test needs the config username
- site = self.get_site()
- site._username = 'myusername'
- site._userinfo = {'name': 'myusername', 'groups': [], 'id': '1'}
- parameters = {'action': 'upload', 'file': 'MP_sounds.png',
- 'filename': join_images_path('MP_sounds.png')}
- req = Request(site=site, mime=True, parameters=parameters)
- with self.assertRaises(AssertionError):
- assert req.mime is True
- self.assertEqual(req.mime, {})
-
-
class ParamInfoDictTests(DefaultDrySiteTestCase):
"""Test extracting data from the ParamInfo."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/657988
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ieecf9fda098ed30dff350a952149735575d9b1b1
Gerrit-Change-Number: 657988
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: DannyS712 <DannyS712.enwiki(a)gmail.com>
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/657989 )
Change subject: [6.0] drop support for mw 1.19-1.22 in pywikibot.page
......................................................................
[6.0] drop support for mw 1.19-1.22 in pywikibot.page
Bug: T268979
Change-Id: I52c253f1cede0299e772c3e79ea8e329a11bcf2d
---
M pywikibot/page/__init__.py
M pywikibot/page/_revision.py
2 files changed, 1 insertion(+), 5 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index a803780..70b165d 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -44,7 +44,7 @@
)
from pywikibot.family import Family
from pywikibot.page._revision import Revision
-from pywikibot.site import DataSite, Namespace, need_version
+from pywikibot.site import DataSite, Namespace
from pywikibot.tools import (
add_full_name,
compute_file_hash,
@@ -257,7 +257,6 @@
If it cannot be reliably determined via the API,
None is returned.
"""
- # TODO: T102735: Add a sane default of 'wikitext' and others for <1.21
if not hasattr(self, '_contentmodel'):
self.site.loadpageinfo(self)
return self._contentmodel
@@ -1576,7 +1575,6 @@
return None
return list(self._coords)
- @need_version('1.20')
def page_image(self):
"""
Return the most appropriate image on the page.
diff --git a/pywikibot/page/_revision.py b/pywikibot/page/_revision.py
index 46913f5..32436b2 100644
--- a/pywikibot/page/_revision.py
+++ b/pywikibot/page/_revision.py
@@ -122,7 +122,5 @@
this returns the content model of the main slot.
@return: content model
- @raises AssertionError: content model not supplied to the constructor
- which always occurs for MediaWiki versions lower than 1.21.
"""
return self.contentmodel
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/657989
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I52c253f1cede0299e772c3e79ea8e329a11bcf2d
Gerrit-Change-Number: 657989
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/660423 )
Change subject: [IMPR] use userinfo deleter to delete APISite._userinfo
......................................................................
[IMPR] use userinfo deleter to delete APISite._userinfo
Change-Id: Ibc9c629096caba03884828e99fd7d1155af5c3e9
---
M pywikibot/site/__init__.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 98b12a7..cd77fdc 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -399,7 +399,7 @@
the internal login state does not match the state we receive
from the site.
"""
- del self._userinfo
+ del self.userinfo
self._loginstatus = _LoginStatus.NOT_LOGGED_IN
self.login()
@@ -423,7 +423,7 @@
self._loginstatus = _LoginStatus.NOT_LOGGED_IN
# Reset tokens and user properties
- del self._userinfo
+ del self.userinfo
self.tokens = TokenWallet(self)
self._paraminfo = api.ParamInfo(self)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/660423
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ibc9c629096caba03884828e99fd7d1155af5c3e9
Gerrit-Change-Number: 660423
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/659819 )
Change subject: [doc] Update ROADMAP.rst
......................................................................
[doc] Update ROADMAP.rst
Change-Id: I6f02b2eadefe06d8f4e19c7b6d90ef2ea09e8a55
---
M ROADMAP.rst
1 file changed, 5 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index 69a9836..d2b9666 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -4,18 +4,20 @@
Breaking changes
^^^^^^^^^^^^^^^^
+* Return requests.Response with http.request() instead of plain text (T265206)
* config.db_hostname has been renamed to db_hostname_format
Other changes
^^^^^^^^^^^^^
-* (no changes yet)
+* Add enabled_options, disabled_options to GeneratorFactory (T271320)
+* Move interwiki() interwiki_prefix() and local_interwiki() methods from BaseSite to APISite
+* Add requests.Response.headers to log when an API error occurs (T272325)
+* Unused comms.threadedhttp module was removed; threadedhttp.HttpRequest was already replaced with requests.Response (T265206)
Future release notes
~~~~~~~~~~~~~~~~~~~~
-* 5.6.0: comms.http.request() will return a requests.Response object rather than plain text (T265206)
-* 5.6.0: comms.threadedhttp module will be removed (T265206)
* 5.6.0: APISite.loadimageinfo will no longer return any content
* 5.6.0: pagenenerators.handleArg() method will be removed in favour of handle_arg() (T271437)
* 5.5.0: Deprecated data attribute of http.fetch() result will be given up (T265206)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/659819
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I6f02b2eadefe06d8f4e19c7b6d90ef2ea09e8a55
Gerrit-Change-Number: 659819
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged