jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/526514 )
Change subject: [PY3] Make pywikibot more Python 3 compatible
......................................................................
[PY3] Make pywikibot more Python 3 compatible
Due to PEP 237 short int operations returns a long if sys.maxint is
exceeded instead raising an OverFlowError. This behavior was introduced
with Python 2.2 and therefore it is not necessary to derive Python 3
int to long anymore.
Change-Id: I633d0895409c131183f436fdf15900a3dcb4bc0a
---
M pywikibot/__init__.py
M pywikibot/page.py
M scripts/replace.py
M tests/utils.py
4 files changed, 13 insertions(+), 16 deletions(-)
Approvals:
Zhuyifei1999: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 662e746..9c9632d 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -74,7 +74,6 @@
if not PY2:
from queue import Queue
- long = int
else:
from Queue import Queue
@@ -507,7 +506,7 @@
to minutes.
@param year: The year as a signed integer of between 1 and 16 digits.
- @type year: long
+ @type year: int
@param month: Month
@type month: int
@param day: Day
@@ -551,7 +550,7 @@
if month is None:
self.precision = self.PRECISION['year']
month = 1
- self.year = long(year)
+ self.year = year
self.month = month
self.day = day
self.hour = hour
@@ -614,7 +613,7 @@
if not match:
raise ValueError("Invalid format: '%s'" % datetimestr)
t = match.groups()
- return cls(long(t[0]), int(t[1]), int(t[2]),
+ return cls(int(t[0]), int(t[1]), int(t[2]),
int(t[3]), int(t[4]), int(t[5]),
precision, before, after, timezone, calendarmodel, site)
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 07fbdbe..c8d3187 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -53,7 +53,6 @@
from pywikibot.tools.ip import is_IP, ip_regexp
if not PY2:
- long = int
from html import entities as htmlentitydefs
from urllib.parse import quote_from_bytes, unquote_to_bytes
else:
@@ -783,7 +782,7 @@
If the page has only one revision, it shall return -1.
- @rtype: long
+ @rtype: int
@raise AssertionError: Use on MediaWiki prior to v1.16.
"""
@@ -797,7 +796,7 @@
DEPRECATED: Use latest_revision.parent_id instead.
- @rtype: long
+ @rtype: int
@raise AssertionError: Use on MediaWiki prior to v1.16.
"""
@@ -3333,11 +3332,11 @@
@param force: if True, forces reloading the data from API
@type force: bool
- @return: long (MediaWiki's internal timestamp format) or 0
- @rtype: int or long
+ @return: int (MediaWiki's internal timestamp format) or 0
+ @rtype: int
"""
if self.registration():
- return long(self.registration().strftime('%Y%m%d%H%M%S'))
+ return int(self.registration().strftime('%Y%m%d%H%M%S'))
else:
return 0
@@ -3365,7 +3364,7 @@
@param force: if True, forces reloading the data from API
@type force: bool
- @rtype: int or long
+ @rtype: int
"""
return self.getprops(force).get('editcount', 0)
@@ -4149,7 +4148,7 @@
"""
Get the revision identifier for the most recent revision of the entity.
- @rtype: long
+ @rtype: int
"""
if not hasattr(self, '_revid'):
self.get()
@@ -5590,7 +5589,7 @@
@param rollbacktoken: rollback token
@type rollbacktoken: str
@param parentid: id of parent Revision (v1.16+)
- @type parentid: long
+ @type parentid: int
@param contentmodel: content model label (v1.21+)
@type contentmodel: str
@param sha1: sha1 of revision text (v1.19+)
@@ -5616,7 +5615,7 @@
Returns 0 if there is no previous revision
@return: id of parent/previous revision
- @rtype: int or long
+ @rtype: int
@raises AssertionError: parent id not supplied to the constructor
"""
assert self._parent_id is not None, (
diff --git a/scripts/replace.py b/scripts/replace.py
index 339dfb5..237c317 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -169,7 +169,6 @@
if not PY2:
from queue import Queue
- long = int
else:
from Queue import Queue
diff --git a/tests/utils.py b/tests/utils.py
index 89f54e8..fefff75 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -645,7 +645,7 @@
@type command: list of unicode
"""
if PY2:
- command.insert(1, '-W ignore::FutureWarning:pywikibot:125')
+ command.insert(1, '-W ignore::FutureWarning:pywikibot:124')
if cryptography_version and cryptography_version < [1, 3, 4]:
command.insert(1, '-W ignore:Old version of cryptography:Warning')
# Any environment variables added on Windows must be of type
--
To view, visit https://gerrit.wikimedia.org/r/526514
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: I633d0895409c131183f436fdf15900a3dcb4bc0a
Gerrit-Change-Number: 526514
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(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/510728 )
Change subject: [cleanup] Throw a FutureWarning with botirc
......................................................................
[cleanup] Throw a FutureWarning with botirc
botirc was used with script_wui only.
I do not expect that this library part is used elsewhere
but notify end users to replace it soon.
It could be deleted after that, probably in two months or so.
Change-Id: I8bddabcaa9f840b64c1c718d93f5ee5452e30b6e
---
M pywikibot/botirc.py
1 file changed, 2 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
Dvorapa: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/botirc.py b/pywikibot/botirc.py
index 4db2ef1..3286341 100644
--- a/pywikibot/botirc.py
+++ b/pywikibot/botirc.py
@@ -133,4 +133,5 @@
'IRCBot',
replacement_name=('irc.bot.SingleServerIRCBot from irc library '
'or EventStreams'),
- since='20190509')
+ since='20190509',
+ future_warning=True)
--
To view, visit https://gerrit.wikimedia.org/r/510728
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: I8bddabcaa9f840b64c1c718d93f5ee5452e30b6e
Gerrit-Change-Number: 510728
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: 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/511388 )
Change subject: [tests] Announce FutureWarning with weblib methods
......................................................................
[tests] Announce FutureWarning with weblib methods
weblib methods are deprecated for 4 years in favour of memento_client
library due to T85001.
The weblib function for WebCite and the Internet Archive function
are broken. All tests are failing. Therefore announce that this
library is no longer supported and is to be removed soon.
Bug: T85001
Change-Id: I98edadcfb237e84eaa4c5b6401a684592d158611
---
M HISTORY.rst
M pywikibot/weblib.py
2 files changed, 3 insertions(+), 2 deletions(-)
Approvals:
Zhuyifei1999: Looks good to me, approved
jenkins-bot: Verified
diff --git a/HISTORY.rst b/HISTORY.rst
index f6694f9..daaa7f4 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -4,6 +4,7 @@
Current release
---------------
+* weblib module will be removed in next release (T85001)
* Bugfixes and improvements
* Localisation updates
diff --git a/pywikibot/weblib.py b/pywikibot/weblib.py
index 6617bf1..988c946 100644
--- a/pywikibot/weblib.py
+++ b/pywikibot/weblib.py
@@ -23,7 +23,7 @@
from urllib import urlencode
-@deprecated('memento_client package', since='20150811')
+@deprecated('memento_client package', since='20150811', future_warning=True)
def getInternetArchiveURL(url, timestamp=None):
"""Return archived URL by Internet Archive.
@@ -63,7 +63,7 @@
return None
-@deprecated('memento_client package', since='20150811')
+@deprecated('memento_client package', since='20150811', future_warning=True)
def getWebCitationURL(url, timestamp=None):
"""Return archived URL by Web Citation.
--
To view, visit https://gerrit.wikimedia.org/r/511388
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: I98edadcfb237e84eaa4c5b6401a684592d158611
Gerrit-Change-Number: 511388
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
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/526278 )
Change subject: Add allowusertalk to the userblock options in pywikibot
......................................................................
Add allowusertalk to the userblock options in pywikibot
Bug: T229288
Change-Id: I8248d57b7bb126cf94fb48d3c31eebea878a3cf7
---
M pywikibot/site.py
1 file changed, 7 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 9856dd8..d66b5d2 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -5911,7 +5911,8 @@
@must_be(group='sysop')
def blockuser(self, user, expiry, reason, anononly=True, nocreate=True,
- autoblock=True, noemail=False, reblock=False):
+ autoblock=True, noemail=False, reblock=False,
+ allowusertalk=False):
"""
Block a user for certain amount of time and for a certain reason.
@@ -5947,6 +5948,9 @@
@param reblock: If the user is already blocked, overwrite the existing
block.
@type reblock: boolean
+ @param allowusertalk: Whether the user can edit their talk page while
+ blocked.
+ @type allowusertalk: boolean
@return: The data retrieved from the API request.
@rtype: dict
"""
@@ -5957,7 +5961,8 @@
expiry=expiry, reason=reason, token=token,
anononly=anononly, nocreate=nocreate,
autoblock=autoblock, noemail=noemail,
- reblock=reblock)
+ reblock=reblock,
+ allowusertalk=allowusertalk)
data = req.submit()
return data
--
To view, visit https://gerrit.wikimedia.org/r/526278
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: I8248d57b7bb126cf94fb48d3c31eebea878a3cf7
Gerrit-Change-Number: 526278
Gerrit-PatchSet: 1
Gerrit-Owner: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <Ladsgroup(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/524499 )
Change subject: [cleanup] Nothing left to do for a deprecated method
......................................................................
[cleanup] Nothing left to do for a deprecated method
Also update the README-conversion.txt file.
Change-Id: I8846ed1f6a483e74813bbfa97e32d424afe5fecf
---
M README-conversion.txt
M pywikibot/page.py
2 files changed, 2 insertions(+), 3 deletions(-)
Approvals:
Zhuyifei1999: Looks good to me, approved
jenkins-bot: Verified
diff --git a/README-conversion.txt b/README-conversion.txt
index e127cc5..f78bb09 100644
--- a/README-conversion.txt
+++ b/README-conversion.txt
@@ -110,8 +110,8 @@
The old ImagePage class has been renamed into FilePage.
For FilePage objects, the getFileMd5Sum() method is deprecated; it is
-recommended to replace it with getFileSHA1Sum(), because MediaWiki now
-stores the SHA1 hash of images.
+recommended to replace it with latest_file_info.sha1 property because
+MediaWiki now stores the SHA1 hash of images.
=== Category objects ===
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 59964df..893c512 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2605,7 +2605,6 @@
@deprecated('FilePage.latest_file_info.sha1', since='20141106')
def getFileMd5Sum(self):
"""Return image file's MD5 checksum."""
- # TODO: check whether this needs a User-Agent header added
req = http.fetch(self.fileUrl())
h = hashlib.md5()
h.update(req.raw)
--
To view, visit https://gerrit.wikimedia.org/r/524499
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: I8846ed1f6a483e74813bbfa97e32d424afe5fecf
Gerrit-Change-Number: 524499
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(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/510722 )
Change subject: [IMPR] Provide FutureWarning with deprecating methods
......................................................................
[IMPR] Provide FutureWarning with deprecating methods
FutureWarning is a warnings about deprecated features when it is
intended to be seen by end users of the applications.
(See also PEP 565)
On pywikibot each FutureWarning is only shown once when running a script.
Enable deprecating methods and decorators to show FutureWarnings
instead of hidden DeprecationWarnings. This can be used if old
deprecated code will be upcoming removed.
Change-Id: I9a79c7458b2a8f1249088c160f983e428835840f
---
M pywikibot/tools/__init__.py
1 file changed, 31 insertions(+), 18 deletions(-)
Approvals:
Lokal Profil: Looks good to me, but someone else must approve
Zhuyifei1999: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 254defe..c170ad1 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -1594,6 +1594,9 @@
@kwarg since: a timestamp string of the date when the method was
deprecated (form 'YYYYMMDD') or a version string.
@type since: str
+ @kwarg future_warning: if True a FutureWarning will be thrown,
+ otherwise it defaults to DeprecationWarning
+ @type future_warning: bool
"""
def decorator(obj):
"""Outer wrapper.
@@ -1613,7 +1616,9 @@
"""
name = obj.__full_name__
depth = get_wrapper_depth(wrapper) + 1
- issue_deprecation_warning(name, instead, depth, since=since)
+ issue_deprecation_warning(
+ name, instead, depth, since=since,
+ warning_class=FutureWarning if future_warning else None)
return obj(*args, **kwargs)
def add_docstring(wrapper):
@@ -1654,6 +1659,7 @@
return wrapper
since = kwargs.pop('since', None)
+ future_warning = kwargs.pop('future_warning', False)
without_parameters = (len(args) == 1 and len(kwargs) == 0
and callable(args[0]))
if 'instead' in kwargs:
@@ -1827,7 +1833,8 @@
def redirect_func(target, source_module=None, target_module=None,
- old_name=None, class_name=None, since=None):
+ old_name=None, class_name=None, since=None,
+ future_warning=False):
"""
Return a function which can be used to redirect to 'target'.
@@ -1853,11 +1860,16 @@
@param since: a timestamp string of the date when the method was
deprecated (form 'YYYYMMDD') or a version string.
@type since: str
+ @param future_warning: if True a FutureWarning will be thrown,
+ otherwise it defaults to DeprecationWarning
+ @type future_warning: bool
@return: A new function which adds a warning prior to each execution.
@rtype: callable
"""
def call(*a, **kw):
- issue_deprecation_warning(old_name, new_name, since=since)
+ issue_deprecation_warning(
+ old_name, new_name, since=since,
+ warning_class=FutureWarning if future_warning else None)
return target(*a, **kw)
if target_module is None:
target_module = target.__module__
@@ -1906,7 +1918,7 @@
def _add_deprecated_attr(self, name, replacement=None,
replacement_name=None, warning_message=None,
- since=None):
+ since=None, future_warning=False):
"""
Add the name to the local deprecated names dict.
@@ -1928,6 +1940,9 @@
@param since: a timestamp string of the date when the method was
deprecated (form 'YYYYMMDD') or a version string.
@type since: str
+ @param future_warning: if True a FutureWarning will be thrown,
+ otherwise it defaults to DeprecationWarning
+ @type future_warning: bool
"""
if '.' in name:
raise ValueError('Deprecated name "{0}" may not contain '
@@ -1956,7 +1971,8 @@
if hasattr(self, name):
# __getattr__ will only be invoked if self.<name> does not exist.
delattr(self, name)
- self._deprecated[name] = replacement_name, replacement, warning_message
+ self._deprecated[name] = (
+ replacement_name, replacement, warning_message, future_warning)
def __setattr__(self, attr, value):
"""Set the value of the wrapped module."""
@@ -1966,23 +1982,20 @@
def __getattr__(self, attr):
"""Return the attribute with a deprecation warning if required."""
if attr in self._deprecated:
- warning_message = self._deprecated[attr][2]
- warn(warning_message.format(self._module.__name__, attr,
- self._deprecated[attr][0]),
- DeprecationWarning, 2)
- if self._deprecated[attr][1]:
- return self._deprecated[attr][1]
- elif '.' in self._deprecated[attr][0]:
+ name, repl, message, future = self._deprecated[attr]
+ warning_message = message
+ warn(warning_message.format(self._module.__name__, attr, name),
+ FutureWarning if future else DeprecationWarning, 2)
+ if repl:
+ return repl
+ elif '.' in name:
try:
- package_name = self._deprecated[attr][0].split('.', 1)[0]
+ package_name = name.split('.', 1)[0]
module = import_module(package_name)
context = {package_name: module}
- replacement = eval(self._deprecated[attr][0], context)
+ replacement = eval(name, context)
self._deprecated[attr] = (
- self._deprecated[attr][0],
- replacement,
- self._deprecated[attr][2]
- )
+ name, replacement, message, future)
return replacement
except Exception:
pass
--
To view, visit https://gerrit.wikimedia.org/r/510722
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: I9a79c7458b2a8f1249088c160f983e428835840f
Gerrit-Change-Number: 510722
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
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: Lokal Profil <andre.costa(a)wikimedia.se>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)