jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/399444 )
Change subject: tools/__init__.py: Make suppress_warnings also work as a decorator
......................................................................
tools/__init__.py: Make suppress_warnings also work as a decorator
`suppress_warnings` already worked as a context manager, but it could not be
configured to suppress specific warnings. The new `message`, `category`, and
`filename` parameters will allow that.
Make the exising usages of `suppress_warnings` more specific. Use it as a
decorator in site_tests.py to suppress an expected DeprecationWarning in
site.search.
Change-Id: Ic606d75f359c4d9c6bc74927da8e6cb0fdf67ab7
---
M pywikibot/tools/__init__.py
M tests/archivebot_tests.py
M tests/site_tests.py
M tests/user_tests.py
4 files changed, 59 insertions(+), 10 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 472bdbe..b9c99e0 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -23,7 +23,8 @@
import types
from distutils.version import Version
-from warnings import catch_warnings, simplefilter, warn
+from functools import wraps
+from warnings import catch_warnings, showwarning, warn
PYTHON_VERSION = sys.version_info[:3]
PY2 = (PYTHON_VERSION[0] == 2)
@@ -209,12 +210,58 @@
class suppress_warnings(catch_warnings): # noqa: N801
- """A context manager that temporarily suppresses warnings."""
+ """A decorator/context manager that temporarily suppresses warnings.
+
+ Those suppressed warnings that do not match the parameters will be raised
+ shown upon exit.
+ """
+
+ def __init__(self, message='', category=Warning, filename=''):
+ """Initialize the object.
+
+ The parameter semantics are similar to those of
+ `warnings.filterwarnings`.
+
+ @param message: A string containing a regular expression that the start
+ of the warning message must match. (case-insensitive)
+ @type message: str
+ @param category: A class (a subclass of Warning) of which the warning
+ category must be a subclass in order to match.
+ @type category: Warning
+ @param filename: A string containing a regular expression that the
+ start of the path to the warning module must match.
+ (case-sensitive)
+ @type filename: str
+ """
+ self.message_match = re.compile(message, re.I).match
+ self.category = category
+ self.filename_match = re.compile(filename).match
+ super(suppress_warnings, self).__init__(record=True)
def __enter__(self):
- """Catch the old filter settings and ignore all warnings."""
- super(suppress_warnings, self).__enter__()
- simplefilter('ignore')
+ """Catch all warnings and store them in `self.log`."""
+ self.log = super(suppress_warnings, self).__enter__()
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ """Stop logging warnings and show those that do not match to params."""
+ super(suppress_warnings, self).__exit__()
+ for warning in self.log:
+ if (
+ not issubclass(warning.category, self.category)
+ or not self.message_match(str(warning.message))
+ or not self.filename_match(warning.filename)
+ ):
+ showwarning(
+ warning.message, warning.category, warning.filename,
+ warning.lineno, warning.file, warning.line)
+
+ def __call__(self, func):
+ """Decorate func to suppress warnings."""
+ @wraps(func)
+ def suppressed_func(*args, **kwargs):
+ with self:
+ return func(*args, **kwargs)
+ return suppressed_func
class UnicodeMixin(object):
diff --git a/tests/archivebot_tests.py b/tests/archivebot_tests.py
index ac253ce..3340b89 100644
--- a/tests/archivebot_tests.py
+++ b/tests/archivebot_tests.py
@@ -98,7 +98,7 @@
def test_checkstr(self):
"""Test for extracting key and duration from shorthand notation of durations."""
self.assertEqual(archivebot.checkstr('400s'), ('s', '400'))
- with suppress_warnings():
+ with suppress_warnings('Time period without qualifier', UserWarning):
self.assertEqual(archivebot.checkstr('3000'), ('s', '3000'))
self.assertEqual(archivebot.checkstr('7d'), ('d', '7'))
self.assertEqual(archivebot.checkstr('3y'), ('y', '3'))
diff --git a/tests/site_tests.py b/tests/site_tests.py
index df886aa..bd77485 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -27,6 +27,7 @@
MediaWikiVersion,
PY2,
StringTypes as basestring,
+ suppress_warnings,
UnicodeType as unicode,
)
@@ -1477,6 +1478,7 @@
raise unittest.SkipTest("gsrsearch returned timeout on site: %r" % e)
raise
+ @suppress_warnings("where='title' is deprecated", DeprecationWarning)
def test_search_where_title(self):
"""Test site.search() method with 'where' parameter set to title."""
try:
diff --git a/tests/user_tests.py b/tests/user_tests.py
index 149cb41..e8678f6 100644
--- a/tests/user_tests.py
+++ b/tests/user_tests.py
@@ -25,7 +25,7 @@
def test_registered_user(self):
"""Test registered user."""
user = User(self.site, 'Xqt')
- with suppress_warnings():
+ with suppress_warnings('pywikibot.page.User.name', DeprecationWarning):
self.assertEqual(user.name(), user.username)
self.assertEqual(user.title(withNamespace=False), user.username)
self.assertTrue(user.isRegistered())
@@ -60,7 +60,7 @@
def test_anonymous_user(self):
"""Test registered user."""
user = User(self.site, '123.45.67.89')
- with suppress_warnings():
+ with suppress_warnings('pywikibot.page.User.name', DeprecationWarning):
self.assertEqual(user.name(), user.username)
self.assertEqual(user.title(withNamespace=False), user.username)
self.assertFalse(user.isRegistered())
@@ -73,7 +73,7 @@
def test_unregistered_user(self):
"""Test unregistered user."""
user = User(self.site, 'This user name is not registered yet')
- with suppress_warnings():
+ with suppress_warnings('pywikibot.page.User.name', DeprecationWarning):
self.assertEqual(user.name(), user.username)
self.assertEqual(user.title(withNamespace=False), user.username)
self.assertFalse(user.isRegistered())
@@ -86,7 +86,7 @@
def test_invalid_user(self):
"""Test invalid user."""
user = User(self.site, 'Invalid char\x9f in Name')
- with suppress_warnings():
+ with suppress_warnings('pywikibot.page.User.name', DeprecationWarning):
self.assertEqual(user.name(), user.username)
self.assertEqual(user.title(withNamespace=False), user.username)
self.assertFalse(user.isRegistered())
--
To view, visit https://gerrit.wikimedia.org/r/399444
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic606d75f359c4d9c6bc74927da8e6cb0fdf67ab7
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/399390 )
Change subject: [L10N] Remove battlestarwiki_family.py out of the framework
......................................................................
[L10N] Remove battlestarwiki_family.py out of the framework
- de.battlestarwiki.org and en.battlestarwiki.org are no longer available
but closed since this year.
- Some of the en pages was ported to en.battlestarwikiclone.org but
the de site is lost and available via web.archive.org.
This clone can be reached via generate_family_file when needed
Change-Id: Iffa70aa32c7902294f5633d25806ce256cca1649
---
M HISTORY.rst
M docs/api_ref/pywikibot.families.rst
D pywikibot/families/battlestarwiki_family.py
M pywikibot/family.py
4 files changed, 1 insertion(+), 34 deletions(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
Zoranzoki21: Looks good to me, but someone else must approve
diff --git a/HISTORY.rst b/HISTORY.rst
index 1b3b1c4..af33cac 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -4,6 +4,7 @@
Current release
---------------
+* Drop battlestarwiki family file
* Bugfixes and improvements
* Localisation updates
diff --git a/docs/api_ref/pywikibot.families.rst b/docs/api_ref/pywikibot.families.rst
index 51cc605..68c2dca 100644
--- a/docs/api_ref/pywikibot.families.rst
+++ b/docs/api_ref/pywikibot.families.rst
@@ -9,14 +9,6 @@
Submodules
----------
-pywikibot.families.battlestarwiki_family module
------------------------------------------------
-
-.. automodule:: pywikibot.families.battlestarwiki_family
- :members:
- :undoc-members:
- :show-inheritance:
-
pywikibot.families.commons_family module
----------------------------------------
diff --git a/pywikibot/families/battlestarwiki_family.py b/pywikibot/families/battlestarwiki_family.py
deleted file mode 100644
index 1a12f79..0000000
--- a/pywikibot/families/battlestarwiki_family.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# -*- coding: utf-8 -*-
-"""Family module for Battlestar Wiki."""
-#
-# (C) Pywikibot team, 2007-2015
-#
-# Distributed under the terms of the MIT license.
-#
-from __future__ import absolute_import, unicode_literals
-
-__version__ = '$Id$'
-
-from pywikibot import family
-
-
-# The Battlestar Wiki family, a set of Battlestar wikis.
-class Family(family.SubdomainFamily):
-
- """Family class for Battlestar Wiki."""
-
- name = 'battlestarwiki'
- domain = 'battlestarwiki.org'
-
- codes = ['en', 'de']
-
- interwiki_removals = ['fr', 'zh', 'es', 'ms', 'tr', 'simple']
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 59be0f8..363c6b8 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -326,7 +326,6 @@
'aspienetwiki': 'aspienetwiki',
'atmwiki': 'atmwiki',
'b': 'wikibooks',
- 'battlestarwiki': 'battlestarwiki',
'bemi': 'bemi',
'benefitswiki': 'benefitswiki',
'betawiki': 'betawiki',
--
To view, visit https://gerrit.wikimedia.org/r/399390
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iffa70aa32c7902294f5633d25806ce256cca1649
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Alex S.H. Lin <alexsh(a)mail2000.com.tw>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/399396 )
Change subject: [doc] use reStructuredText instead of markdown
......................................................................
[doc] use reStructuredText instead of markdown
- a rst file could be included to other doc files e.g. in readme.rst
for the pypi package
Change-Id: I4859ebecd83e1d6eecb0c38bd5317c02085f4e55
---
D CODE_OF_CONDUCT.md
A CODE_OF_CONDUCT.rst
2 files changed, 5 insertions(+), 2 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
Zoranzoki21: Looks good to me, but someone else must approve
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
deleted file mode 100644
index 7815dda..0000000
--- a/CODE_OF_CONDUCT.md
+++ /dev/null
@@ -1,2 +0,0 @@
-The development of this software is covered by a [Code of Conduct](https://www.mediawiki.org/wiki/Code_of_Conduct).
-
diff --git a/CODE_OF_CONDUCT.rst b/CODE_OF_CONDUCT.rst
new file mode 100644
index 0000000..ea6ab54
--- /dev/null
+++ b/CODE_OF_CONDUCT.rst
@@ -0,0 +1,5 @@
+Code of Conduct
+---------------
+
+The development of this software is covered by a `Code of Conduct <https://www.mediawiki.org/wiki/Code_of_Conduct>`_.
+
--
To view, visit https://gerrit.wikimedia.org/r/399396
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4859ebecd83e1d6eecb0c38bd5317c02085f4e55
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <Ladsgroup(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/397803 )
Change subject: [bugfix] Make archivebot ignore headers in nowiki, pre, etc.
......................................................................
[bugfix] Make archivebot ignore headers in nowiki, pre, etc.
archivebot.py has been incorrectly searching for thread headers in tags
like nowiki, pre, source and in comments
Bug: T182496
Change-Id: I2e7183f431ce3bb4cdd1729e592b7509cbd37b94
---
M scripts/archivebot.py
1 file changed, 25 insertions(+), 5 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 52f1b31..930a8d9 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -109,7 +109,7 @@
from pywikibot.date import apply_month_delta
from pywikibot import i18n
-from pywikibot.textlib import TimeStripper
+from pywikibot.textlib import TimeStripper, _get_regexes
from pywikibot.textlib import to_local_digits
from pywikibot.tools import issue_deprecation_warning, FrozenDict
@@ -453,12 +453,32 @@
self.threads = []
self.archives = {}
self.archived_threads = 0
- lines = self.get().split('\n')
+ text = self.get()
+ # Replace text in following exceptions by spaces, but don't change line
+ # numbers
+ exceptions = ['comment', 'code', 'pre', 'source', 'nowiki']
+ exc_regexes = _get_regexes(exceptions, self.site)
+ stripped_text = text
+ for regex in exc_regexes:
+ for match in re.finditer(regex, stripped_text):
+ before = stripped_text[:match.start()]
+ restricted = stripped_text[match.start():match.end()]
+ after = stripped_text[match.end():]
+ restricted = re.sub(r'[^\n]', r'', restricted)
+ stripped_text = before + restricted + after
+ # Find thread headers in stripped text and return their line numbers
+ stripped_lines = stripped_text.split('\n')
+ thread_headers = []
+ for line_number, line in enumerate(stripped_lines, start=1):
+ if re.search(r'^== *[^=].*? *== *$', line):
+ thread_headers.append(line_number)
+ # Fill self by original thread headers on returned line numbers
+ lines = text.split('\n')
found = False # Reading header
cur_thread = None
- for line in lines:
- thread_header = re.search('^== *([^=].*?) *== *$', line)
- if thread_header:
+ for line_number, line in enumerate(lines, start=1):
+ if line_number in thread_headers:
+ thread_header = re.search('^== *([^=].*?) *== *$', line)
found = True # Reading threads now
if cur_thread:
self.threads.append(cur_thread)
--
To view, visit https://gerrit.wikimedia.org/r/397803
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2e7183f431ce3bb4cdd1729e592b7509cbd37b94
Gerrit-PatchSet: 11
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Ato 01 <ato(a)freemail.hu>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Erling Blad <jeblad(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Revi <wiki(a)ymhong.com>
Gerrit-Reviewer: Tacsipacsi <tacsipacsi(a)jnet.hu>
Gerrit-Reviewer: Whym <whym(a)whym.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/398670 )
Change subject: imagecopy.py: Add protocol in the link of 'View in browser' function
......................................................................
imagecopy.py: Add protocol in the link of 'View in browser' function
Bug: T182854
Change-Id: I490c35b62f41b662ddb03150e74ea3850b497c79
---
M scripts/imagecopy.py
1 file changed, 2 insertions(+), 1 deletion(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/scripts/imagecopy.py b/scripts/imagecopy.py
index 656525e..c58a2df 100644
--- a/scripts/imagecopy.py
+++ b/scripts/imagecopy.py
@@ -530,7 +530,8 @@
# Do the TkdialogIC to accept/reject and change te name
(newname, skip) = TkdialogIC(
imagepage.title(withNamespace=False),
- imagepage.get(), username, imagepage.permalink(),
+ imagepage.get(), username,
+ imagepage.permalink(with_protocol=True),
imagepage.templates()).getnewname()
if skip:
--
To view, visit https://gerrit.wikimedia.org/r/398670
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I490c35b62f41b662ddb03150e74ea3850b497c79
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Eflyjason <eflyjason(a)gmail.com>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>