jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/692710 )
Change subject: [cleanup] Remove toStdout parameter of ui.output()
......................................................................
[cleanup] Remove toStdout parameter of ui.output()
toStdout parameter was never used.
The targetStream is passed via TerminalHandler
Change-Id: Iba42257962d94917a2df623449e2fcf256ecf7b0
---
M pywikibot/userinterfaces/terminal_interface_base.py
1 file changed, 4 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index 4b026b0..bdd2672 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -189,14 +189,14 @@
# set the new color, but only if they change
self.encounter_color(color_stack[-1], target_stream)
- def output(self, text, toStdout=False, targetStream=None):
+ def output(self, text, targetStream=None):
"""Forward text to cache and flush if output is not locked.
All input methods locks the output to a stream but collect them
in cache. They will be printed with next unlocked output call or
at termination time.
"""
- self.cache_output(text, toStdout, targetStream)
+ self.cache_output(text, targetStream=targetStream)
if not self.lock.locked():
self.flush()
@@ -213,7 +213,7 @@
"""
self.cache.put_nowait((args, kwargs))
- def stream_output(self, text, toStdout=False, targetStream=None):
+ def stream_output(self, text, targetStream=None):
"""
Output text to a stream.
@@ -268,10 +268,7 @@
text = transliteratedText
if not targetStream:
- if toStdout:
- targetStream = self.stdout
- else:
- targetStream = self.stderr
+ targetStream = self.stderr
self._print(text, targetStream)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/692710
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: Iba42257962d94917a2df623449e2fcf256ecf7b0
Gerrit-Change-Number: 692710
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/+/692572 )
Change subject: [tests] Re-implement YearPageGenerator tests
......................................................................
[tests] Re-implement YearPageGenerator tests
A lot of YearPageGenerator tests aren't tests but skipped because
site.lang is missing in date.formats['YearAD'] mapping but
date.formats['YearAD'] was changes to a defaultdict which maps
every missing lang to dh_simpleYearAD function.
Change-Id: I0534651184fe41cdd77164d6d76eaead2ded3192
---
M tests/pagegenerators_tests.py
1 file changed, 3 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 484bd0c..afcc382 100644
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -476,10 +476,10 @@
"""Test YearPageGenerator."""
site = self.get_site()
# Some languages are missing (T85681)
- if (site.lang not in date.formats['YearBC']
- or site.lang not in date.formats['YearAD']):
+ if site.lang not in date.formats['YearBC']:
self.skipTest(
- 'Date formats for this language are missing from date.py')
+ 'Date formats for {!r} language are missing from date.py'
+ .format(site.lang))
start = -20
end = 2026
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/692572
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: I0534651184fe41cdd77164d6d76eaead2ded3192
Gerrit-Change-Number: 692572
Gerrit-PatchSet: 6
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/+/692270 )
Change subject: [IMPR] subclass TerminalHandler from logging.StreamHandler
......................................................................
[IMPR] subclass TerminalHandler from logging.StreamHandler
- rename strm parameter to stream
- use createLock to set thread lock
- flush of superclass to flush the stream which also acquires locking
- rename text to msg like usage in StreamHandler
Change-Id: Iccc67f233880dcc6c55e5980b3942695a03711fc
---
M pywikibot/userinterfaces/terminal_interface_base.py
1 file changed, 22 insertions(+), 26 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index 9db7fc3..c7bc96b 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -22,7 +22,7 @@
StandardOption,
)
from pywikibot.logging import INFO, INPUT, STDOUT, VERBOSE, WARNING
-from pywikibot.tools import RLock
+from pywikibot.tools import deprecated_args, RLock
from pywikibot.userinterfaces import transliteration
from pywikibot.userinterfaces._interface_base import ABUIC
@@ -97,7 +97,7 @@
default_stream = self.stderr
# default handler for display to terminal
- default_handler = TerminalHandler(self, strm=default_stream)
+ default_handler = TerminalHandler(self, stream=default_stream)
if config.verbose_output:
default_handler.setLevel(VERBOSE)
else:
@@ -109,7 +109,7 @@
root_logger.addHandler(default_handler)
# handler for level STDOUT
- output_handler = TerminalHandler(self, strm=self.stdout)
+ output_handler = TerminalHandler(self, stream=self.stdout)
output_handler.setLevel(STDOUT)
output_handler.addFilter(MaxLevelFilter(STDOUT))
output_handler.setFormatter(
@@ -117,7 +117,7 @@
root_logger.addHandler(output_handler)
# handler for levels WARNING and higher
- warning_handler = TerminalHandler(self, strm=self.stderr)
+ warning_handler = TerminalHandler(self, stream=self.stderr)
warning_handler.setLevel(WARNING)
warning_handler.setFormatter(
TerminalFormatter(fmt='%(levelname)s: %(message)s%(newline)s'))
@@ -494,44 +494,40 @@
return list(self.argv)
-class TerminalHandler(logging.Handler):
+class TerminalHandler(logging.StreamHandler):
"""A handler class that writes logging records to a terminal.
- This class does not close the stream,
- as sys.stdout or sys.stderr may be (and usually will be) used.
+ This class does not close the stream, as sys.stdout or sys.stderr
+ may be (and usually will be) used.
Slightly modified version of the StreamHandler class that ships with
logging module, plus code for colorization of output.
-
"""
# create a class-level lock that can be shared by all instances
sharedlock = threading.RLock()
- def __init__(self, UI, strm=None):
+ @deprecated_args(strm='stream')
+ def __init__(self, UI, stream=None):
"""Initialize the handler.
- If strm is not specified, sys.stderr is used.
-
+ If stream is not specified, sys.stderr is used.
"""
- super().__init__()
- # replace Handler's instance-specific lock with the shared class lock
- # to ensure that only one instance of this handler can write to
- # the console at a time
- self.lock = TerminalHandler.sharedlock
- if strm is None:
- strm = sys.stderr
- self.stream = strm
- self.formatter = None
+ super().__init__(stream=stream)
self.UI = UI
- def flush(self):
- """Flush the stream."""
- self.stream.flush()
+ def createLock(self):
+ """Acquire a thread lock for serializing access to the underlying I/O.
+
+ Replace Handler's instance-specific lock with the shared
+ class lock to ensure that only one instance of this handler can
+ write to the console at a time.
+ """
+ self.lock = TerminalHandler.sharedlock
def emit(self, record):
- """Emit the record formatted to the output and return it."""
+ """Emit the record formatted to the output."""
if record.name == 'py.warnings':
# Each warning appears twice
# the second time it has a 'message'
@@ -540,8 +536,8 @@
record.__dict__.setdefault('newline', '\n')
- text = self.format(record)
- return self.UI.output(text, targetStream=self.stream)
+ msg = self.format(record)
+ self.UI.output(msg, targetStream=self.stream)
class TerminalFormatter(logging.Formatter):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/692270
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: Iccc67f233880dcc6c55e5980b3942695a03711fc
Gerrit-Change-Number: 692270
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
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/+/692317 )
Change subject: [doc] Update doc of ui_tests.Stream
......................................................................
[doc] Update doc of ui_tests.Stream
BytesIO instance are no longer supported with Python 3
Change-Id: Ie41b2d4087e4a576376213ba5c223b44743d7938
---
M tests/ui_tests.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/ui_tests.py b/tests/ui_tests.py
index 4f5e610..a4d7f7f 100644
--- a/tests/ui_tests.py
+++ b/tests/ui_tests.py
@@ -33,11 +33,11 @@
class Stream:
- """Handler for a StringIO or BytesIO instance able to patch itself."""
+ """Handler for a StringIO instance able to patch itself."""
def __init__(self, name: str, patched_streams: dict):
"""
- Create a new stream with a StringIO or BytesIO instance.
+ Create a new stream with a StringIO instance.
@param name: The part after 'std' (e.g. 'err').
@param patched_streams: A mapping which maps the original stream to
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/692317
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: Ie41b2d4087e4a576376213ba5c223b44743d7938
Gerrit-Change-Number: 692317
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/692322 )
Change subject: [tests] Additional processing hints
......................................................................
[tests] Additional processing hints
Change-Id: I9abecd69e8f1ea8e8398cbc3cd9b0e91e45f20f8
---
M pywikibot/userinterfaces/terminal_interface_base.py
1 file changed, 3 insertions(+), 2 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index 6b9a587..e9e2cf5 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -209,8 +209,9 @@
print('######### SIZE is >0 but QUEUE is EMPTY #####')
while not self.cache.empty():
args, kwargs = self.cache.get_nowait()
- print('###', args)
+ print('##>', args)
self.stream_output(*args, **kwargs)
+ print('##<')
print('<<< flush:', self.cache.qsize())
def cache_output(self, *args, **kwargs):
@@ -232,7 +233,7 @@
*New in version 6.2*
"""
- print('>>> stream_output:', text)
+ print('>>> stream_output:', text, file=sys.stdout, flush=True)
if config.transliterate:
# Encode our unicode string in the encoding used by the user's
# console, and decode it back to unicode. Then we can see which
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/692322
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: tests
Gerrit-Change-Id: I9abecd69e8f1ea8e8398cbc3cd9b0e91e45f20f8
Gerrit-Change-Number: 692322
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/692290 )
Change subject: [tests] flush tests anf method hints
......................................................................
[tests] flush tests anf method hints
Change-Id: I4d934b0db42fbe0cb3e6355cd392cdf250c976f9
---
M pywikibot/userinterfaces/terminal_interface_base.py
1 file changed, 32 insertions(+), 23 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index 9db7fc3..f2bd888 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -22,7 +22,7 @@
StandardOption,
)
from pywikibot.logging import INFO, INPUT, STDOUT, VERBOSE, WARNING
-from pywikibot.tools import RLock
+from pywikibot.tools import deprecated_args, RLock
from pywikibot.userinterfaces import transliteration
from pywikibot.userinterfaces._interface_base import ABUIC
@@ -97,7 +97,7 @@
default_stream = self.stderr
# default handler for display to terminal
- default_handler = TerminalHandler(self, strm=default_stream)
+ default_handler = TerminalHandler(self, stream=default_stream)
if config.verbose_output:
default_handler.setLevel(VERBOSE)
else:
@@ -109,7 +109,7 @@
root_logger.addHandler(default_handler)
# handler for level STDOUT
- output_handler = TerminalHandler(self, strm=self.stdout)
+ output_handler = TerminalHandler(self, stream=self.stdout)
output_handler.setLevel(STDOUT)
output_handler.addFilter(MaxLevelFilter(STDOUT))
output_handler.setFormatter(
@@ -117,7 +117,7 @@
root_logger.addHandler(output_handler)
# handler for levels WARNING and higher
- warning_handler = TerminalHandler(self, strm=self.stderr)
+ warning_handler = TerminalHandler(self, stream=self.stderr)
warning_handler.setLevel(WARNING)
warning_handler.setFormatter(
TerminalFormatter(fmt='%(levelname)s: %(message)s%(newline)s'))
@@ -196,22 +196,28 @@
in cache. They will be printed with next unlocked output call or
at termination time.
"""
+ print('>>> output', text)
self.cache_output(text, toStdout, targetStream)
if not self.lock.locked():
self.flush()
+ print('<<< output', text)
def flush(self):
"""Output cached text."""
+ print('>>> flush')
while not self.cache.empty():
args, kwargs = self.cache.get_nowait()
self.stream_output(*args, **kwargs)
+ print('<<< flush')
def cache_output(self, *args, **kwargs):
"""Put text to cache.
*New in version 6.2*
"""
+ print('>>> cache_output', args)
self.cache.put_nowait((args, kwargs))
+ print('<<< cache_output', args)
def stream_output(self, text, toStdout=False, targetStream=None):
"""
@@ -223,6 +229,7 @@
*New in version 6.2*
"""
+ print('>>> stream_output', text)
if config.transliterate:
# Encode our unicode string in the encoding used by the user's
# console, and decode it back to unicode. Then we can see which
@@ -274,6 +281,7 @@
targetStream = self.stderr
self._print(text, targetStream)
+ print('<<< stream_output', text)
def _raw_input(self):
# May be overridden by subclass
@@ -494,41 +502,42 @@
return list(self.argv)
-class TerminalHandler(logging.Handler):
+class TerminalHandler(logging.StreamHandler):
"""A handler class that writes logging records to a terminal.
- This class does not close the stream,
- as sys.stdout or sys.stderr may be (and usually will be) used.
+ This class does not close the stream, as sys.stdout or sys.stderr
+ may be (and usually will be) used.
Slightly modified version of the StreamHandler class that ships with
logging module, plus code for colorization of output.
-
"""
# create a class-level lock that can be shared by all instances
sharedlock = threading.RLock()
- def __init__(self, UI, strm=None):
+ @deprecated_args(strm='stream')
+ def __init__(self, UI, stream=None):
"""Initialize the handler.
- If strm is not specified, sys.stderr is used.
-
+ If stream is not specified, sys.stderr is used.
"""
- super().__init__()
- # replace Handler's instance-specific lock with the shared class lock
- # to ensure that only one instance of this handler can write to
- # the console at a time
- self.lock = TerminalHandler.sharedlock
- if strm is None:
- strm = sys.stderr
- self.stream = strm
- self.formatter = None
+ super().__init__(stream=stream)
self.UI = UI
+ def createLock(self):
+ """Acquire a thread lock for serializing access to the underlying I/O.
+
+ Replace Handler's instance-specific lock with the shared
+ class lock to ensure that only one instance of this handler can
+ write to the console at a time.
+ """
+ self.lock = TerminalHandler.sharedlock
+
def flush(self):
"""Flush the stream."""
- self.stream.flush()
+ self.UI.flush()
+ super().flush()
def emit(self, record):
"""Emit the record formatted to the output and return it."""
@@ -540,8 +549,8 @@
record.__dict__.setdefault('newline', '\n')
- text = self.format(record)
- return self.UI.output(text, targetStream=self.stream)
+ msg = self.format(record)
+ return self.UI.output(msg, targetStream=self.stream)
class TerminalFormatter(logging.Formatter):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/692290
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: tests
Gerrit-Change-Id: I4d934b0db42fbe0cb3e6355cd392cdf250c976f9
Gerrit-Change-Number: 692290
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/+/691932 )
Change subject: [tests] fix INVALID_TITLE_RE in page_tests
......................................................................
[tests] fix INVALID_TITLE_RE in page_tests
Change-Id: I12fcba6966b3ad47089c0321be86083a8fe204ad
---
M tests/page_tests.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/page_tests.py b/tests/page_tests.py
index c2de328..fdf51e9 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -31,7 +31,7 @@
EMPTY_TITLE_RE = r'Title must be specified and not empty if source is a Site\.'
-INVALID_TITLE_RE = r'The link does not contain a page title'
+INVALID_TITLE_RE = r'The link \[\[.*\]\] does not contain a page title'
NO_PAGE_RE = r"doesn't exist\."
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/691932
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: I12fcba6966b3ad47089c0321be86083a8fe204ad
Gerrit-Change-Number: 691932
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged