jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/592679 )
Change subject: Improvements for replace.py
......................................................................
Improvements for replace.py
Detached from I600816e5a297427159c5bbedad988c0dfd823868
Change-Id: Iffa58bf64e731a738aba562e24a91adfeb05df0f
Signed-off-by: xqt <info(a)gno.de>
---
M scripts/replace.py
1 file changed, 5 insertions(+), 18 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/replace.py b/scripts/replace.py
index a50c778..4f7d75d 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -895,12 +895,8 @@
# will become True when the user presses a ('yes to all') or uses the
# -always flag.
acceptall = False
- # Will become True if the user inputs the commandline parameter -nocase
- caseInsensitive = False
- # Will become True if the user inputs the commandline parameter -dotall
- dotall = False
- # Will become True if the user inputs the commandline parameter -multiline
- multiline = False
+ # Set the default regular expression flags
+ flags = re.UNICODE
# Do all hits when they overlap
allowoverlap = False
# Do not recurse replacement
@@ -961,11 +957,11 @@
elif arg == '-recursive':
recursive = True
elif arg == '-nocase':
- caseInsensitive = True
+ flags |= re.IGNORECASE
elif arg == '-dotall':
- dotall = True
+ flags |= re.DOTALL
elif arg == '-multiline':
- multiline = True
+ flags |= re.MULTILINE
elif arg.startswith('-addcat:'):
add_cat = arg[8:]
elif arg.startswith('-summary:'):
@@ -1139,15 +1135,6 @@
else:
edit_summary = ''
- # Set the regular expression flags
- flags = re.UNICODE
- if caseInsensitive:
- flags = flags | re.IGNORECASE
- if dotall:
- flags = flags | re.DOTALL
- if multiline:
- flags = flags | re.MULTILINE
-
# Pre-compile all regular expressions here to save time later
for replacement in replacements:
replacement.compile(regex, flags)
--
To view, visit https://gerrit.wikimedia.org/r/592679
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: Iffa58bf64e731a738aba562e24a91adfeb05df0f
Gerrit-Change-Number: 592679
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)disroot.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/589557 )
Change subject: [bugfix] Do not return a random i18n.translation() result
......................................................................
[bugfix] Do not return a random i18n.translation() result
As noted in i18n comment for i18n.translate() this function shouldn't
simply return "any one" result from given translation dict. The
result is also not deterministic and may differ between several
Python versions.
Now just return None if fallback is False by default or raise a
KeyError exception if fallback is not False and no fallback dict
entry is given.
Update test accordingly.
Bug: T220099
Change-Id: Ia80d1bf9e2eede9959ec955874caa3915054a0b7
---
M pywikibot/i18n.py
M tests/i18n_tests.py
2 files changed, 6 insertions(+), 11 deletions(-)
Approvals:
Huji: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 607553b..73fb7f0 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -17,7 +17,7 @@
messages. See L{twtranslate} for more information on the messages.
"""
#
-# (C) Pywikibot team, 2004-2019
+# (C) Pywikibot team, 2004-2020
#
# Distributed under the terms of the MIT license.
#
@@ -614,14 +614,10 @@
trans = xdict[code]
break
else:
- if fallback is not True:
- # this shouldn't simply return "any one" code but when fallback
- # was True before 65518573d2b0, it did just that. When False it
- # did just return None. It's now also returning None in the new
- # iterable mode.
+ if fallback is False:
return None
- code = list(xdict.keys())[0]
- trans = xdict[code]
+ raise KeyError('No fallback key found in lookup dict for "{}"'
+ .format(code))
if trans is None:
return None # return None if we have no translation found
if parameters is None:
diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py
index 2d2d32d..6e21cbe 100644
--- a/tests/i18n_tests.py
+++ b/tests/i18n_tests.py
@@ -70,9 +70,8 @@
"""Test translate with missing English text."""
for code in ('en', 'fy', 'nl'):
with self.subTest(code=code):
- self.assertEqual(i18n.translate(code, self.msg_no_english,
- fallback=True),
- 'test-no-english JA')
+ with self.assertRaises(KeyError):
+ i18n.translate(code, self.msg_no_english, fallback=True)
class UserInterfaceLangTestCase(TestCase):
--
To view, visit https://gerrit.wikimedia.org/r/589557
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: Ia80d1bf9e2eede9959ec955874caa3915054a0b7
Gerrit-Change-Number: 589557
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: Isaacandy <isaac(a)iznd.xyz>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/580067 )
Change subject: [cleanup] remove deprecated tools.ip.ip_regex
......................................................................
[cleanup] remove deprecated tools.ip.ip_regex
- ipaddress is mandatory for Python 2 and part of Python 3.
This dependency is checked by pwb.py and the script fails
if the package is missing. Therefore the regex is no longer
needed will not be used anymore.
- tools.ip.ip_regex was announced to be removed.
Remove it from tools.ip and also remove page.ip_regex
- Remove ip_address/ip_addr backport test. This should
be part of the library itself.
- ip_addr is deprecated already in favour of ip_address.
Its version can be checked with a patch given here:
https://gerrit.wikimedia.org/r/#/c/pywikibot/core/+/577966/
Bug: T174482
Change-Id: Ib7a39cb98a38a552b96679d3a01550e90fc85d7a
---
M pywikibot/page/__init__.py
M pywikibot/tools/__init__.py
M pywikibot/tools/ip.py
3 files changed, 8 insertions(+), 63 deletions(-)
Approvals:
Huji: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 5cdb83c..00b72f9 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -54,7 +54,6 @@
first_upper, redirect_func, remove_last_args, UnicodeType,
StringTypes
)
-from pywikibot.tools.ip import ip_regexp # deprecated
from pywikibot.tools import is_IP
if not PY2:
@@ -93,7 +92,6 @@
'UnicodeToAsciiHtml',
'unicode2html',
'url2unicode',
- 'ip_regexp', # unused & deprecated
)
logger = logging.getLogger('pywiki.wiki.page')
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index f1987be..a6e7c88 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -390,7 +390,7 @@
method = ip_address
if not ip_address: # Python 2 needs ipaddress to be installed
issue_deprecation_warning(
- 'ipaddr module or tools.ip.ip_regexp', 'ipaddress module',
+ 'ipaddr module', 'ipaddress module',
warning_class=FutureWarning, since='20200120')
from pywikibot.tools import ip
with suppress_warnings('pywikibot.tools.ip.is_IP is deprecated'):
diff --git a/pywikibot/tools/ip.py b/pywikibot/tools/ip.py
index b98289d..e935796 100644
--- a/pywikibot/tools/ip.py
+++ b/pywikibot/tools/ip.py
@@ -7,13 +7,9 @@
#
from __future__ import absolute_import, division, unicode_literals
-import re
-
from distutils.version import StrictVersion
-from warnings import warn
-from pywikibot.tools import (DeprecatedRegex, PY2, UnicodeType,
- ModuleDeprecationWrapper)
+from pywikibot.tools import ModuleDeprecationWrapper
_ipaddress_e = _ipaddr_e = _ipaddr_version = None
@@ -23,7 +19,7 @@
_ipaddress_e = e
ip_address = None
-if not ip_address or PY2:
+if not ip_address:
try:
from ipaddr import __version__ as _ipaddr_version
except ImportError as e:
@@ -35,60 +31,11 @@
else:
_ipaddr_e = ImportError('ipaddr %s is broken.' % _ipaddr_version)
-if ip_address and ip_address.__module__ == 'ipaddress':
- if PY2:
- # This backport fails many tests
- # https://pypi.org/project/py2-ipaddress
- # It accepts '1111' as a valid IP address.
- try:
- ip_address('1111')
- ip_address = None
- raise ImportError('ipaddress backport is broken; install ipaddr')
- except ValueError:
- pass
-
- # This backport only fails a few tests if given a unicode object
- # https://pypi.org/project/ipaddress
- # However while it rejects '1111', it will consider b'1111' valid
- try:
- ip_address(b'1111')
- warn('ipaddress backport is defective; patching; install ipaddr',
- ImportWarning)
- orig_ip_address = ip_address
- # force all input to be a unicode object so it validates correctly
-
- def ip_address_patched(IP):
- """Safe ip_address."""
- return orig_ip_address(UnicodeType(IP))
-
- ip_address = ip_address_patched
- except ValueError:
- # This means ipaddress has correctly determined b'1111' is invalid
- pass
-elif not ip_address:
- warn('Importing ipaddr.IPAddress failed: %s\n'
- 'Importing ipaddress.ip_address failed: %s\n'
- 'Please install ipaddr 2.1.10+ or ipaddress.'
- % (_ipaddr_e, _ipaddress_e), ImportWarning)
-
- def ip_address_fake(IP):
- """Fake ip_address method."""
- warn('ipaddress backport not available.', DeprecationWarning)
- if ip_regexp.match(IP) is None:
- raise ValueError('Invalid IP address')
-
- ip_address = ip_address_fake
-
-# deprecated IP detector
-ip_regexp = DeprecatedRegex(
- r'^(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}'
- r'(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|'
- r'(((?=(?=(.*?(::)))\3(?!.+\4)))\4?|[\dA-F]{1,4}:)'
- r'([\dA-F]{1,4}(\4|:\b)|\2){5}'
- r'(([\dA-F]{1,4}(\4|:\b|$)|\2){2}|'
- r'(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\Z',
- re.IGNORECASE,
- 'page.ip_regexp', 'tools.is_IP', since='20150212')
+if not ip_address:
+ raise ImportError('Importing ipaddr.IPAddress failed: {}\n'
+ 'Importing ipaddress.ip_address failed: {}\n'
+ 'Please install ipaddress.'
+ .format(_ipaddr_e, _ipaddress_e))
def is_IP(IP):
--
To view, visit https://gerrit.wikimedia.org/r/580067
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: Ib7a39cb98a38a552b96679d3a01550e90fc85d7a
Gerrit-Change-Number: 580067
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/404435 )
Change subject: [doc] Update breaking change info for getVersionHistory
......................................................................
[doc] Update breaking change info for getVersionHistory
- There is a difference in timestamp too
- Update compat2core.py script accordingly
Bug: T136513
Change-Id: Ibd89306199ee346369d9241a78f61b94fcc3b9f3
---
M pywikibot/page/__init__.py
M scripts/maintenance/compat2core.py
2 files changed, 5 insertions(+), 2 deletions(-)
Approvals:
Dvorapa: Looks good to me, but someone else must approve
Huji: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index a1a92b5..a8b435c 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -1768,6 +1768,8 @@
# (revid, timestamp, user, comment)
# whereas old framework had a tuple of 6 items:
# (revid, timestamp, user, comment, size, tags)
+ #
+ # timestamp is a pywikibot.Timestamp, not a MediaWiki timestamp string
@deprecated('Page.revisions()', since='20150206')
@deprecated_args(forceReload=None, revCount='total', step=None,
getAll=None, reverseOrder='reverse')
diff --git a/scripts/maintenance/compat2core.py b/scripts/maintenance/compat2core.py
index 29b3129..2d4d558 100755
--- a/scripts/maintenance/compat2core.py
+++ b/scripts/maintenance/compat2core.py
@@ -98,8 +98,9 @@
('.replaceImage(',
'Page.replaceImage() is deprecated and does not work at core'),
('.getVersionHistory(',
- 'Page.getVersionHistory() returns a pywikibot.Timestamp object instead of'
- '\na MediaWiki one'),
+ 'Page.getVersionHistory() returns a pywikibot.Timestamp object instead\n'
+ 'of a MediaWiki one. It also returns a tuple of 4 items instead of 6:\n'
+ 'size and tags items are missing. Use Page.revisions() instead.'),
('.contributions(',
'User.contributions() returns a pywikibot.Timestamp object instead of a\n'
'MediaWiki one'),
--
To view, visit https://gerrit.wikimedia.org/r/404435
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: Ibd89306199ee346369d9241a78f61b94fcc3b9f3
Gerrit-Change-Number: 404435
Gerrit-PatchSet: 7
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: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)