jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/687057 )
Change subject: [IMPR] Add abstract base user interface module to the framework
......................................................................
[IMPR] Add abstract base user interface module to the framework
bot module calls the user interface to be used.
in compat release we had additional interfacec (cgi, tkinter, wxpython)
but all of them failed due to missing interface methods. Therefore add
a abstract base user interface class to ensure that each interface
method is provided. This probably would allow us to implement an
interface for tests and enable assertLogs/assertNoLogs unittest methods
Change-Id: Ic425fe52264b57c44fe97a0a89b9e6260944a8c7
---
M docs/api_ref/pywikibot.userinterfaces.rst
M pywikibot/CONTENT.rst
A pywikibot/userinterfaces/_interface_base.py
M pywikibot/userinterfaces/terminal_interface_base.py
4 files changed, 87 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/api_ref/pywikibot.userinterfaces.rst b/docs/api_ref/pywikibot.userinterfaces.rst
index 486ae00..6d0b506 100644
--- a/docs/api_ref/pywikibot.userinterfaces.rst
+++ b/docs/api_ref/pywikibot.userinterfaces.rst
@@ -3,10 +3,10 @@
.. automodule:: pywikibot.userinterfaces
-gui module
-----------
+\_interface\_base module
+------------------------
-.. automodule:: pywikibot.userinterfaces.gui
+.. automodule:: pywikibot.userinterfaces._interface_base
terminal\_interface module
--------------------------
@@ -28,6 +28,11 @@
.. automodule:: pywikibot.userinterfaces.terminal_interface_win32
+gui module
+----------
+
+.. automodule:: pywikibot.userinterfaces.gui
+
transliteration module
----------------------
diff --git a/pywikibot/CONTENT.rst b/pywikibot/CONTENT.rst
index 5929d91..7f977f5 100644
--- a/pywikibot/CONTENT.rst
+++ b/pywikibot/CONTENT.rst
@@ -172,6 +172,8 @@
+-----------------------------------------------------------------------------------+
| User Interface |
+============================+======================================================+
+ | _interface_base.py | Abstract base user interface module |
+ +----------------------------+------------------------------------------------------+
| gui.py | GUI with a unicode textfield where the user can edit |
+----------------------------+------------------------------------------------------+
| terminal_interface.py | Platform independent terminal interface module |
diff --git a/pywikibot/userinterfaces/_interface_base.py b/pywikibot/userinterfaces/_interface_base.py
new file mode 100644
index 0000000..856a2a3
--- /dev/null
+++ b/pywikibot/userinterfaces/_interface_base.py
@@ -0,0 +1,75 @@
+"""Abstract base user interface module.
+
+*New in version 6.2.*
+"""
+#
+# (C) Pywikibot team, 2021
+#
+# Distributed under the terms of the MIT license.
+#
+import sys
+
+from abc import ABC, abstractmethod
+from typing import Any, Union
+
+from pywikibot.backports import List
+
+
+class ABUIC(ABC):
+
+ """Abstract base user interface class.
+
+ Every user interface should derive from it to ensure that all
+ required methods are implemented.
+ """
+
+ def argvu(self) -> List[str]:
+ """Return copy of sys.argv.
+
+ Assigned to pywikibot.argvu in bot module
+ """
+ return list(sys.argv)
+
+ @abstractmethod
+ def init_handlers(self, *args, **kwargs):
+ """Initialize the handlers for user output.
+
+ Called in bot.init_handlers().
+ """
+
+ @abstractmethod
+ def input(self, *args, **kwargs) -> str:
+ """Ask the user a question and return the answer.
+
+ Called by bot.input().
+ """
+ if args:
+ return input(args[0])
+ return input()
+
+ @abstractmethod
+ def input_choice(self, *args, **kwargs) -> Union[int, str]:
+ """Ask the user and returns a value from the options.
+
+ Called by bot.input_choice().
+ """
+ return self.input()
+
+ @abstractmethod
+ def input_list_choice(self, *args, **kwargs) -> Any:
+ """Ask the user to select one entry from a list of entries.
+
+ Called by bot.input_list_choice().
+ """
+ return self.input()
+
+ @abstractmethod
+ def output(self, *args, **kwargs) -> None:
+ """Output text to a stream."""
+ print(*args, **kwargs) # noqa: T001
+
+ def flush(self):
+ """Flush cached output.
+
+ May be passed to atexit.register() to flush any ui cache.
+ """
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index dfbb0ac..0c13fec 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -22,6 +22,7 @@
StandardOption,
)
from pywikibot.logging import INFO, INPUT, STDOUT, VERBOSE, WARNING
+from pywikibot.userinterfaces._interface_base import ABUIC
from pywikibot.userinterfaces import transliteration
@@ -51,7 +52,7 @@
colorTagR = re.compile('\03{((:?%s);?(:?%s)?)}' % (_color_pat, _color_pat))
-class UI:
+class UI(ABUIC):
"""Base for terminal user interfaces."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/687057
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: Ic425fe52264b57c44fe97a0a89b9e6260944a8c7
Gerrit-Change-Number: 687057
Gerrit-PatchSet: 7
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/+/687203 )
Change subject: [IO] remove outdated register_cp65001() function
......................................................................
[IO] remove outdated register_cp65001() function
cp65001 is an alias for utf-8 since Python 3.8
and was added to the codecs table in Python 3.3 already
https://docs.python.org/3/library/codecs.htmlhttps://docs.python.org/3.7/library/codecs.html
Change-Id: I35277ca3d4a018cc4673c5ac84a8e89e4026cfd0
---
M pywikibot/userinterfaces/win32_unicode.py
1 file changed, 2 insertions(+), 13 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/userinterfaces/win32_unicode.py b/pywikibot/userinterfaces/win32_unicode.py
index 7962408..4b858de 100755
--- a/pywikibot/userinterfaces/win32_unicode.py
+++ b/pywikibot/userinterfaces/win32_unicode.py
@@ -1,6 +1,6 @@
"""Stdout, stderr and argv support for unicode."""
#
-# (C) Pywikibot team, 2012-2018
+# (C) Pywikibot team, 2012-2021
#
##############################################
# Support for unicode in Windows cmd.exe
@@ -21,8 +21,8 @@
# Licensed under both CC-BY-SA and the MIT license.
#
################################################
-import codecs
import sys
+
from contextlib import suppress
from ctypes import Structure, byref
from ctypes import c_void_p as LPVOID
@@ -172,13 +172,6 @@
file=original_stderr)
-def register_cp65001():
- """Register codecs cp65001 as utf-8."""
- # Work around <https://bugs.python.org/issue6058>
- codecs.register(lambda name: name == 'cp65001'
- and codecs.lookup('utf-8') or None)
-
-
def force_truetype_console(h_stdout):
"""Force the console to use a TrueType font (Vista+)."""
TMPF_TRUETYPE = 0x04
@@ -331,7 +324,3 @@
.format(e))
return stdin, stdout, stderr, argv
-
-
-if OSWIN32:
- register_cp65001()
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/687203
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: I35277ca3d4a018cc4673c5ac84a8e89e4026cfd0
Gerrit-Change-Number: 687203
Gerrit-PatchSet: 3
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/+/691263 )
Change subject: [doc] Update ROADMAP.rst, update doc strings
......................................................................
[doc] Update ROADMAP.rst, update doc strings
Change-Id: I7dea0f031379ac563fe1f19a6946a177edce461f
---
M ROADMAP.rst
M pywikibot/pagegenerators.py
M pywikibot/site/_generators.py
3 files changed, 15 insertions(+), 6 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index a688629..1f6e461 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,9 +1,15 @@
Current release changes
^^^^^^^^^^^^^^^^^^^^^^^
+* APISite method pagelanglinks() may skip links with empty titles (T223157)
+* User.name() method was removed in favour of User.username property
+* BasePage.getLatestEditors() method was removed in favour of contributors() or revisions()
+* pagenenerators.handleArg() method was renamed to handle_arg() (T271437)
+* CategoryGenerator, FileGenerator, ImageGenerator and ReferringPageGenerator pagegenerator functions were removed
+* Family.ignore_certificate_error() method was removed in favour of verify_SSL_certificate (T265205)
* tools.is_IP was renamed to is_ip_address due to PEP8
* Fix Page.getDeletedRevision() method which always returned an empty list
-* Async chunked uploads are supported (T129216, 133443)
+* Async chunked uploads are supported (T129216, T133443)
* A new InvalidPageError will be raised if a Page has no version history (T280043)
* config2.py was renamed to config.py
* L10N updates
@@ -26,9 +32,5 @@
* 6.0.1: Site.undeletepage() and Site.undelete_file_versions() will be removed in favour of Site.undelete() method
* 6.0.1: Site.deletepage() and Site.deleteoldimage() will be removed in favour of Site.delete() method
* 6.0.1: DataSite.createNewItemFromPage() method will be removed in favour of ImagePage.fromPage() (T98663)
-* 6.0.0: User.name() method will be removed in favour of User.username property
-* 5.6.0: pagenenerators.handleArg() method will be removed in favour of handle_arg() (T271437)
-* 5.6.0: Family.ignore_certificate_error() method will be removed in favour of verify_SSL_certificate() (T265205)
* 5.0.0: OptionHandler.options dict will be removed in favour of OptionHandler.opt
* 5.0.0: Methods deprecated for 5 years or longer will be removed
-* 5.0.0: pagegenerators.ReferringPageGenerator is desupported and will be removed
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index a8c635a..a992b3c 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -1215,7 +1215,10 @@
return self._parse_log_events(*params)
def handle_args(self, args: Iterable[str]) -> List[str]:
- """Handle command line arguments and return the rest as a list."""
+ """Handle command line arguments and return the rest as a list.
+
+ *New in version 6.0.*
+ """
return [arg for arg in args if not self.handle_arg(arg)]
def handle_arg(self, arg: str) -> bool:
@@ -1227,6 +1230,8 @@
can try parsing the argument. Call getCombinedGenerator() after all
arguments have been parsed to get the final output generator.
+ *Renamed in version 6.0.*
+
@param arg: Pywikibot argument consisting of -name:value
@return: True if the argument supplied was recognised by the factory
"""
diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py
index 475d71b..cfa7bf8 100644
--- a/pywikibot/site/_generators.py
+++ b/pywikibot/site/_generators.py
@@ -736,6 +736,8 @@
include_empty_titles: bool = False):
"""Iterate all interlanguage links on page, yielding Link objects.
+ *New in 6.2:* *include_empty_titles* parameter was added.
+
@see: U{https://www.mediawiki.org/wiki/API:Langlinks}
@param include_obsolete: if true, yield even Link objects whose
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/691263
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: I7dea0f031379ac563fe1f19a6946a177edce461f
Gerrit-Change-Number: 691263
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/+/691149 )
Change subject: [IMPR] pagelanglinks() may skip links with empty titles.
......................................................................
[IMPR] pagelanglinks() may skip links with empty titles.
langlinks API call may retrieve site links with empty titles like
[[en:]]. Introduce a new parameter include_empty_titles (default False)
to ignore such links because it cannot be upcasted to a Page object
but link.astitle() would work.
raise an InvalidTitleError if a Page is to be created with empty title
raise an InvalidPageError if a Page has no pageid
Bug: T223157
Change-Id: Iab294e318ff5412ef9a5b7485afcfb85600d531f
---
M pywikibot/page/__init__.py
M pywikibot/site/_generators.py
2 files changed, 19 insertions(+), 4 deletions(-)
Approvals:
Meno25: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 390e23a..5553d95 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -179,6 +179,13 @@
self._link = Link(title, source=source.site,
default_namespace=ns)
elif isinstance(source, BaseLink):
+ if not source.title:
+ raise InvalidTitleError(
+ '{} title of {} {} cannot be empty.'
+ .format(self.__class__.__name__,
+ source.__class__.__name__,
+ source.astext()))
+
self._link = source
self._revisions = {}
else:
@@ -707,7 +714,9 @@
If the title includes a section, return False if this section isn't
found.
"""
- return self.pageid > 0
+ with suppress(AttributeError):
+ return self.pageid > 0
+ raise InvalidPageError(self)
@property
def oldest_revision(self):
diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py
index 5bd2755..475d71b 100644
--- a/pywikibot/site/_generators.py
+++ b/pywikibot/site/_generators.py
@@ -730,13 +730,18 @@
api.update_page(page, pagedata, rvgen.props)
@deprecated_args(step=True)
- def pagelanglinks(self, page, *, total=None, include_obsolete=False):
+ def pagelanglinks(self, page, *,
+ total: Optional[int] = None,
+ include_obsolete: bool = False,
+ include_empty_titles: bool = False):
"""Iterate all interlanguage links on page, yielding Link objects.
@see: U{https://www.mediawiki.org/wiki/API:Langlinks}
@param include_obsolete: if true, yield even Link objects whose
- site is obsolete
+ site is obsolete
+ @param include_empty_titles: if true, yield even Link objects whose
+ title is empty but redirects to a site like [[en:]]
"""
lltitle = page.title(with_section=False)
llquery = self._generator(api.PropertyGenerator,
@@ -755,7 +760,8 @@
if link.site.obsolete and not include_obsolete:
continue
- yield link
+ if link.title or include_empty_titles:
+ yield link
@deprecated_args(step=True)
def page_extlinks(self, page, *, total=None):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/691149
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: Iab294e318ff5412ef9a5b7485afcfb85600d531f
Gerrit-Change-Number: 691149
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Meno25 <meno25mail(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged