jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/583057 )
Change subject: [cleanup] Remove old compat line_separator config variable
......................................................................
[cleanup] Remove old compat line_separator config variable
line_separator was introduced due to different behaviour when page
content was retrieved by api and screen scraping. Therefore the
LS at core is '\n' whereas at compat it was '\r\n'. That config
variable was mainly for having scripts in sync for the both
framework variants compat and core; the scripts where mainly the
same but the LS was different in config files.
Replace all occurences with '\n'
Change-Id: Ia7fe8d56c52a8430385dc4dc9014b5fad758c27e
---
M pywikibot/config2.py
M pywikibot/cosmetic_changes.py
M pywikibot/family.py
M pywikibot/textlib.py
M scripts/add_text.py
M tests/textlib_tests.py
6 files changed, 32 insertions(+), 57 deletions(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 9b5b4d4..da754de 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -112,8 +112,9 @@
_private_values = {'authenticate', 'db_password'}
_deprecated_variables = {'available_ssl_project', 'fake_user_agent',
- 'panoramio', 'proxy',
'special_page_limit',
- 'sysopnames', 'use_SSL_onlogin',
'use_SSL_always'}
+ 'line_separator', 'LS', 'panoramio',
'proxy',
+ 'special_page_limit', 'sysopnames',
'use_SSL_onlogin',
+ 'use_SSL_always'}
# ############# ACCOUNT SETTINGS ##############
@@ -875,12 +876,6 @@
# processing. As higher this value this effect will decrease.
max_queue_size = 64
-# Define the line separator. Pages retrieved via API have "\n" whereas
-# pages fetched from screen (mostly) have "\r\n". Interwiki and category
-# separator settings in family files should use multiplied of this.
-# LS is a shortcut alias.
-line_separator = LS = '\n'
-
# Settings to enable mwparserfromhell
# <https://mwparserfromhell.readthedocs.org/en/latest/>
# Currently used in textlib.extract_templates_and_params
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 051b06f..c40fc49 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -68,8 +68,8 @@
import pywikibot
-from pywikibot import config, textlib
from pywikibot.page import url2unicode
+from pywikibot import textlib
from pywikibot.textlib import (_MultiTemplateMatchBuilder, FILE_LINK_REGEX,
_get_regexes)
from pywikibot.tools import deprecated_args, first_lower, first_upper
@@ -711,7 +711,7 @@
return textlib.replaceExcept(
text,
r'(?m)^(={1,6})[ \t]*(?P<title>.*[^\s=])[ \t]*\1[ \t]*\r?\n',
- r'\1 \g<title> \1%s' % config.LS,
+ r'\1 \g<title> \1\n',
['comment', 'math', 'nowiki', 'pre'])
def putSpacesInLists(self, text):
diff --git a/pywikibot/family.py b/pywikibot/family.py
index c413503..43e5e65 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -817,7 +817,7 @@
# one-after-another on a single line
interwiki_on_one_line = []
# String used as separator between interwiki links and the text
- interwiki_text_separator = config.line_separator * 2
+ interwiki_text_separator = '\n\n'
# Similar for category
category_attop = []
@@ -825,7 +825,7 @@
# one-after-another on a single line
category_on_one_line = []
# String used as separator between category links and the text
- category_text_separator = config.line_separator * 2
+ category_text_separator = '\n\n'
# When both at the bottom should categories come after interwikilinks?
# TODO: T86284 Needed on Wikia sites, as it uses the CategorySelect
# extension which puts categories last on all sites. TO BE DEPRECATED!
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 4723749..8a7a10c 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -7,7 +7,7 @@
"""
#
-# (C) Pywikibot team, 2008-2019
+# (C) Pywikibot team, 2008-2020
#
# Distributed under the terms of the MIT license.
#
@@ -1230,9 +1230,8 @@
if insite.code in insite.family.interwiki_on_one_line:
sep = ' '
else:
- sep = config.line_separator
- s = sep.join(s) + config.line_separator
- return s
+ sep = '\n'
+ return sep.join(s) + '\n'
def interwikiSort(sites, insite=None):
@@ -1334,7 +1333,7 @@
site=site)
if marker:
# avoid having multiple linefeeds at the end of the text
- text = re.sub(r'\s*%s' % re.escape(marker), config.LS + marker,
+ text = re.sub(r'\s*%s' % re.escape(marker), '\n' + marker,
text.strip())
return text.strip()
@@ -1449,7 +1448,7 @@
site = pywikibot.Site()
if re.search(r'\{\{ *(' +
r'|'.join(site.getmagicwords('defaultsort'))
+ r')', oldtext, flags=re.I):
- separator = config.line_separator
+ separator = '\n'
else:
separator = site.family.category_text_separator
iseparator = site.family.interwiki_text_separator
@@ -1560,10 +1559,10 @@
if insite.category_on_one_line():
sep = ' '
else:
- sep = config.line_separator
+ sep = '\n'
# Some people don't like the categories sorted
# catLinks.sort()
- return sep.join(catLinks) + config.line_separator
+ return sep.join(catLinks) + '\n'
# -------------------------------------
@@ -1996,18 +1995,17 @@
@type stars_list: list
@param site: a site where the given text is used.
interwiki_text_separator is used when a site object is given.
- Otherwise line_separator is used twice to separate stars list.
+ Otherwise two line separators are used to separate stars list.
@type site: BaseSite
@return: modified text
@rtype: str
"""
- LS = (config.line_separator * 2
- if not site else site.family.interwiki_text_separator)
+ LS = '\n\n' if not site else site.family.interwiki_text_separator
text = text.strip() + LS
stars = stars_list[:]
stars.sort()
for element in stars:
- text += element.strip() + config.line_separator
+ text += element.strip() + '\n'
return text
diff --git a/scripts/add_text.py b/scripts/add_text.py
index 04f893f..43e80c3 100755
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -56,7 +56,7 @@
#
# (C) Filnik, 2007-2010
-# (C) Pywikibot team, 2007-2019
+# (C) Pywikibot team, 2007-2020
#
# Distributed under the terms of the MIT license.
#
@@ -223,8 +223,8 @@
if not up:
newtext = text
# Translating the \\n into binary \n
- addText = addText.replace('\\n', config.line_separator)
- if (reorderEnabled):
+ addText = addText.replace('\\n', '\n')
+ if reorderEnabled:
# Getting the categories
categoriesInside = textlib.getCategoryLinks(newtext, site)
# Deleting the categories
@@ -235,7 +235,7 @@
newtext = textlib.removeLanguageLinks(newtext, site)
# Adding the text
- newtext += '{}{}'.format(config.line_separator, addText)
+ newtext += '\n' + addText
# Reputting the categories
newtext = textlib.replaceCategoryLinks(newtext,
categoriesInside, site,
@@ -244,9 +244,9 @@
newtext = textlib.replaceLanguageLinks(newtext, interwikiInside,
site)
else:
- newtext += '{}{}'.format(config.line_separator, addText)
+ newtext += '\n' + addText
else:
- newtext = addText + config.line_separator + text
+ newtext = addText + '\n' + text
if putText and text != newtext:
pywikibot.output(color_format(
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index 6ae076d..1cf7791 100644
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Test textlib module."""
#
-# (C) Pywikibot team, 2011-2019
+# (C) Pywikibot team, 2011-2020
#
# Distributed under the terms of the MIT license.
#
@@ -44,8 +44,7 @@
def setUp(self):
"""Setup tests."""
- self.catresult1 = ('[[Category:Cat1]]%(LS)s[[Category:Cat2]]%(LS)s'
- % {'LS': config.LS})
+ self.catresult1 = '[[Category:Cat1]]\n[[Category:Cat2]]\n'
super(TestSectionFunctions, self).setUp()
def contains(self, fn, sn):
@@ -126,8 +125,7 @@
'de': pywikibot.Page(pywikibot.Link('de:German',
self.site)),
'fr': pywikibot.Page(pywikibot.Link('fr:French', self.site))
}
- self.assertEqual('[[de:German]]%(LS)s[[fr:French]]%(LS)s'
- % {'LS': config.LS},
+ self.assertEqual('[[de:German]]\n[[fr:French]]\n',
textlib.interwikiFormat(interwikis, self.site))
def test_interwiki_format_Link(self):
@@ -136,8 +134,7 @@
'de': pywikibot.Link('de:German', self.site),
'fr': pywikibot.Link('fr:French', self.site),
}
- self.assertEqual('[[de:German]]%(LS)s[[fr:French]]%(LS)s'
- % {'LS': config.LS},
+ self.assertEqual('[[de:German]]\n[[fr:French]]\n',
textlib.interwikiFormat(interwikis, self.site))
@@ -145,8 +142,7 @@
"""Test category formatting."""
- catresult = ('[[Category:Cat1]]%(LS)s[[Category:Cat2]]%(LS)s'
- % {'LS': config.LS})
+ catresult = '[[Category:Cat1]]\n[[Category:Cat2]]\n'
def test_category_format_raw(self):
"""Test formatting categories as strings formatted as
links."""
@@ -184,9 +180,8 @@
with both a newline and an empty string as separators.
"""
- old = ('[[Category:Cat1]]%(LS)s[[Category:Cat2|]]%(LS)s'
- '[[Category:Cat1| ]]%(LS)s[[Category:Cat2|key]]'
- % {'LS': config.LS})
+ old = ('[[Category:Cat1]]\n[[Category:Cat2|]]\n'
+ '[[Category:Cat1| ]]\n[[Category:Cat2|key]]')
def test_standard_links(self):
"""Test getting and replacing categories."""
@@ -194,29 +189,16 @@
new = textlib.replaceCategoryLinks(self.old, cats, site=self.site)
self.assertEqual(self.old, new)
- def test_adjoining_links(self):
- """Test getting and replacing adjacent
categories."""
- cats_std = textlib.getCategoryLinks(self.old, site=self.site)
- old = self.old.replace(config.LS, '')
- cats = textlib.getCategoryLinks(old, site=self.site)
- self.assertEqual(cats_std, cats)
- sep = config.LS
- config.line_separator = '' # use an empty separator temporarily
- new = textlib.replaceCategoryLinks(old, cats, site=self.site)
- # Restore the default separator.
- config.line_separator = sep
- self.assertEqual(old, new)
-
def test_indentation(self):
"""Test indentation from previous block."""
# Block of text
- old = 'Some text%(LS)s%(LS)s' % {'LS': config.LS} + self.old
+ old = 'Some text\n\n' + self.old
cats = textlib.getCategoryLinks(old, site=self.site)
new = textlib.replaceCategoryLinks(old, cats, site=self.site)
self.assertEqual(old, new)
# DEFAULTSORT
- old_ds = '{{DEFAULTSORT:key}}%(LS)s' % {'LS': config.LS} +
self.old
+ old_ds = '{{DEFAULTSORT:key}}\n' + self.old
cats_ds = textlib.getCategoryLinks(old_ds, site=self.site)
new_ds = textlib.replaceCategoryLinks(old_ds, cats_ds, site=self.site)
self.assertEqual(old_ds, new_ds)
--
To view, visit
https://gerrit.wikimedia.org/r/583057
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia7fe8d56c52a8430385dc4dc9014b5fad758c27e
Gerrit-Change-Number: 583057
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)