jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Use unicode_literals ......................................................................
[IMPROV] Use unicode_literals
This adds the unicode_literals import to the library.
Bug: T89589 Change-Id: I033e6a71cc82e3b46b843c9895b7c152d102fc40 --- M pwb.py M pywikibot/__init__.py M pywikibot/backports.py M pywikibot/bot.py M pywikibot/botirc.py M pywikibot/comms/__init__.py M pywikibot/comms/http.py M pywikibot/comms/rcstream.py M pywikibot/comms/threadedhttp.py M pywikibot/compat/catlib.py M pywikibot/compat/query.py M pywikibot/compat/userlib.py M pywikibot/config2.py M pywikibot/data/__init__.py M pywikibot/data/api.py M pywikibot/data/wikidataquery.py M pywikibot/data/wikistats.py M pywikibot/date.py M pywikibot/diff.py M pywikibot/echo.py M pywikibot/editor.py M pywikibot/exceptions.py M pywikibot/families/__init__.py M pywikibot/families/anarchopedia_family.py M pywikibot/families/battlestarwiki_family.py M pywikibot/families/commons_family.py M pywikibot/families/i18n_family.py M pywikibot/families/incubator_family.py M pywikibot/families/lyricwiki_family.py M pywikibot/families/mediawiki_family.py M pywikibot/families/meta_family.py M pywikibot/families/omegawiki_family.py M pywikibot/families/osm_family.py M pywikibot/families/outreach_family.py M pywikibot/families/species_family.py M pywikibot/families/strategy_family.py M pywikibot/families/test_family.py M pywikibot/families/vikidia_family.py M pywikibot/families/wikia_family.py M pywikibot/families/wikibooks_family.py M pywikibot/families/wikidata_family.py M pywikibot/families/wikimedia_family.py M pywikibot/families/wikinews_family.py M pywikibot/families/wikipedia_family.py M pywikibot/families/wikiquote_family.py M pywikibot/families/wikisource_family.py M pywikibot/families/wikitech_family.py M pywikibot/families/wikiversity_family.py M pywikibot/families/wikivoyage_family.py M pywikibot/families/wiktionary_family.py M pywikibot/families/wowwiki_family.py M pywikibot/family.py M pywikibot/fixes.py M pywikibot/i18n.py M pywikibot/interwiki_graph.py M pywikibot/logentries.py M pywikibot/login.py M pywikibot/page.py M pywikibot/pagegenerators.py M pywikibot/plural.py M pywikibot/site.py M pywikibot/textlib.py M pywikibot/throttle.py M pywikibot/titletranslate.py M pywikibot/tools/__init__.py M pywikibot/tools/ip.py M pywikibot/userinterfaces/__init__.py M pywikibot/userinterfaces/cgi_interface.py M pywikibot/userinterfaces/gui.py M pywikibot/userinterfaces/terminal_interface.py M pywikibot/userinterfaces/terminal_interface_base.py M pywikibot/userinterfaces/terminal_interface_unix.py M pywikibot/userinterfaces/terminal_interface_win32.py M pywikibot/userinterfaces/transliteration.py M pywikibot/userinterfaces/win32_unicode.py M pywikibot/version.py M pywikibot/weblib.py M pywikibot/xmlreader.py M scripts/add_text.py M scripts/archivebot.py M scripts/basic.py M scripts/blockpageschecker.py M scripts/blockreview.py M scripts/capitalize_redirects.py M scripts/casechecker.py M scripts/catall.py M scripts/category.py M scripts/category_redirect.py M scripts/cfd.py M scripts/checkimages.py M scripts/claimit.py M scripts/clean_sandbox.py M scripts/commons_link.py M scripts/commonscat.py M scripts/coordinate_import.py M scripts/cosmetic_changes.py M scripts/create_categories.py M scripts/data_ingestion.py M scripts/delete.py M scripts/disambredir.py M scripts/editarticle.py M scripts/featured.py M scripts/fixing_redirects.py M scripts/flickrripper.py M scripts/freebasemappingupload.py M scripts/harvest_template.py M scripts/illustrate_wikidata.py M scripts/image.py M scripts/imagerecat.py M scripts/imagetransfer.py M scripts/imageuncat.py M scripts/interwiki.py M scripts/isbn.py M scripts/listpages.py M scripts/login.py M scripts/lonelypages.py M scripts/maintenance/cache.py M scripts/maintenance/compat2core.py M scripts/maintenance/make_i18n_dict.py M scripts/maintenance/wikimedia_sites.py M scripts/makecat.py M scripts/match_images.py M scripts/misspelling.py M scripts/movepages.py M scripts/newitem.py M scripts/noreferences.py M scripts/nowcommons.py M scripts/pagefromfile.py M scripts/patrol.py M scripts/piper.py M scripts/protect.py M scripts/redirect.py M scripts/reflinks.py M scripts/replace.py M scripts/replicate_wiki.py M scripts/revertbot.py M scripts/script_wui.py M scripts/selflink.py M scripts/shell.py M scripts/solve_disambiguation.py M scripts/spamremove.py M scripts/states_redirect.py M scripts/template.py M scripts/templatecount.py M scripts/touch.py M scripts/transferbot.py M scripts/unlink.py M scripts/unusedfiles.py M scripts/upload.py M scripts/version.py M scripts/watchlist.py M scripts/weblinkchecker.py M scripts/welcome.py M tests/__init__.py M tests/api_tests.py M tests/archivebot_tests.py M tests/aspects.py M tests/cache_tests.py M tests/category_tests.py M tests/checkimages_tests.py M tests/data_ingestion_tests.py M tests/date_tests.py M tests/deletionbot_tests.py M tests/deprecation_tests.py M tests/dry_api_tests.py M tests/dry_site_tests.py M tests/edit_failure_tests.py M tests/exceptions_tests.py M tests/family_tests.py M tests/file_tests.py M tests/http_tests.py M tests/i18n/pywikibot.py M tests/i18n/test.py M tests/i18n_tests.py M tests/interwiki_link_tests.py M tests/ipregex_tests.py M tests/isbn_tests.py M tests/l10n_tests.py M tests/link_tests.py M tests/mediawikiversion_tests.py M tests/namespace_tests.py M tests/page_tests.py M tests/pagegenerators_tests.py M tests/protectbot_tests.py M tests/pwb/print_locals.py M tests/pwb_tests.py M tests/reflinks_tests.py M tests/script_tests.py M tests/site_tests.py M tests/tests_tests.py M tests/textlib_tests.py M tests/thread_tests.py M tests/timestamp_tests.py M tests/timestripper_tests.py M tests/tk_tests.py M tests/ui_tests.py M tests/upload_tests.py M tests/uploadbot_tests.py M tests/utils.py M tests/weblib_tests.py M tests/wikibase_edit_tests.py M tests/wikibase_tests.py M tests/wikidataquery_tests.py M tests/wikistats_tests.py M tests/xmlreader_tests.py 205 files changed, 466 insertions(+), 98 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py index 09d0836..365a22e 100644 --- a/pwb.py +++ b/pwb.py @@ -12,7 +12,7 @@ # # Distributed under the terms of the MIT license. # -from __future__ import print_function +from __future__ import print_function, unicode_literals __version__ = '$Id$'
# The following snippet was developed by Ned Batchelder (and others) @@ -57,7 +57,8 @@
# Create a module to serve as __main__ old_main_mod = sys.modules['__main__'] - main_mod = types.ModuleType('__main__') + # it's explicitly using str() to bypass unicode_literals in Python 2 + main_mod = types.ModuleType(str('__main__')) sys.modules['__main__'] = main_mod main_mod.__file__ = filename if sys.version_info[0] > 2: @@ -65,7 +66,8 @@ else: main_mod.__builtins__ = sys.modules['__builtin__'] if package: - main_mod.__package__ = package + # it's explicitly using str() to bypass unicode_literals in Python 2 + main_mod.__package__ = str(package)
# Set sys.argv and the first path element properly. old_argv = sys.argv diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index d4b3081..db96621 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __release__ = '2.0b3' __version__ = '$Id$'
diff --git a/pywikibot/backports.py b/pywikibot/backports.py index f24100d..fbebf8f 100644 --- a/pywikibot/backports.py +++ b/pywikibot/backports.py @@ -58,6 +58,7 @@ # # Distributed under the terms of the PSF license. # +from __future__ import unicode_literals
import logging import warnings diff --git a/pywikibot/bot.py b/pywikibot/bot.py index 3a5ea91..ef8ef57 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
# Note: the intention is to develop this module (at some point) into a Bot @@ -359,7 +361,9 @@ ver = version.get_module_version(module) mtime = version.get_module_mtime(module) if filename and ver and mtime: - log(u' {0} {1} {2}'.format(filename, ver[:7], mtime.isoformat(' '))) + # it's explicitly using str() to bypass unicode_literals in Python 2 + # isoformat expects a char not a unicode in Python 2 + log(u' {0} {1} {2}'.format(filename, ver[:7], mtime.isoformat(str(' '))))
if config.log_pywiki_repo_version: log(u'PYWIKI REPO VERSION: %s' % version.getversion_onlinerepo()) diff --git a/pywikibot/botirc.py b/pywikibot/botirc.py index e4868a1..c63f4d0 100644 --- a/pywikibot/botirc.py +++ b/pywikibot/botirc.py @@ -11,6 +11,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
# Note: the intention is to develop this module (at some point) into a Bot diff --git a/pywikibot/comms/__init__.py b/pywikibot/comms/__init__.py index 3b768bb..747d0a7 100644 --- a/pywikibot/comms/__init__.py +++ b/pywikibot/comms/__init__.py @@ -5,4 +5,6 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py index 011eb59..7606963 100644 --- a/pywikibot/comms/http.py +++ b/pywikibot/comms/http.py @@ -11,6 +11,7 @@ - URL-encoding all data - Basic HTTP error handling """ +from __future__ import unicode_literals
# # (C) Pywikibot team, 2007-2015 diff --git a/pywikibot/comms/rcstream.py b/pywikibot/comms/rcstream.py index fb310f9..d024bc8 100644 --- a/pywikibot/comms/rcstream.py +++ b/pywikibot/comms/rcstream.py @@ -8,6 +8,7 @@ This module requires socketIO_client to be installed: pip install socketIO_client """ +from __future__ import unicode_literals
import sys import threading diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py index e3c0e64..4adb427 100644 --- a/pywikibot/comms/threadedhttp.py +++ b/pywikibot/comms/threadedhttp.py @@ -8,6 +8,7 @@ - HttpRequest object
""" +from __future__ import unicode_literals
# (C) Pywikibot team, 2007-2014 # (C) Httplib 2 team, 2006 diff --git a/pywikibot/compat/catlib.py b/pywikibot/compat/catlib.py index f329b21..fe2aa55 100644 --- a/pywikibot/compat/catlib.py +++ b/pywikibot/compat/catlib.py @@ -11,6 +11,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
diff --git a/pywikibot/compat/query.py b/pywikibot/compat/query.py index 46e9976..13c7059 100644 --- a/pywikibot/compat/query.py +++ b/pywikibot/compat/query.py @@ -11,6 +11,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + import pywikibot from pywikibot.data import api from pywikibot.tools import deprecated, deprecate_arg diff --git a/pywikibot/compat/userlib.py b/pywikibot/compat/userlib.py index 4c999c7..4ff7e78 100644 --- a/pywikibot/compat/userlib.py +++ b/pywikibot/compat/userlib.py @@ -11,6 +11,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
diff --git a/pywikibot/config2.py b/pywikibot/config2.py index 6e7954d..dbb1c28 100644 --- a/pywikibot/config2.py +++ b/pywikibot/config2.py @@ -19,6 +19,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
@@ -28,6 +30,8 @@ import sys
from warnings import warn + +from pywikibot.tools import default_encoding
# This frozen set should contain all imported modules/variables, so it must # occur directly after the imports. At that point globals() only contains the @@ -903,11 +907,7 @@ _ConfigurationDeprecationWarning)
# Fix up default console_encoding -if console_encoding is None: - if sys.platform == 'win32': - console_encoding = 'cp850' - else: - console_encoding = 'iso-8859-1' +console_encoding = default_encoding(console_encoding)
# Fix up transliteration_target if transliteration_target == 'not set': diff --git a/pywikibot/data/__init__.py b/pywikibot/data/__init__.py index 81fe96f..44183c7 100644 --- a/pywikibot/data/__init__.py +++ b/pywikibot/data/__init__.py @@ -5,4 +5,6 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 127c423..6c13e0e 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
from collections import Container, MutableMapping @@ -1144,7 +1146,7 @@
if ip.is_IP(self.site._userinfo['name']): raise Error(u"API write action attempted as IP %r" - % self.site._userinfo['name']) + % str(self.site._userinfo['name']))
if not self.site.user(): pywikibot.warning( @@ -1463,10 +1465,9 @@ # strip the headers to get the HTTP message body if sys.version_info[0] > 2: body = container.as_bytes() - marker = b"\n\n" # separates headers from body else: body = container.as_string() - marker = "\n\n" # separates headers from body + marker = b'\n\n' # separates headers from body eoh = body.find(marker) body = body[eoh + len(marker):] # retrieve the headers from the MIME object diff --git a/pywikibot/data/wikidataquery.py b/pywikibot/data/wikidataquery.py index fd08839..2af1792 100644 --- a/pywikibot/data/wikidataquery.py +++ b/pywikibot/data/wikidataquery.py @@ -4,11 +4,13 @@ # (C) Pywikibot team, 2013 # # Distributed under the terms of the MIT license. +from __future__ import unicode_literals
import json import sys if sys.version_info[0] > 2: from urllib.parse import quote + basestring = (str, ) else: from urllib2 import quote import pickle @@ -294,7 +296,7 @@ return '"%s"' % x
def validate(self): - return self.isOrContainsOnlyTypes(self.items, str) + return self.isOrContainsOnlyTypes(self.items, basestring)
class Tree(Query): @@ -408,7 +410,7 @@ self.validateOrRaise()
def validate(self): - return self.isOrContainsOnlyTypes(self.link, str) + return self.isOrContainsOnlyTypes(self.link, basestring)
def __str__(self): return "%s[%s]" % (self.queryType, self.formatList(self.link)) diff --git a/pywikibot/data/wikistats.py b/pywikibot/data/wikistats.py index dee09fd..dd445c7 100644 --- a/pywikibot/data/wikistats.py +++ b/pywikibot/data/wikistats.py @@ -4,6 +4,7 @@ # (C) Pywikibot team, 2014 # # Distributed under the terms of the MIT license. +from __future__ import unicode_literals
import sys
diff --git a/pywikibot/date.py b/pywikibot/date.py index aea18fd..976edef 100644 --- a/pywikibot/date.py +++ b/pywikibot/date.py @@ -11,7 +11,7 @@ # # Distributed under the terms of the MIT license. # -from __future__ import division +from __future__ import division, unicode_literals __version__ = '$Id$' #
diff --git a/pywikibot/diff.py b/pywikibot/diff.py index 9bde69f..6e0e38b 100644 --- a/pywikibot/diff.py +++ b/pywikibot/diff.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
diff --git a/pywikibot/echo.py b/pywikibot/echo.py index a7ed138..311827d 100644 --- a/pywikibot/echo.py +++ b/pywikibot/echo.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Classes and functions for working with the Echo extension.""" +from __future__ import unicode_literals
import pywikibot
diff --git a/pywikibot/editor.py b/pywikibot/editor.py index 7d1687d..7d0aa1b 100644 --- a/pywikibot/editor.py +++ b/pywikibot/editor.py @@ -1,6 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- """Text editor class for your favourite editor.""" +from __future__ import unicode_literals
# # (C) Gerrit Holl, 2004 diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py index df3ffbd..117165a 100644 --- a/pywikibot/exceptions.py +++ b/pywikibot/exceptions.py @@ -67,6 +67,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import sys diff --git a/pywikibot/families/__init__.py b/pywikibot/families/__init__.py index e1d916b..ccb2305 100644 --- a/pywikibot/families/__init__.py +++ b/pywikibot/families/__init__.py @@ -5,4 +5,6 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' diff --git a/pywikibot/families/anarchopedia_family.py b/pywikibot/families/anarchopedia_family.py index 08ba6f3..e6d31fd 100644 --- a/pywikibot/families/anarchopedia_family.py +++ b/pywikibot/families/anarchopedia_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Anarchopedia wiki.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/battlestarwiki_family.py b/pywikibot/families/battlestarwiki_family.py index a5fe75d..954dfe3 100644 --- a/pywikibot/families/battlestarwiki_family.py +++ b/pywikibot/families/battlestarwiki_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Battlestar Wiki.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/commons_family.py b/pywikibot/families/commons_family.py index 7eb670a..e4d8520 100644 --- a/pywikibot/families/commons_family.py +++ b/pywikibot/families/commons_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Wikimedia Commons.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/i18n_family.py b/pywikibot/families/i18n_family.py index 31c33e0..dc75d8d 100644 --- a/pywikibot/families/i18n_family.py +++ b/pywikibot/families/i18n_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Translate Wiki.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/incubator_family.py b/pywikibot/families/incubator_family.py index b57d386..5f0ad41 100644 --- a/pywikibot/families/incubator_family.py +++ b/pywikibot/families/incubator_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Incubator Wiki.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/lyricwiki_family.py b/pywikibot/families/lyricwiki_family.py index 642e573..0839ff9 100644 --- a/pywikibot/families/lyricwiki_family.py +++ b/pywikibot/families/lyricwiki_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for LyricWiki.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/mediawiki_family.py b/pywikibot/families/mediawiki_family.py index fe979b0..8c9856d 100644 --- a/pywikibot/families/mediawiki_family.py +++ b/pywikibot/families/mediawiki_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for MediaWiki wiki.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/meta_family.py b/pywikibot/families/meta_family.py index 58f7de9..eeb4b27 100644 --- a/pywikibot/families/meta_family.py +++ b/pywikibot/families/meta_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Meta Wiki.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/omegawiki_family.py b/pywikibot/families/omegawiki_family.py index d6b4a8d..f25c6a8 100644 --- a/pywikibot/families/omegawiki_family.py +++ b/pywikibot/families/omegawiki_family.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """Family module for Omega Wiki.""" +from __future__ import unicode_literals + __version__ = '$Id$'
from pywikibot import family diff --git a/pywikibot/families/osm_family.py b/pywikibot/families/osm_family.py index 995c8d6..5b0d198 100644 --- a/pywikibot/families/osm_family.py +++ b/pywikibot/families/osm_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for OpenStreetMap wiki.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/outreach_family.py b/pywikibot/families/outreach_family.py index 318dbe3..8ad23b6 100644 --- a/pywikibot/families/outreach_family.py +++ b/pywikibot/families/outreach_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Wikimedia outreach wiki.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/species_family.py b/pywikibot/families/species_family.py index 6a85925..9206243 100644 --- a/pywikibot/families/species_family.py +++ b/pywikibot/families/species_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Wikimedia species wiki.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/strategy_family.py b/pywikibot/families/strategy_family.py index fc33e9c..3d3570c 100644 --- a/pywikibot/families/strategy_family.py +++ b/pywikibot/families/strategy_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Wikimedia Strategy Wiki.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/test_family.py b/pywikibot/families/test_family.py index 2a587c0..2a943b9 100644 --- a/pywikibot/families/test_family.py +++ b/pywikibot/families/test_family.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """Family module for test.wikipedia.org.""" +from __future__ import unicode_literals + __version__ = '$Id$'
from pywikibot import family diff --git a/pywikibot/families/vikidia_family.py b/pywikibot/families/vikidia_family.py index 95e34c7..07bbe7a 100644 --- a/pywikibot/families/vikidia_family.py +++ b/pywikibot/families/vikidia_family.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """Family module for Vikidia.""" +from __future__ import unicode_literals + __version__ = '$Id$'
from pywikibot import family diff --git a/pywikibot/families/wikia_family.py b/pywikibot/families/wikia_family.py index 7dc627a..73e0f46 100644 --- a/pywikibot/families/wikia_family.py +++ b/pywikibot/families/wikia_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Wikia.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/wikibooks_family.py b/pywikibot/families/wikibooks_family.py index f701f01..3183106 100644 --- a/pywikibot/families/wikibooks_family.py +++ b/pywikibot/families/wikibooks_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Wikibooks.""" +from __future__ import unicode_literals
from pywikibot import family
diff --git a/pywikibot/families/wikidata_family.py b/pywikibot/families/wikidata_family.py index 1673439..181c4c4 100644 --- a/pywikibot/families/wikidata_family.py +++ b/pywikibot/families/wikidata_family.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """Family module for Wikidata.""" +from __future__ import unicode_literals + __version__ = '$Id$'
from pywikibot import family diff --git a/pywikibot/families/wikimedia_family.py b/pywikibot/families/wikimedia_family.py index 1df7d81..b240954 100644 --- a/pywikibot/families/wikimedia_family.py +++ b/pywikibot/families/wikimedia_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Wikimedia chapter wikis.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/wikinews_family.py b/pywikibot/families/wikinews_family.py index 46f18b3..65aeb3b 100644 --- a/pywikibot/families/wikinews_family.py +++ b/pywikibot/families/wikinews_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Wikinews.""" +from __future__ import unicode_literals
from pywikibot import family
diff --git a/pywikibot/families/wikipedia_family.py b/pywikibot/families/wikipedia_family.py index 12333bb..c37f4a6 100644 --- a/pywikibot/families/wikipedia_family.py +++ b/pywikibot/families/wikipedia_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Wikipedia.""" +from __future__ import unicode_literals
from pywikibot import family
diff --git a/pywikibot/families/wikiquote_family.py b/pywikibot/families/wikiquote_family.py index 52dfffb..e7a5d76 100644 --- a/pywikibot/families/wikiquote_family.py +++ b/pywikibot/families/wikiquote_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Wikiquote.""" +from __future__ import unicode_literals
from pywikibot import family
diff --git a/pywikibot/families/wikisource_family.py b/pywikibot/families/wikisource_family.py index 2abbaaa..3b8a9fa 100644 --- a/pywikibot/families/wikisource_family.py +++ b/pywikibot/families/wikisource_family.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """Family module for Wikisource.""" +from __future__ import unicode_literals + from pywikibot import family
__version__ = '$Id$' diff --git a/pywikibot/families/wikitech_family.py b/pywikibot/families/wikitech_family.py index 4fd054e..5cba33c 100644 --- a/pywikibot/families/wikitech_family.py +++ b/pywikibot/families/wikitech_family.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """Family module for Wikitech.""" +from __future__ import unicode_literals + __version__ = '$Id$'
from pywikibot import family diff --git a/pywikibot/families/wikiversity_family.py b/pywikibot/families/wikiversity_family.py index f954137..3002613 100644 --- a/pywikibot/families/wikiversity_family.py +++ b/pywikibot/families/wikiversity_family.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """Family module for Wikiversity.""" +from __future__ import unicode_literals + from pywikibot import family
__version__ = '$Id$' diff --git a/pywikibot/families/wikivoyage_family.py b/pywikibot/families/wikivoyage_family.py index 33fb2ca..323247c 100644 --- a/pywikibot/families/wikivoyage_family.py +++ b/pywikibot/families/wikivoyage_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Wikivoyage.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/families/wiktionary_family.py b/pywikibot/families/wiktionary_family.py index 374dc0a..4e84155 100644 --- a/pywikibot/families/wiktionary_family.py +++ b/pywikibot/families/wiktionary_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for Wiktionary.""" +from __future__ import unicode_literals
from pywikibot import family
diff --git a/pywikibot/families/wowwiki_family.py b/pywikibot/families/wowwiki_family.py index 6dec001..b675001 100644 --- a/pywikibot/families/wowwiki_family.py +++ b/pywikibot/families/wowwiki_family.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Family module for WOW Wiki.""" +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/pywikibot/family.py b/pywikibot/family.py index 01a6ac7..cee0a29 100644 --- a/pywikibot/family.py +++ b/pywikibot/family.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/pywikibot/fixes.py b/pywikibot/fixes.py index 3261004..d84788c 100644 --- a/pywikibot/fixes.py +++ b/pywikibot/fixes.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
parameter_help = u""" diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py index 10f01c9..2fff519 100644 --- a/pywikibot/i18n.py +++ b/pywikibot/i18n.py @@ -21,6 +21,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
@@ -73,7 +75,8 @@ # directories before loading the python file. try: warnings.simplefilter("ignore", ImportWarning) - module = __import__(_messages_package_name, fromlist=['pywikibot']) + # it's explicitly using str() to bypass unicode_literals in Python 2 + module = __import__(_messages_package_name, fromlist=[str('pywikibot')]) except ImportError: _messages_available = False return False @@ -308,8 +311,9 @@ # directories before loading the python file. warnings.simplefilter("ignore", ImportWarning) try: + # it's explicitly using str() to bypass unicode_literals in Python 2 transdict = getattr(__import__(_messages_package_name, - fromlist=[name]), + fromlist=[str(name)]), name).msg except ImportError as e: exception_message = str(e) diff --git a/pywikibot/interwiki_graph.py b/pywikibot/interwiki_graph.py index b89f3dc..68a95c7 100644 --- a/pywikibot/interwiki_graph.py +++ b/pywikibot/interwiki_graph.py @@ -4,6 +4,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py index 1a8a9bb..c4919cb 100644 --- a/pywikibot/logentries.py +++ b/pywikibot/logentries.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/pywikibot/login.py b/pywikibot/login.py index 22a28b8..c0cc049 100644 --- a/pywikibot/login.py +++ b/pywikibot/login.py @@ -7,6 +7,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' # import codecs diff --git a/pywikibot/page.py b/pywikibot/page.py index 25b0892..0546585 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -14,6 +14,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
@@ -271,8 +273,8 @@
def __repr__(self): """Return a more complete string representation.""" - return "%s(%s)" % (self.__class__.__name__, - self.title().encode(config.console_encoding)) + title = self.title().encode(config.console_encoding).decode('unicode-escape') + return '{0}({1})'.format(self.__class__.__name__, title)
def _cmpkey(self): """ @@ -4145,7 +4147,7 @@ @rtype: bool """ if (isinstance(self.target, pywikibot.ItemPage) and - isinstance(value, str) and + isinstance(value, basestring) and self.target.id == value): return True
@@ -4155,7 +4157,7 @@ return True
if (isinstance(self.target, pywikibot.Coordinate) and - isinstance(value, str)): + isinstance(value, basestring)): coord_args = [float(x) for x in value.split(',')] if len(coord_args) >= 3: precision = coord_args[2] @@ -4859,7 +4861,7 @@ if unicodeCodepoint and unicodeCodepoint not in ignore: if unicodeCodepoint > sys.maxunicode: # solve narrow Python 2 build exception (UTF-16) - return eval(r"u'\U{:08x}'".format(unicodeCodepoint)) + return eval("'\U{:08x}'".format(unicodeCodepoint)) else: return chr(unicodeCodepoint) else: diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index f797874..a98794a 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -18,6 +18,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/pywikibot/plural.py b/pywikibot/plural.py index 02a50e4..c9edb6b 100644 --- a/pywikibot/plural.py +++ b/pywikibot/plural.py @@ -6,6 +6,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/pywikibot/site.py b/pywikibot/site.py index 73b6a2b..2df0a5c 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -10,6 +10,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index 69c67d8..410c100 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -11,6 +11,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py index a311a20..4157254 100644 --- a/pywikibot/throttle.py +++ b/pywikibot/throttle.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/pywikibot/titletranslate.py b/pywikibot/titletranslate.py index cf60b41..349c6c8 100644 --- a/pywikibot/titletranslate.py +++ b/pywikibot/titletranslate.py @@ -7,6 +7,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' # import re diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py index 051349f..b7de462 100644 --- a/pywikibot/tools/__init__.py +++ b/pywikibot/tools/__init__.py @@ -5,7 +5,7 @@ # # Distributed under the terms of the MIT license. # -from __future__ import print_function +from __future__ import print_function, unicode_literals __version__ = '$Id$'
import collections @@ -405,6 +405,26 @@ self.stop()
+def stream_encoding(stream): + """Get encoding of the stream and use a default if not existent/None.""" + try: + encoding = stream.encoding + except AttributeError: + encoding = None + return default_encoding(encoding) + + +def default_encoding(encoding): + """Return an encoding even if it's originally None.""" + if encoding is None: + if sys.platform == 'win32': + return 'cp850' + else: + return 'iso-8859-1' + else: + return encoding + + def itergroup(iterable, size): """Make an iterator that returns lists of (up to) size items from iterable.
diff --git a/pywikibot/tools/ip.py b/pywikibot/tools/ip.py index 4b11c5c..08c03a1 100644 --- a/pywikibot/tools/ip.py +++ b/pywikibot/tools/ip.py @@ -7,6 +7,8 @@ # # Note that this module _must_ not import future.unicode_literals # otherwise it will not be able to detect the defective ipaddress module. +from __future__ import unicode_literals + __version__ = '$Id$'
import re diff --git a/pywikibot/userinterfaces/__init__.py b/pywikibot/userinterfaces/__init__.py index 120ec4e..43eceeb 100644 --- a/pywikibot/userinterfaces/__init__.py +++ b/pywikibot/userinterfaces/__init__.py @@ -5,4 +5,6 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' diff --git a/pywikibot/userinterfaces/cgi_interface.py b/pywikibot/userinterfaces/cgi_interface.py index 79572f7..42424b0 100644 --- a/pywikibot/userinterfaces/cgi_interface.py +++ b/pywikibot/userinterfaces/cgi_interface.py @@ -1,4 +1,6 @@ """CGI user interface.""" +from __future__ import unicode_literals + import sys
diff --git a/pywikibot/userinterfaces/gui.py b/pywikibot/userinterfaces/gui.py index 07a4ba5..6ca260b 100644 --- a/pywikibot/userinterfaces/gui.py +++ b/pywikibot/userinterfaces/gui.py @@ -4,6 +4,7 @@
Useful for editing the contents of an article. """ +from __future__ import unicode_literals
# # (C) Rob W.W. Hooft, 2003 diff --git a/pywikibot/userinterfaces/terminal_interface.py b/pywikibot/userinterfaces/terminal_interface.py index b0e2743..9a5fbf1 100644 --- a/pywikibot/userinterfaces/terminal_interface.py +++ b/pywikibot/userinterfaces/terminal_interface.py @@ -9,6 +9,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import sys diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py index d6b9ba2..5a4c4b9 100755 --- a/pywikibot/userinterfaces/terminal_interface_base.py +++ b/pywikibot/userinterfaces/terminal_interface_base.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import getpass diff --git a/pywikibot/userinterfaces/terminal_interface_unix.py b/pywikibot/userinterfaces/terminal_interface_unix.py index 73d577a..60d8cb2 100755 --- a/pywikibot/userinterfaces/terminal_interface_unix.py +++ b/pywikibot/userinterfaces/terminal_interface_unix.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import sys diff --git a/pywikibot/userinterfaces/terminal_interface_win32.py b/pywikibot/userinterfaces/terminal_interface_win32.py index 7c0dd98..ddef65f 100755 --- a/pywikibot/userinterfaces/terminal_interface_win32.py +++ b/pywikibot/userinterfaces/terminal_interface_win32.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import re diff --git a/pywikibot/userinterfaces/transliteration.py b/pywikibot/userinterfaces/transliteration.py index 1d8e217..efd4103 100644 --- a/pywikibot/userinterfaces/transliteration.py +++ b/pywikibot/userinterfaces/transliteration.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """Module to transliterate text.""" +from __future__ import unicode_literals + __version__ = '$Id$'
diff --git a/pywikibot/userinterfaces/win32_unicode.py b/pywikibot/userinterfaces/win32_unicode.py index b1eca21..5f7da5f 100755 --- a/pywikibot/userinterfaces/win32_unicode.py +++ b/pywikibot/userinterfaces/win32_unicode.py @@ -19,7 +19,7 @@ # Licensed under both CC-BY-SA and the MIT license. # ################################################ -from __future__ import print_function +from __future__ import print_function, unicode_literals from io import UnsupportedOperation import sys stdin = sys.stdin diff --git a/pywikibot/version.py b/pywikibot/version.py index 5063908..d790756 100644 --- a/pywikibot/version.py +++ b/pywikibot/version.py @@ -7,6 +7,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/pywikibot/weblib.py b/pywikibot/weblib.py index 8f0622d..50ff23e 100644 --- a/pywikibot/weblib.py +++ b/pywikibot/weblib.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import sys diff --git a/pywikibot/xmlreader.py b/pywikibot/xmlreader.py index bf5eee3..2b77234 100644 --- a/pywikibot/xmlreader.py +++ b/pywikibot/xmlreader.py @@ -13,6 +13,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
@@ -131,7 +133,10 @@ # assume it's an uncompressed XML file source = open(self.filename, 'rb') try: - context = iterparse(source, events=("start", "end", "start-ns")) + # iterparse's event must be a str but they are unicode with + # unicode_literals in Python 2 + context = iterparse(source, events=(str('start'), str('end'), + str('start-ns'))) self.root = None
for event, elem in context: diff --git a/scripts/add_text.py b/scripts/add_text.py index ae21071..b4b6532 100644 --- a/scripts/add_text.py +++ b/scripts/add_text.py @@ -41,6 +41,7 @@ # This is a script to add a template to the top of the pages with # category:catname # Warning! Put it in one line, otherwise it won't work correctly. +from __future__ import unicode_literals
python add_text.py -cat:catname -summary:"Bot: Adding a template" -text:"{{Something}}" -except:"{{([Tt]emplate:|)[Ss]omething" -up diff --git a/scripts/archivebot.py b/scripts/archivebot.py index 2506408..22d9af7 100644 --- a/scripts/archivebot.py +++ b/scripts/archivebot.py @@ -92,6 +92,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' # import datetime diff --git a/scripts/basic.py b/scripts/basic.py index 33d6319..b6d73be 100755 --- a/scripts/basic.py +++ b/scripts/basic.py @@ -20,6 +20,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py index a012eb4..bb416c7 100755 --- a/scripts/blockpageschecker.py +++ b/scripts/blockpageschecker.py @@ -54,6 +54,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/blockreview.py b/scripts/blockreview.py index ec8f8ea..d78c9f9 100644 --- a/scripts/blockreview.py +++ b/scripts/blockreview.py @@ -19,6 +19,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/capitalize_redirects.py b/scripts/capitalize_redirects.py index 42fe6c1..01746de 100644 --- a/scripts/capitalize_redirects.py +++ b/scripts/capitalize_redirects.py @@ -29,6 +29,8 @@ # # Automatically converted from compat branch by compat2core.py script # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/casechecker.py b/scripts/casechecker.py index 4a9a684..27be8e0 100644 --- a/scripts/casechecker.py +++ b/scripts/casechecker.py @@ -6,7 +6,7 @@ # # Distributed under the terms of the MIT license. # -from __future__ import print_function +from __future__ import print_function, unicode_literals __version__ = '$Id$'
import os diff --git a/scripts/catall.py b/scripts/catall.py index 8585c91..c70ece8 100755 --- a/scripts/catall.py +++ b/scripts/catall.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - """ This script shows the categories on each page and lets you change them.
@@ -23,6 +22,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/category.py b/scripts/category.py index 0c1a3c4..1342d45 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -108,6 +108,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py index c68c8c7..7860d67 100755 --- a/scripts/category_redirect.py +++ b/scripts/category_redirect.py @@ -20,12 +20,13 @@ Usage: category_redirect.py [options]
""" - # # (C) Pywikibot team, 2008-2014 # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' # import sys diff --git a/scripts/cfd.py b/scripts/cfd.py index 53a49aa..16d5c24 100644 --- a/scripts/cfd.py +++ b/scripts/cfd.py @@ -14,6 +14,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/checkimages.py b/scripts/checkimages.py index 9e3377d..a477953 100644 --- a/scripts/checkimages.py +++ b/scripts/checkimages.py @@ -76,7 +76,6 @@ * Add a report for the image tagged.
""" - # # (C) Kyle/Orgullomoore, 2006-2007 (newimage.py) # (C) Siebrand Mazeland, 2007-2010 @@ -85,6 +84,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/claimit.py b/scripts/claimit.py index b1a968d..099d9a2 100755 --- a/scripts/claimit.py +++ b/scripts/claimit.py @@ -54,6 +54,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py index 597b0a2..9d42220 100755 --- a/scripts/clean_sandbox.py +++ b/scripts/clean_sandbox.py @@ -45,7 +45,7 @@ # # Distributed under the terms of the MIT license. # -from __future__ import division +from __future__ import division, unicode_literals __version__ = '$Id$' #
diff --git a/scripts/commons_link.py b/scripts/commons_link.py index fae8aa5..c8ca521 100644 --- a/scripts/commons_link.py +++ b/scripts/commons_link.py @@ -29,7 +29,7 @@ # Ported by Geoffrey "GEOFBOT" Mon for Google Code-In 2013 # User:Sn1per # - +from __future__ import unicode_literals
__version__ = '$Id$'
diff --git a/scripts/commonscat.py b/scripts/commonscat.py index 957983c..75beea1 100755 --- a/scripts/commonscat.py +++ b/scripts/commonscat.py @@ -25,35 +25,30 @@ For example to go through all categories: commonscat.py -start:Category:! """ -""" -Commonscat bot: - -Take a page. Follow the interwiki's and look for the commonscat template -*Found zero templates. Done. -*Found one template. Add this template -*Found more templates. Ask the user <- still have to implement this - -TODO: -*Update interwiki's at commons -*Collect all possibilities also if local wiki already has link. -*Better support for other templates (translations) / redundant templates. -*Check mode, only check pages which already have the template -*More efficient like interwiki.py -*Possibility to update other languages in the same run -""" - -""" -Porting notes: - -*Ported from compat to core -*Replaced now-deprecated Page methods -*Fixed way of finding interlanguage links in findCommonscatLink() -*Removed unused and now possibly broken updateInterwiki() method - -Ported by Allen Guo Guoguo12@gmail.com -November 2013 -""" - +# Commonscat bot: +# +# Take a page. Follow the interwiki's and look for the commonscat template +# *Found zero templates. Done. +# *Found one template. Add this template +# *Found more templates. Ask the user <- still have to implement this +# +# TODO: +# *Update interwiki's at commons +# *Collect all possibilities also if local wiki already has link. +# *Better support for other templates (translations) / redundant templates. +# *Check mode, only check pages which already have the template +# *More efficient like interwiki.py +# *Possibility to update other languages in the same run +# +# Porting notes: +# +# *Ported from compat to core +# *Replaced now-deprecated Page methods +# *Fixed way of finding interlanguage links in findCommonscatLink() +# *Removed unused and now possibly broken updateInterwiki() method +# +# Ported by Allen Guo Guoguo12@gmail.com +# November 2013 # # (C) Multichill, 2008-2009 # (C) Xqt, 2009-2015 @@ -61,6 +56,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py index 6074ba3..22541c1 100644 --- a/scripts/coordinate_import.py +++ b/scripts/coordinate_import.py @@ -26,6 +26,8 @@ # # Distributed under the terms of MIT License. # +from __future__ import unicode_literals + __version__ = '$Id$' # import pywikibot diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py index b04acb8..14e88fb 100755 --- a/scripts/cosmetic_changes.py +++ b/scripts/cosmetic_changes.py @@ -70,6 +70,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/create_categories.py b/scripts/create_categories.py index b3d0f59..ba5ab06 100755 --- a/scripts/create_categories.py +++ b/scripts/create_categories.py @@ -28,6 +28,8 @@ to create [[Category:Cultural heritage monuments in Hensies]].
""" +from __future__ import unicode_literals + __version__ = '$Id$' # # (C) Multichill, 2011 diff --git a/scripts/data_ingestion.py b/scripts/data_ingestion.py index 1e44ece..c30669e 100755 --- a/scripts/data_ingestion.py +++ b/scripts/data_ingestion.py @@ -10,6 +10,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/delete.py b/scripts/delete.py index e6fb2f1..2b0ed2a 100644 --- a/scripts/delete.py +++ b/scripts/delete.py @@ -30,6 +30,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/disambredir.py b/scripts/disambredir.py index af697bb..e1b2db9 100644 --- a/scripts/disambredir.py +++ b/scripts/disambredir.py @@ -15,6 +15,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' # import re diff --git a/scripts/editarticle.py b/scripts/editarticle.py index 97656d9..ca7b850 100755 --- a/scripts/editarticle.py +++ b/scripts/editarticle.py @@ -27,6 +27,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/featured.py b/scripts/featured.py index b5957a6..ed6347d 100644 --- a/scripts/featured.py +++ b/scripts/featured.py @@ -61,6 +61,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py index aabbd78..6fbe7bd 100644 --- a/scripts/fixing_redirects.py +++ b/scripts/fixing_redirects.py @@ -19,6 +19,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' # import re diff --git a/scripts/flickrripper.py b/scripts/flickrripper.py index 433ee2a..38e97df 100644 --- a/scripts/flickrripper.py +++ b/scripts/flickrripper.py @@ -15,6 +15,7 @@ #**Add a nice hotcat lookalike for the adding of categories #**Filter the categories #*Upload the image +from __future__ import unicode_literals
Todo: *Check if the image is already uploaded (SHA hash) diff --git a/scripts/freebasemappingupload.py b/scripts/freebasemappingupload.py index bbacec6..5722da6 100644 --- a/scripts/freebasemappingupload.py +++ b/scripts/freebasemappingupload.py @@ -13,13 +13,14 @@ -filename: the filename to read the freebase-wikidata mappings from; default: fb2w.nt.gz """ - # # (C) Denny Vrandecic, 2013 # (C) Pywikibot team, 2013-2014 # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py index d5e0d64..c131a23 100755 --- a/scripts/harvest_template.py +++ b/scripts/harvest_template.py @@ -26,6 +26,8 @@ # # Distributed under the terms of MIT License. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/illustrate_wikidata.py b/scripts/illustrate_wikidata.py index c6c5518..cc1e4e2 100644 --- a/scripts/illustrate_wikidata.py +++ b/scripts/illustrate_wikidata.py @@ -18,6 +18,8 @@ # # Distributed under the terms of MIT License. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/image.py b/scripts/image.py index 08efc95..c66c586 100644 --- a/scripts/image.py +++ b/scripts/image.py @@ -38,6 +38,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' # import pywikibot diff --git a/scripts/imagerecat.py b/scripts/imagerecat.py index b911148..73a60b3 100644 --- a/scripts/imagerecat.py +++ b/scripts/imagerecat.py @@ -30,6 +30,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py index 94a1739..9592c60 100644 --- a/scripts/imagetransfer.py +++ b/scripts/imagetransfer.py @@ -30,6 +30,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import re diff --git a/scripts/imageuncat.py b/scripts/imageuncat.py index acc6087..e553851 100755 --- a/scripts/imageuncat.py +++ b/scripts/imageuncat.py @@ -12,6 +12,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/interwiki.py b/scripts/interwiki.py index 41b4a67..aa3d46a 100755 --- a/scripts/interwiki.py +++ b/scripts/interwiki.py @@ -342,6 +342,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/isbn.py b/scripts/isbn.py index 2d5ed9d..b9b118e 100755 --- a/scripts/isbn.py +++ b/scripts/isbn.py @@ -1,6 +1,5 @@ #!/usr/bin/python # -*- coding: utf-8 -*- - """ This script reports and fixes invalid ISBN numbers.
@@ -40,6 +39,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/listpages.py b/scripts/listpages.py index 55da78b..6c64157 100644 --- a/scripts/listpages.py +++ b/scripts/listpages.py @@ -77,6 +77,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/login.py b/scripts/login.py index 8d52556..1e87a4e 100755 --- a/scripts/login.py +++ b/scripts/login.py @@ -52,6 +52,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/lonelypages.py b/scripts/lonelypages.py index af36aa1..72b06fb 100644 --- a/scripts/lonelypages.py +++ b/scripts/lonelypages.py @@ -37,6 +37,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py index 2b84d3c..4a0d1d2 100644 --- a/scripts/maintenance/cache.py +++ b/scripts/maintenance/cache.py @@ -42,7 +42,7 @@ # # Distributed under the terms of the MIT license. # -from __future__ import print_function +from __future__ import print_function, unicode_literals __version__ = '$Id$' #
diff --git a/scripts/maintenance/compat2core.py b/scripts/maintenance/compat2core.py index 386d509..fb9ef6c 100644 --- a/scripts/maintenance/compat2core.py +++ b/scripts/maintenance/compat2core.py @@ -27,6 +27,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/maintenance/make_i18n_dict.py b/scripts/maintenance/make_i18n_dict.py index 711c3d4..c685618 100644 --- a/scripts/maintenance/make_i18n_dict.py +++ b/scripts/maintenance/make_i18n_dict.py @@ -27,6 +27,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/maintenance/wikimedia_sites.py b/scripts/maintenance/wikimedia_sites.py index 83f2080..57b7e5e 100644 --- a/scripts/maintenance/wikimedia_sites.py +++ b/scripts/maintenance/wikimedia_sites.py @@ -6,6 +6,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/makecat.py b/scripts/makecat.py index b92cbd3..e1ca9b3 100644 --- a/scripts/makecat.py +++ b/scripts/makecat.py @@ -31,12 +31,13 @@ R(emove) - remove a page that is already in the list L(ist) - show current list of pages to include or to check """ - # (C) Andre Engels, 2004 # (C) Pywikibot team, 2005-2014 # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/match_images.py b/scripts/match_images.py index 915d1be..d74b715 100644 --- a/scripts/match_images.py +++ b/scripts/match_images.py @@ -29,7 +29,7 @@ # # Distributed under the terms of the MIT license. # -from __future__ import division +from __future__ import division, unicode_literals __version__ = '$Id$'
diff --git a/scripts/misspelling.py b/scripts/misspelling.py index a18a7e4..e0d7b36 100644 --- a/scripts/misspelling.py +++ b/scripts/misspelling.py @@ -20,12 +20,13 @@ -main only check pages in the main namespace, not in the talk, wikipedia, user, etc. namespaces. """ - # (C) Daniel Herding, 2007 # (C) Pywikibot team, 2007-2014 # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/movepages.py b/scripts/movepages.py index 59edd26..300f2e0 100644 --- a/scripts/movepages.py +++ b/scripts/movepages.py @@ -38,6 +38,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/newitem.py b/scripts/newitem.py index eac1b05..fcf3873 100644 --- a/scripts/newitem.py +++ b/scripts/newitem.py @@ -24,6 +24,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/noreferences.py b/scripts/noreferences.py index ed79be3..3fa562a 100755 --- a/scripts/noreferences.py +++ b/scripts/noreferences.py @@ -38,6 +38,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py index a6df733..ac41e39 100644 --- a/scripts/nowcommons.py +++ b/scripts/nowcommons.py @@ -54,6 +54,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py index 9f28900..94cd310 100644 --- a/scripts/pagefromfile.py +++ b/scripts/pagefromfile.py @@ -53,6 +53,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/patrol.py b/scripts/patrol.py index b347c1f..540bc42 100644 --- a/scripts/patrol.py +++ b/scripts/patrol.py @@ -22,6 +22,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' import pywikibot from pywikibot import pagegenerators, Bot diff --git a/scripts/piper.py b/scripts/piper.py index b12f21f..b015a0c 100644 --- a/scripts/piper.py +++ b/scripts/piper.py @@ -33,6 +33,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/protect.py b/scripts/protect.py index c5d259a..47b5bb2 100644 --- a/scripts/protect.py +++ b/scripts/protect.py @@ -39,7 +39,6 @@ Unprotect all pages listed in text file 'unprotect.txt' without prompting. python protect.py -file:unprotect.txt -unprotect -always """ - # # Written by https://it.wikisource.org/wiki/Utente:Qualc1 # Created by modifying delete.py @@ -48,6 +47,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/redirect.py b/scripts/redirect.py index c29fa88..65ac41b 100755 --- a/scripts/redirect.py +++ b/scripts/redirect.py @@ -73,6 +73,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/reflinks.py b/scripts/reflinks.py index 70d6426..79fbbd7 100644 --- a/scripts/reflinks.py +++ b/scripts/reflinks.py @@ -41,7 +41,7 @@ # # Distributed under the terms of the MIT license. # -from __future__ import division +from __future__ import division, unicode_literals __version__ = '$Id$' #
diff --git a/scripts/replace.py b/scripts/replace.py index 5c57a4f..44f8ecb 100755 --- a/scripts/replace.py +++ b/scripts/replace.py @@ -122,6 +122,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/replicate_wiki.py b/scripts/replicate_wiki.py index 41d7a11..aef3948 100644 --- a/scripts/replicate_wiki.py +++ b/scripts/replicate_wiki.py @@ -41,6 +41,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/revertbot.py b/scripts/revertbot.py index 4f99c73..abd3fbf 100644 --- a/scripts/revertbot.py +++ b/scripts/revertbot.py @@ -21,6 +21,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/script_wui.py b/scripts/script_wui.py index fd6e792..052d721 100755 --- a/scripts/script_wui.py +++ b/scripts/script_wui.py @@ -58,6 +58,8 @@ # ... # --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/selflink.py b/scripts/selflink.py index 734cf39..bcd284c 100644 --- a/scripts/selflink.py +++ b/scripts/selflink.py @@ -1,6 +1,5 @@ #!/usr/bin/python # -*- coding: utf-8 -*- - """ This bot searches for selflinks and allows removing them.
@@ -16,6 +15,7 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals
import re import pywikibot diff --git a/scripts/shell.py b/scripts/shell.py index 0a0add6..a5de43b 100644 --- a/scripts/shell.py +++ b/scripts/shell.py @@ -17,6 +17,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py index c740a58..60d4149 100644 --- a/scripts/solve_disambiguation.py +++ b/scripts/solve_disambiguation.py @@ -75,6 +75,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/spamremove.py b/scripts/spamremove.py index 0f8303e..c728e9b 100755 --- a/scripts/spamremove.py +++ b/scripts/spamremove.py @@ -1,6 +1,5 @@ #!/usr/bin/python # -*- coding: utf-8 -*- - """ Script to remove links that are being or have been spammed.
@@ -23,12 +22,13 @@ multiple times it will search all given namespaces
""" - # # (C) Pywikibot team, 2007-2014 # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
# diff --git a/scripts/states_redirect.py b/scripts/states_redirect.py index f184df5..de8ddc8 100644 --- a/scripts/states_redirect.py +++ b/scripts/states_redirect.py @@ -1,6 +1,5 @@ #!usr/bin/python # -*- coding: utf-8 -*- - """Create country sub-division redirect pages.
Check if they are in the form Something, State, and if so, create a redirect @@ -20,6 +19,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/template.py b/scripts/template.py index 741c865..f145fdc 100755 --- a/scripts/template.py +++ b/scripts/template.py @@ -105,6 +105,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/templatecount.py b/scripts/templatecount.py index 9ca5120..5751641 100644 --- a/scripts/templatecount.py +++ b/scripts/templatecount.py @@ -36,6 +36,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import datetime diff --git a/scripts/touch.py b/scripts/touch.py index 8048a57..42d112e 100755 --- a/scripts/touch.py +++ b/scripts/touch.py @@ -1,6 +1,5 @@ #!/usr/bin/python # -*- coding: utf-8 -*- - """ This bot goes over multiple pages of a wiki, and edits them without changes.
@@ -21,6 +20,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/transferbot.py b/scripts/transferbot.py index 8b9cbcf..61dfbfd 100644 --- a/scripts/transferbot.py +++ b/scripts/transferbot.py @@ -1,6 +1,5 @@ #!/usr/bin/python # -*- coding: utf-8 -*- - """ This script transfers pages from a source wiki to a target wiki.
@@ -25,6 +24,8 @@
# Transfer all pages in category "Query service" from the Toolserver wiki to # wikitech, adding Nova_Resource:Tools/Tools/ as prefix +from __future__ import unicode_literals + transferbot.py -v -family:toolserver -tofamily:wikitech -cat:"Query service" -prefix:Nova_Resource:Tools/Tools/
# Copy the template "Query service" from the Toolserver wiki to wikitech diff --git a/scripts/unlink.py b/scripts/unlink.py index 403d626..103a9a0 100755 --- a/scripts/unlink.py +++ b/scripts/unlink.py @@ -25,6 +25,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py index 7307368..61957a1 100644 --- a/scripts/unusedfiles.py +++ b/scripts/unusedfiles.py @@ -8,7 +8,6 @@ -always Don't be asked every time.
""" - # # (C) Leonardo Gregianin, 2007 # (C) Filnik, 2008 @@ -17,6 +16,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/upload.py b/scripts/upload.py index 5afd564..0412b9b 100755 --- a/scripts/upload.py +++ b/scripts/upload.py @@ -37,6 +37,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/version.py b/scripts/version.py index fb43be1..17d0b4b 100755 --- a/scripts/version.py +++ b/scripts/version.py @@ -8,6 +8,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/watchlist.py b/scripts/watchlist.py index 9873992..447858a 100755 --- a/scripts/watchlist.py +++ b/scripts/watchlist.py @@ -21,6 +21,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py index 968d763..9faf7f9 100644 --- a/scripts/weblinkchecker.py +++ b/scripts/weblinkchecker.py @@ -88,13 +88,14 @@ python weblinkchecker.py -repeat Loads all wiki pages where dead links were found during a prior run """ - # # (C) Daniel Herding, 2005 # (C) Pywikibot team, 2005-2014 # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import re diff --git a/scripts/welcome.py b/scripts/welcome.py index ed327cf..16403be 100644 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -177,6 +177,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/tests/__init__.py b/tests/__init__.py index 96672a4..031b90d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import os diff --git a/tests/api_tests.py b/tests/api_tests.py index d827f9c..ad44b6b 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import datetime diff --git a/tests/archivebot_tests.py b/tests/archivebot_tests.py index 5c57d54..4379c96 100644 --- a/tests/archivebot_tests.py +++ b/tests/archivebot_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
from datetime import datetime diff --git a/tests/aspects.py b/tests/aspects.py index c6ff682..1fb1728 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -11,7 +11,7 @@ # # Distributed under the terms of the MIT license. # -from __future__ import print_function +from __future__ import print_function, unicode_literals __version__ = '$Id$' """ TODO: diff --git a/tests/cache_tests.py b/tests/cache_tests.py index 020dd1e..b5e6fed 100644 --- a/tests/cache_tests.py +++ b/tests/cache_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/tests/category_tests.py b/tests/category_tests.py index d9d543c..df7fc19 100644 --- a/tests/category_tests.py +++ b/tests/category_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import pywikibot diff --git a/tests/checkimages_tests.py b/tests/checkimages_tests.py index 4c0b10e..f033a88 100644 --- a/tests/checkimages_tests.py +++ b/tests/checkimages_tests.py @@ -1,6 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- """Unit tests for checkimages script.""" +from __future__ import unicode_literals
from scripts import checkimages
diff --git a/tests/data_ingestion_tests.py b/tests/data_ingestion_tests.py index 909889c..8a26978 100644 --- a/tests/data_ingestion_tests.py +++ b/tests/data_ingestion_tests.py @@ -1,7 +1,8 @@ #!/usr/bin/python # -*- coding: utf-8 -*- - """Unit tests for data_ingestion.py script.""" +from __future__ import unicode_literals + __version__ = '$Id$'
import os diff --git a/tests/date_tests.py b/tests/date_tests.py index c7058ed..178da8f 100644 --- a/tests/date_tests.py +++ b/tests/date_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + from datetime import datetime
from pywikibot import date @@ -45,7 +47,8 @@ return testMapEntry
for formatname in date.formats: - test_name = "test_" + formatname + # it's explicitly using str() because __name__ must be str + test_name = str('test_' + formatname) dct[test_name] = test_method(formatname) dct[test_name].__name__ = test_name return type.__new__(cls, name, bases, dct) diff --git a/tests/deletionbot_tests.py b/tests/deletionbot_tests.py index 1a8d5ed..c1050df 100644 --- a/tests/deletionbot_tests.py +++ b/tests/deletionbot_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import pywikibot diff --git a/tests/deprecation_tests.py b/tests/deprecation_tests.py index 699ffcb..eccac70 100644 --- a/tests/deprecation_tests.py +++ b/tests/deprecation_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
from pywikibot.tools import ( diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py index f895be7..82d35af 100644 --- a/tests/dry_api_tests.py +++ b/tests/dry_api_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/tests/dry_site_tests.py b/tests/dry_site_tests.py index 3efa3f3..4e28476 100644 --- a/tests/dry_site_tests.py +++ b/tests/dry_site_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/tests/edit_failure_tests.py b/tests/edit_failure_tests.py index a13c330..01b163d 100644 --- a/tests/edit_failure_tests.py +++ b/tests/edit_failure_tests.py @@ -12,6 +12,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import pywikibot diff --git a/tests/exceptions_tests.py b/tests/exceptions_tests.py index 9f3e250..9fa8041 100644 --- a/tests/exceptions_tests.py +++ b/tests/exceptions_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import pywikibot diff --git a/tests/family_tests.py b/tests/family_tests.py index d32a3c4..24e9c95 100644 --- a/tests/family_tests.py +++ b/tests/family_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
from pywikibot.family import Family diff --git a/tests/file_tests.py b/tests/file_tests.py index 8fa1de5..625df91 100644 --- a/tests/file_tests.py +++ b/tests/file_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import pywikibot diff --git a/tests/http_tests.py b/tests/http_tests.py index ff8337c..3453d4b 100644 --- a/tests/http_tests.py +++ b/tests/http_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import os diff --git a/tests/i18n/pywikibot.py b/tests/i18n/pywikibot.py index a8650f3..f0c1382 100644 --- a/tests/i18n/pywikibot.py +++ b/tests/i18n/pywikibot.py @@ -1,3 +1,5 @@ # -*- coding: utf-8 -*- """i18n message bundle called 'pywikibot' to fool the i18n loader.""" +from __future__ import unicode_literals + msg = {} diff --git a/tests/i18n/test.py b/tests/i18n/test.py index 44afee0..315224a 100644 --- a/tests/i18n/test.py +++ b/tests/i18n/test.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """Test i18n data.""" +from __future__ import unicode_literals + msg = { 'de': { 'test-plural': u'Bot: Ändere %(num)d {{PLURAL:num|Seite|Seiten}}.', diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py index 5c05011..c116abb 100644 --- a/tests/i18n_tests.py +++ b/tests/i18n_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import sys diff --git a/tests/interwiki_link_tests.py b/tests/interwiki_link_tests.py index d5b44fb..0ddee67 100644 --- a/tests/interwiki_link_tests.py +++ b/tests/interwiki_link_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
from pywikibot import config2 as config diff --git a/tests/ipregex_tests.py b/tests/ipregex_tests.py index 098fdc7..7553684 100644 --- a/tests/ipregex_tests.py +++ b/tests/ipregex_tests.py @@ -5,6 +5,8 @@ # (C) Pywikibot team, 2014 # # Distributed under the terms of the MIT license. +from __future__ import unicode_literals + __version__ = '$Id$'
from pywikibot.tools import ip diff --git a/tests/isbn_tests.py b/tests/isbn_tests.py index 26ec753..b871903 100644 --- a/tests/isbn_tests.py +++ b/tests/isbn_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + import pywikibot
__version__ = '$Id$' diff --git a/tests/l10n_tests.py b/tests/l10n_tests.py index d3dc417..2dbe1c8 100644 --- a/tests/l10n_tests.py +++ b/tests/l10n_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import re diff --git a/tests/link_tests.py b/tests/link_tests.py index ab80d0d..461dc88 100644 --- a/tests/link_tests.py +++ b/tests/link_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import pywikibot diff --git a/tests/mediawikiversion_tests.py b/tests/mediawikiversion_tests.py index 17bd115..125a257 100644 --- a/tests/mediawikiversion_tests.py +++ b/tests/mediawikiversion_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
diff --git a/tests/namespace_tests.py b/tests/namespace_tests.py index 4b497f2..6f18a73 100644 --- a/tests/namespace_tests.py +++ b/tests/namespace_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
from collections import Iterable @@ -203,14 +205,14 @@
a.defaultcontentmodel = 'bar' s = repr(a) - r = "Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[], defaultcontentmodel='bar')" \ - % (unicode('Foo'), unicode('Foo')) + r = "Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[], defaultcontentmodel=%r)" \ + % (unicode('Foo'), unicode('Foo'), unicode('bar')) self.assertEqual(s, r)
a.case = 'upper' s = repr(a) - r = "Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[], case='upper', defaultcontentmodel='bar')" \ - % (unicode('Foo'), unicode('Foo')) + r = "Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[], case=%r, defaultcontentmodel=%r)" \ + % (unicode('Foo'), unicode('Foo'), unicode('upper'), unicode('bar')) self.assertEqual(s, r)
b = eval(repr(a)) diff --git a/tests/page_tests.py b/tests/page_tests.py index d170cab..44b1d42 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import sys diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index 35e6320..d504e25 100755 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -5,6 +5,8 @@ # (C) Pywikibot team, 2014 # # Distributed under the terms of the MIT license. +from __future__ import unicode_literals + __version__ = '$Id$'
import datetime diff --git a/tests/protectbot_tests.py b/tests/protectbot_tests.py index df7d56b..260ac6a 100644 --- a/tests/protectbot_tests.py +++ b/tests/protectbot_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import pywikibot diff --git a/tests/pwb/print_locals.py b/tests/pwb/print_locals.py index 42749df..c39b776 100644 --- a/tests/pwb/print_locals.py +++ b/tests/pwb/print_locals.py @@ -1,4 +1,5 @@ """Script that forms part of pwb_tests.""" +from __future__ import unicode_literals
import os.path
diff --git a/tests/pwb_tests.py b/tests/pwb_tests.py index e4c0285..fe52837 100644 --- a/tests/pwb_tests.py +++ b/tests/pwb_tests.py @@ -11,6 +11,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import os diff --git a/tests/reflinks_tests.py b/tests/reflinks_tests.py index 042c29f..fec7c44 100644 --- a/tests/reflinks_tests.py +++ b/tests/reflinks_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import os diff --git a/tests/script_tests.py b/tests/script_tests.py index fb47dea..dd44df3 100644 --- a/tests/script_tests.py +++ b/tests/script_tests.py @@ -5,7 +5,7 @@ # # Distributed under the terms of the MIT license. # -from __future__ import print_function +from __future__ import print_function, unicode_literals __version__ = '$Id$'
import os @@ -306,6 +306,8 @@ test_name = 'test__' + script_name + '_help' else: test_name = 'test_' + script_name + '_help' + # it's explicitly using str() because __name__ must be str + test_name = str(test_name) dct[test_name] = test_execution(script_name, ['-help']) if script_name in ['version', 'script_wui', # Failing on travis-ci @@ -326,6 +328,8 @@ test_name = 'test__' + script_name + '_simulate' else: test_name = 'test_' + script_name + '_simulate' + # it's explicitly using str() because __name__ must be str + test_name = str(test_name) dct[test_name] = test_execution(script_name, ['-simulate'], no_args_expected_results) if script_name in ['catall', # stdout user interaction diff --git a/tests/site_tests.py b/tests/site_tests.py index 23ad897..274c282 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
diff --git a/tests/tests_tests.py b/tests/tests_tests.py index 6ac9c69..c95c57d 100755 --- a/tests/tests_tests.py +++ b/tests/tests_tests.py @@ -5,6 +5,8 @@ # (C) Pywikibot team, 2014 # # Distributed under the terms of the MIT license. +from __future__ import unicode_literals + __version__ = '$Id$'
import pywikibot diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py index 3d9c2a3..6baae06 100644 --- a/tests/textlib_tests.py +++ b/tests/textlib_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import codecs diff --git a/tests/thread_tests.py b/tests/thread_tests.py index 581aab0..326a606 100644 --- a/tests/thread_tests.py +++ b/tests/thread_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
from tests.aspects import unittest, TestCase diff --git a/tests/timestamp_tests.py b/tests/timestamp_tests.py index 362247b..1b449d4 100644 --- a/tests/timestamp_tests.py +++ b/tests/timestamp_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import calendar diff --git a/tests/timestripper_tests.py b/tests/timestripper_tests.py index 54af2a0..3573bb9 100644 --- a/tests/timestripper_tests.py +++ b/tests/timestripper_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import datetime diff --git a/tests/tk_tests.py b/tests/tk_tests.py index efa21a9..8fc10af 100644 --- a/tests/tk_tests.py +++ b/tests/tk_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
diff --git a/tests/ui_tests.py b/tests/ui_tests.py index 087a230..20e8204 100644 --- a/tests/ui_tests.py +++ b/tests/ui_tests.py @@ -5,7 +5,6 @@ # # Distributed under the terms of the MIT license. # - # NOTE FOR RUNNING WINDOWS UI TESTS # # Windows UI tests have to be run using the tests\ui_tests.bat helper script. @@ -25,6 +24,8 @@ # easy_install --upgrade https://pywinauto.googlecode.com/files/pywinauto-0.4.2.zip # # +from __future__ import unicode_literals + __version__ = '$Id$'
import logging @@ -138,6 +139,19 @@ newstderr = strerr._stream newstdin = strin._stream
+if sys.version_info[0] == 2: + # In Python 2 the sys.std* streams use bytes instead of unicode + # But this module is using unicode_literals so '…' will generate unicode + # So it'll convert those back into bytes + original_write = newstdin.write + + def encoded_write(text): + if isinstance(text, unicode): + text = text.encode('utf8') + original_write(text) + + newstdin.write = encoded_write + org_print = ui._print org_input = ui._raw_input
diff --git a/tests/upload_tests.py b/tests/upload_tests.py index 628362b..4d1b1ea 100644 --- a/tests/upload_tests.py +++ b/tests/upload_tests.py @@ -9,6 +9,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import os diff --git a/tests/uploadbot_tests.py b/tests/uploadbot_tests.py index a84667c..b7e2de2 100644 --- a/tests/uploadbot_tests.py +++ b/tests/uploadbot_tests.py @@ -9,6 +9,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/tests/utils.py b/tests/utils.py index ae80633..99c0957 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -5,7 +5,7 @@ # # Distributed under the terms of the MIT license. # -from __future__ import print_function +from __future__ import print_function, unicode_literals __version__ = '$Id$' # import os @@ -16,7 +16,7 @@ from warnings import warn
import pywikibot -from pywikibot.tools import SelfCallDict +from pywikibot.tools import SelfCallDict, stream_encoding from pywikibot.site import Namespace from pywikibot.data.api import CachedRequest from pywikibot.data.api import Request as _original_Request @@ -258,11 +258,6 @@ @param command: executable to run and arguments to use @type command: list of unicode """ - def decode(stream): - if sys.version_info[0] > 2: - return stream.decode(pywikibot.config.console_encoding) - else: - return stream env = os.environ.copy() # sys.path may have been modified by the test runner to load dependencies. env['PYTHONPATH'] = ":".join(sys.path) @@ -283,10 +278,12 @@
p = subprocess.Popen(command, env=env, **options)
+ stdin_encoding = stream_encoding(p.stdin) + stdout_encoding = stream_encoding(p.stdout) + stderr_encoding = stream_encoding(p.stderr) + if data_in is not None: - if sys.version_info[0] > 2: - data_in = data_in.encode(pywikibot.config.console_encoding) - p.stdin.write(data_in) + p.stdin.write(data_in.encode(stdin_encoding)) p.stdin.flush() # _communicate() otherwise has a broken pipe
stderr_lines = b'' @@ -299,7 +296,7 @@ if error: line = p.stderr.readline() stderr_lines += line - if error in decode(line): + if error in line.decode(stdout_encoding): break time.sleep(1) waited += 1 @@ -312,8 +309,8 @@
data_out = p.communicate() return {'exit_code': p.returncode, - 'stdout': decode(data_out[0]), - 'stderr': decode(stderr_lines + data_out[1])} + 'stdout': data_out[0].decode(stdout_encoding), + 'stderr': (stderr_lines + data_out[1]).decode(stderr_encoding)}
def execute_pwb(args, data_in=None, timeout=0, error=None): diff --git a/tests/weblib_tests.py b/tests/weblib_tests.py index 84f445f..d05c853 100644 --- a/tests/weblib_tests.py +++ b/tests/weblib_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import sys diff --git a/tests/wikibase_edit_tests.py b/tests/wikibase_edit_tests.py index 9094e53..84dc056 100644 --- a/tests/wikibase_edit_tests.py +++ b/tests/wikibase_edit_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py index f3bf135..5a37136 100644 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/tests/wikidataquery_tests.py b/tests/wikidataquery_tests.py index 04266c5..6254126 100644 --- a/tests/wikidataquery_tests.py +++ b/tests/wikidataquery_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/tests/wikistats_tests.py b/tests/wikistats_tests.py index deda834..6a2dca0 100644 --- a/tests/wikistats_tests.py +++ b/tests/wikistats_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$' #
diff --git a/tests/xmlreader_tests.py b/tests/xmlreader_tests.py index 85dbbe8..bee3cb5 100644 --- a/tests/xmlreader_tests.py +++ b/tests/xmlreader_tests.py @@ -5,6 +5,8 @@ # # Distributed under the terms of the MIT license. # +from __future__ import unicode_literals + __version__ = '$Id$'
import os.path