jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/616699 )
Change subject: [4.0] Remove Python 2 code parts in logging.py ......................................................................
[4.0] Remove Python 2 code parts in logging.py
Also cleanup unicode parts in tools.
Change-Id: I330064cbbd9f32f017a387962c2b211ea9f220d4 --- M pywikibot/logging.py M pywikibot/tools/__init__.py 2 files changed, 16 insertions(+), 22 deletions(-)
Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/logging.py b/pywikibot/logging.py index 033c628..83abad9 100644 --- a/pywikibot/logging.py +++ b/pywikibot/logging.py @@ -5,8 +5,6 @@ # # Distributed under the terms of the MIT license. # -from __future__ import absolute_import, division, unicode_literals - import logging import os import sys @@ -18,9 +16,6 @@ VERBOSE = 18 INPUT = 25
-if sys.version_info[0] > 2: - unicode = str - _init_routines = [] _inited_routines = set()
@@ -43,8 +38,8 @@
# User output/logging functions
-# Six output functions are defined. Each requires a unicode or string -# argument. All of these functions generate a message to the log file if +# Six output functions are defined. Each requires a string argument +# All of these functions generate a message to the log file if # logging is enabled ("-log" or "-debug" command line arguments).
# The functions output(), stdout(), warning(), and error() all display a @@ -94,17 +89,16 @@
if decoder: text = text.decode(decoder) - elif not isinstance(text, unicode): - if not isinstance(text, str): - # looks like text is a non-text object. - # Maybe it has a __unicode__ builtin ? - # (allows to print Page, Site...) - text = unicode(text) - else: - try: - text = text.decode('utf-8') - except UnicodeDecodeError: - text = text.decode('iso8859-1') + elif isinstance(text, bytes): + try: + text = text.decode('utf-8') + except UnicodeDecodeError: + text = text.decode('iso8859-1') + else: + # looks like text is a non-text object. + # Maybe it has a __str__ builtin ? + # (allows to print Page, Site...) + text = str(text)
logger.log(_level, text, extra=context, **kwargs)
@@ -210,8 +204,8 @@ exc_info = 1 else: exc_info = sys.exc_info() - msg = '%s: %s' % ( - repr(exc_info[1]).split('(')[0], unicode(exc_info[1]).strip()) + msg = '{}: {}'.format(repr(exc_info[1]).split('(')[0], + str(exc_info[1]).strip()) if tb: kwargs['exc_info'] = exc_info logoutput(msg, decoder, newline, ERROR, **kwargs) diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py index 00735a3..ecfadb0 100644 --- a/pywikibot/tools/__init__.py +++ b/pywikibot/tools/__init__.py @@ -954,7 +954,7 @@
class SelfCallString(SelfCallMixin, str):
- """Unicode string with SelfCallMixin.""" + """String with SelfCallMixin."""
pass
@@ -1089,7 +1089,7 @@ result.update(arg) if conflicts: raise ValueError('Multiple dicts contain the same keys: {0}' - .format(', '.join(sorted(UnicodeType(key) + .format(', '.join(sorted(str(key) for key in conflicts)))) return result