XZise has uploaded a new change for review.
https://gerrit.wikimedia.org/r/198203
Change subject: [FIX] Format Unicode strings if required
......................................................................
[FIX] Format Unicode strings if required
The format method of str does not change the type to unicode if
non-ASCII characters are added using it. This is changing strings to
unicode when it's possible that non-ASCII characters may be added to it.
Change-Id: I22951d410084bce67744e78a0d25949e34ea133c
---
M generate_user_files.py
M pywikibot/__init__.py
M pywikibot/bot.py
M pywikibot/comms/threadedhttp.py
M pywikibot/data/api.py
M pywikibot/editor.py
M pywikibot/family.py
M pywikibot/page.py
M pywikibot/pagegenerators.py
M pywikibot/site.py
M pywikibot/tools/__init__.py
M scripts/cosmetic_changes.py
M scripts/protect.py
M scripts/replace.py
M scripts/version.py
M tests/page_tests.py
M tests/site_tests.py
17 files changed, 56 insertions(+), 56 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/03/198203/1
diff --git a/generate_user_files.py b/generate_user_files.py
index 825f948..4925c6e 100644
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -179,7 +179,7 @@
username = None
message = u"Username on {0}:{1}".format(mylang, fam.name)
if default_username:
- message += " (default: '{0}')".format(default_username)
+ message += u" (default: '{0}')".format(default_username)
message += ":"
while not username:
username = pywikibot.input(message) or default_username
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index d4b3081..4894cd4 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -558,7 +558,7 @@
code = cached[0]
fam = cached[1]
else:
- raise Error("Unknown URL '{0}'.".format(url))
+ raise Error(u"Unknown URL '{0}'.".format(url))
else:
# Iterate through all families and look, which does apply to
# the given URL
@@ -572,7 +572,7 @@
_url_cache[url] = None
# TODO: As soon as AutoFamily is ready, try and use an
# AutoFamily
- raise Error("Unknown URL '{0}'.".format(url))
+ raise Error(u"Unknown URL '{0}'.".format(url))
else:
# Fallback to config defaults
code = code or config.mylang
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index be83074..124d509 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1259,7 +1259,7 @@
def treat(self, page):
"""Treat page if it exists and handle NoPage from it."""
if not page.exists():
- pywikibot.warning('Page "{0}" does not exist on {1}.'.format(
+ pywikibot.warning(u'Page "{0}" does not exist on {1}.'.format(
page.title(), page.site))
return
try:
@@ -1268,8 +1268,8 @@
if e.page != page:
raise
pywikibot.warning(
- 'During handling of page "{0}" on {1} a NoPage exception was '
- 'raised.'.format(page.title(), page.site))
+ u'During handling of page "{0}" on {1} a NoPage exception was '
+ u'raised.'.format(page.title(), page.site))
class FollowRedirectPageBot(CurrentPageBot):
@@ -1290,7 +1290,7 @@
def treat(self, page):
"""Treat page if doesn't exist."""
if page.exists():
- pywikibot.warning('Page "{0}" does already exist on {1}.'.format(
+ pywikibot.warning(u'Page "{0}" does already exist on {1}.'.format(
page.title(), page.site))
return
super(CreatingPageBot, self).treat(page)
@@ -1303,8 +1303,8 @@
def treat(self, page):
"""Treat only redirect pages and handle IsNotRedirectPage from it."""
if not page.isRedirectPage():
- pywikibot.warning('Page "{0}" on {1} is skipped because it is not '
- 'a redirect'.format(page.title(), page.site))
+ pywikibot.warning(u'Page "{0}" on {1} is skipped because it is not
'
+ u'a redirect'.format(page.title(), page.site))
return
try:
super(RedirectPageBot, self).treat(page)
@@ -1312,8 +1312,8 @@
if e.page != page:
raise
pywikibot.warning(
- 'During handling of page "{0}" on {1} a IsNotRedirectPage '
- 'exception was raised.'.format(page.title(), page.site))
+ u'During handling of page "{0}" on {1} a IsNotRedirectPage '
+ u'exception was raised.'.format(page.title(), page.site))
class NoRedirectPageBot(CurrentPageBot):
@@ -1323,8 +1323,8 @@
def treat(self, page):
"""Treat only non-redirect pages and handle IsRedirectPage from it."""
if page.isRedirectPage():
- pywikibot.warning('Page "{0}" on {1} is skipped because it is a '
- 'redirect'.format(page.title(), page.site))
+ pywikibot.warning(u'Page "{0}" on {1} is skipped because it is a '
+ u'redirect'.format(page.title(), page.site))
return
try:
super(NoRedirectPageBot, self).treat(page)
@@ -1332,8 +1332,8 @@
if e.page != page:
raise
pywikibot.warning(
- 'During handling of page "{0}" on {1} a IsRedirectPage '
- 'exception was raised.'.format(page.title(), page.site))
+ u'During handling of page "{0}" on {1} a IsRedirectPage '
+ u'exception was raised.'.format(page.title(), page.site))
class WikidataBot(Bot):
@@ -1475,8 +1475,8 @@
item = pywikibot.ItemPage(data_site, page.title())
item.get()
elif self.use_from_page is False:
- pywikibot.error('{0} is not in the item namespace but '
- 'must be an item.'.format(page))
+ pywikibot.error(u'{0} is not in the item namespace but '
+ u'must be an item.'.format(page))
continue
else:
try:
diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py
index e3c0e64..a98e6f5 100644
--- a/pywikibot/comms/threadedhttp.py
+++ b/pywikibot/comms/threadedhttp.py
@@ -456,7 +456,7 @@
(codecs.lookup(charset) if charset else None)):
if charset:
pywikibot.warning(u'Encoding "{0}" requested but "{1}" '
- 'received in the header.'.format(
+ u'received in the header.'.format(
charset, self.header_encoding))
try:
# TODO: Buffer decoded content, weakref does remove it too
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 9a9c030..8ef9137 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -99,7 +99,7 @@
def __repr__(self):
"""Return internal representation."""
- return '{name}("{code}", "{info}", {other})'.format(
+ return u'{name}("{code}", "{info}", {other})'.format(
name=self.__class__.__name__, **self.__dict__)
def __str__(self):
@@ -406,7 +406,7 @@
elif php_class == 'ApiPageSet':
name = 'pageset'
else:
- pywikibot.warning('Unknown paraminfo module
"{0}"'.format(
+ pywikibot.warning(u'Unknown paraminfo module
"{0}"'.format(
php_class))
name = '<unknown>:' + php_class
@@ -1879,7 +1879,7 @@
param = self.site._paraminfo.parameter(self.limited_module,
'namespace')
if not param:
pywikibot.warning(u'{0} module does not support a namespace '
- 'parameter'.format(self.limited_module))
+ u'parameter'.format(self.limited_module))
return
if isinstance(namespaces, basestring):
diff --git a/pywikibot/editor.py b/pywikibot/editor.py
index 7d1687d..94a951c 100644
--- a/pywikibot/editor.py
+++ b/pywikibot/editor.py
@@ -68,8 +68,8 @@
@staticmethod
def _concat(command):
- return ' '.join("'{0}'".format(part) if ' ' in part else part
- for part in command)
+ return u' '.join(u"'{0}'".format(part) if ' ' in part else part
+ for part in command)
@deprecated('_command (should not be used from the outside)')
def command(self, tempFilename, text, jumpIndex=None):
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 01a6ac7..167154b 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -1064,7 +1064,7 @@
uri = self.ssl_pathprefix(code) + uri
else:
host = self.hostname(code)
- return urlparse.urljoin('{0}://{1}'.format(protocol, host), uri)
+ return urlparse.urljoin(u'{0}://{1}'.format(protocol, host), uri)
def path(self, code):
return '%s/index.php' % self.scriptpath(code)
@@ -1108,10 +1108,10 @@
if len(self.langs) == 1:
return _get_coded_path_regex(next(iter(self.langs.keys())))
else:
- raise Error('Pywikibot is unable to generate an automatic '
- 'path regex for the family {0}. It is recommended '
- 'to overwrite "_get_path_regex" in that '
- 'family.'.format(self.name))
+ raise Error(u'Pywikibot is unable to generate an automatic '
+ u'path regex for the family {0}. It is recommended
'
+ u'to overwrite "_get_path_regex" in that '
+ u'family.'.format(self.name))
def from_url(self, url):
"""
@@ -1129,7 +1129,7 @@
@rtype: str or None
"""
url_match = re.match(r'(?:(https?)://|//)?(.*){0}'
- '\$1'.format(self._get_path_regex()), url)
+ r'\$1'.format(self._get_path_regex()), url)
if not url_match:
return None
for code, domain in self.langs.items():
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 5607ace..f5ef879 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1407,8 +1407,8 @@
result += '! oldid || date/time || username || edit summary\n'
for entry in self.revisions(reverse=reverse, step=step, total=total):
result += '|----\n'
- result += ('| {r.revid} || {r.timestamp} || {r.user} || '
- '<nowiki>{r.comment}</nowiki>\n'.format(r=entry))
+ result += (u'| {r.revid} || {r.timestamp} || {r.user} || '
+ u'<nowiki>{r.comment}</nowiki>\n'.format(r=entry))
result += '|}\n'
return result
@@ -4494,7 +4494,7 @@
except SiteDefinitionError:
raise SiteDefinitionError(
u'{0} is not a local page on {1}, and the interwiki prefix
'
- '{2} is not supported by PyWikiBot!'.format(
+ u'{2} is not supported by PyWikiBot!'.format(
self._text, self._site, prefix))
else:
t = t[t.index(u":"):].lstrip(u":").lstrip(u" ")
@@ -4502,7 +4502,7 @@
if not self._site.local_interwiki(prefix):
raise pywikibot.InvalidTitle(
u'{0} links to a non local site {1} via an '
- 'interwiki link to {2}.'.format(
+ u'interwiki link to {2}.'.format(
self._text, newsite, first_other_site))
elif newsite != self._source:
first_other_site = newsite
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index b01ae3f..855d0e4 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -449,7 +449,7 @@
raise ValueError
except ValueError:
pywikibot.error(u'Total number of log ({0}) events must be a '
- 'positive int.'.format(total))
+ u'positive int.'.format(total))
return None
# 'user or None', because user might be an empty string when
# 'foo,,bar' was used.
diff --git a/pywikibot/site.py b/pywikibot/site.py
index fdecbe0..e1cadca 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -2755,8 +2755,8 @@
def getToken(self, getalways=True, getagain=False, sysop=False):
"""DEPRECATED: Get edit token."""
if self.username(sysop) != self.user():
- raise ValueError('The token for {0} was requested but only the '
- 'token for {1} can be retrieved.'.format(
+ raise ValueError(u'The token for {0} was requested but only the '
+ u'token for {1} can be retrieved.'.format(
self.username(sysop), self.user()))
if not getalways:
raise ValueError('In pywikibot/core getToken does not support the '
@@ -2771,8 +2771,8 @@
def getPatrolToken(self, sysop=False):
"""DEPRECATED: Get patrol token."""
if self.username(sysop) != self.user():
- raise ValueError('The token for {0} was requested but only the '
- 'token for {1} can be retrieved.'.format(
+ raise ValueError(u'The token for {0} was requested but only the '
+ u'token for {1} can be retrieved.'.format(
self.username(sysop), self.user()))
return self.tokens['patrol']
@@ -4119,7 +4119,7 @@
if MediaWikiVersion(self.version()) < MediaWikiVersion("1.16"):
if watch in ['preferences', 'nochange']:
pywikibot.warning(u'The watch value {0} is not supported '
- 'by {1}'.format(watch, self))
+ u'by {1}'.format(watch, self))
else:
params[watch] = True
else:
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 051349f..3b87c40 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -276,7 +276,7 @@
"""Parse version string."""
version_match = MediaWikiVersion.MEDIAWIKI_VERSION.match(vstring)
if not version_match:
- raise ValueError('Invalid version number "{0}"'.format(vstring))
+ raise ValueError(u'Invalid version number "{0}"'.format(vstring))
components = [int(n) for n in version_match.group(1).split('.')]
# The _dev_version numbering scheme might change. E.g. if a stage
# between 'alpha' and 'beta' is added, 'beta', 'rc' and stable releases
@@ -511,8 +511,8 @@
# If any generator is empty, no pages are going to be returned
for source in genlist:
if not source:
- debug('At least one generator ({0!r}) is empty and execution was '
- 'skipped immediately.'.format(source), 'intersect')
+ debug(u'At least one generator ({0!r}) is empty and execution was '
+ u'skipped immediately.'.format(source), 'intersect')
return
# Item is cached to check that it is found n_gen
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py
index 8012326..ead6f98 100755
--- a/scripts/cosmetic_changes.py
+++ b/scripts/cosmetic_changes.py
@@ -960,7 +960,7 @@
elif ignore_mode == 'page':
options['ignore'] = CANCEL_PAGE
else:
- raise ValueError('Unknown ignore mode
"{0}"!'.format(ignore_mode))
+ raise ValueError(u'Unknown ignore mode
"{0}"!'.format(ignore_mode))
else:
genFactory.handleArg(arg)
diff --git a/scripts/protect.py b/scripts/protect.py
index c5d259a..46a63d7 100644
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -198,7 +198,7 @@
is_p_type = True
if not is_p_type:
if not genFactory.handleArg(arg):
- raise ValueError('Unknown parameter "{0}"'.format(arg))
+ raise ValueError(u'Unknown parameter "{0}"'.format(arg))
found = arg.find(':')
if found:
message_properties.update({'cat': arg[found + 1:],
diff --git a/scripts/replace.py b/scripts/replace.py
index 5c57a4f..889b7f6 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -439,8 +439,8 @@
for i, replacement in enumerate(replacements):
if isinstance(replacement, collections.Sequence):
if len(replacement) != 2:
- raise ValueError('Replacement number {0} does not have '
- 'exactly two elements: {1}'.format(
+ raise ValueError(u'Replacement number {0} does not have '
+ u'exactly two elements: {1}'.format(
i, replacement))
# Replacement assumes it gets strings but it's already compiled
replacements[i] = Replacement.from_compiled(replacement[0],
diff --git a/scripts/version.py b/scripts/version.py
index fb43be1..c2af6fb 100755
--- a/scripts/version.py
+++ b/scripts/version.py
@@ -22,7 +22,7 @@
def check_environ(environ_name):
- pywikibot.output('{0}: {1}'.format(environ_name,
os.environ.get(environ_name, 'Not set')))
+ pywikibot.output(u'{0}: {1}'.format(environ_name,
os.environ.get(environ_name, 'Not set')))
if __name__ == '__main__':
@@ -50,14 +50,14 @@
check_environ('PYWIKIBOT2_DIR')
check_environ('PYWIKIBOT2_DIR_PWB')
check_environ('PYWIKIBOT2_NO_USER_CONFIG')
- pywikibot.output('Config base dir: {0}'.format(pywikibot.config2.base_dir))
+ pywikibot.output(u'Config base dir:
{0}'.format(pywikibot.config2.base_dir))
for family, usernames in pywikibot.config2.usernames.items():
if usernames:
- pywikibot.output('Usernames for family "{0}":'.format(family))
+ pywikibot.output(u'Usernames for family "{0}":'.format(family))
for lang, username in usernames.items():
sysop_name = pywikibot.config2.sysopnames.get(family,
{}).get(lang)
if not sysop_name:
sysop_name = 'no sysop configured'
elif sysop_name == username:
sysop_name = 'also sysop'
- pywikibot.output('\t{0}: {1} ({2})'.format(lang, username,
sysop_name))
+ pywikibot.output(u'\t{0}: {1} ({2})'.format(lang, username,
sysop_name))
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 921d088..d097f54 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -508,7 +508,7 @@
for page in site.allpages(filterredir=True, total=1):
break
else:
- raise unittest.SkipTest('No redirect pages on site
{0!r}'.format(site))
+ raise unittest.SkipTest(u'No redirect pages on site
{0!r}'.format(site))
# This page is already initialised
self.assertTrue(hasattr(page, '_isredir'))
# call api.update_page without prop=info
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 762f91f..fd46b52 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -719,8 +719,8 @@
if list(site.protectedpages(type='edit', level=level, total=1)):
levels.add(level)
if not levels:
- raise unittest.SkipTest('The site "{0}" has no protected pages in '
- 'main namespace.'.format(site))
+ raise unittest.SkipTest(u'The site "{0}" has no protected pages in
'
+ u'main namespace.'.format(site))
# select one level which won't yield all pages from above
level = next(iter(levels))
if len(levels) == 1:
@@ -805,8 +805,8 @@
for using in mysite.imageusage(imagepage, filterredir=False, total=5):
self.assertIsInstance(using, pywikibot.Page)
if using.isRedirectPage():
- print('{0} is a redirect, although just non-redirects were '
- 'searched. See also bug 73120'.format(using))
+ print(u'{0} is a redirect, although just non-redirects were '
+ u'searched. See also bug 73120'.format(using))
self.assertFalse(using.isRedirectPage())
@@ -1171,7 +1171,7 @@
break
else:
raise unittest.SkipTest(
- '{0} contains no deleted revisions.'.format(mainpage))
+ u'{0} contains no deleted revisions.'.format(mainpage))
self.assertLessEqual(len(dr['revisions']), 10)
self.assertTrue(all(isinstance(rev, dict)
for rev in dr['revisions']))
--
To view, visit https://gerrit.wikimedia.org/r/198203
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I22951d410084bce67744e78a0d25949e34ea133c
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits